Skip to content

Commit

Permalink
Simplify JSON parse condition. Improve documentation description.
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Oct 21, 2019
1 parent 478ede7 commit 09499be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Initializes a new instance of the Kinesis client.
| [options.s3.nonS3Keys] | <code>Array.&lt;string&gt;</code> | <code>[]</code> | If the `useS3ForLargeItems` option is set to `true`, the `nonS3Keys` option lists the keys that will be sent normally on the kinesis record. |
| [options.s3.tags] | <code>string</code> | | If provided, the client will ensure that the S3 bucket is tagged with these tags. If the bucket already has tags, they will be merged. |
| [options.shardCount] | <code>number</code> | <code>1</code> | The number of shards that the newly-created stream will use (if the `createStreamIfNeeded` option is set) |
| [options.shouldParseJson] | <code>string</code> \| <code>boolean</code> | <code>&quot;auto&quot;</code> | Indicates if consumer data should be parsed as JSON. 'auto': if data matches json format, data will be parsed. `true`: will parse data regardless |
| [options.shouldParseJson] | <code>string</code> \| <code>boolean</code> | <code>&quot;auto&quot;</code> | Whether if retrieved records' data should be parsed as JSON or not. Set to "auto" to only attempt parsing if data looks like JSON. Set to true to force data parse. |
| [options.statsInterval] | <code>number</code> | <code>30000</code> | The interval in milliseconds for how often to emit the "stats" event. The event is only available while the consumer is running. |
| options.streamName | <code>string</code> | | The name of the stream to consume data from (required) |
| [options.tags] | <code>object</code> | | If provided, the client will ensure that the stream is tagged with these tags upon connection. If the stream is already tagged, the existing tags will be merged with the provided ones before updating them. |
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class Kinesis extends PassThrough {
* S3 bucket is tagged with these tags. If the bucket already has tags, they will be merged.
* @param {number} [options.shardCount=1] - The number of shards that the newly-created stream
* will use (if the `createStreamIfNeeded` option is set)
* @param {string|boolean} [options.shouldParseJson=auto] - Indicates if consumer data should be parsed as JSON.
* 'auto': if data matches json format, data will be parsed. `true`: will parse data regardless
* @param {string|boolean} [options.shouldParseJson=auto] - Whether if retrieved records' data should be parsed as JSON or not.
* Set to "auto" to only attempt parsing if data looks like JSON. Set to true to force data parse.
* @param {number} [options.statsInterval=30000] - The interval in milliseconds for how often to
* emit the "stats" event. The event is only available while the consumer is running.
* @param {string} options.streamName - The name of the stream to consume data from (required)
Expand Down
8 changes: 2 additions & 6 deletions lib/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function hash(buffer) {
* @param {object} options - Options object.
* @param {string} [options.compression] - The kind of compression used in the Kinesis record data.
* @param {string} [options.inputEncoding] - The encoding of the `Data` property in the AWS.Kinesis record.
* @param {boolean} [options.shouldParseJson] - Indicates if consumer data should be parsed as JSON.
* @param {boolean} [options.shouldParseJson] - Whether if retrieved records' data should be parsed as JSON or not.
* @param {string} [options.logger] - An instance of a logger.
* @param {object} [options.s3Client] - The s3Client in the current kinesis client.
* @param {boolean} [options.useS3ForLargeItems] - Whether to automatically use an S3 bucket to store large items or not.
Expand Down Expand Up @@ -89,11 +89,7 @@ function getRecordsDecoder({
data = Buffer.from(data, 'base64').toString('utf8');
}

if (shouldParseJson === 'auto') {
if (IS_JSON_REGEX.test(data)) {
data = JSON.parse(data);
}
} else if (shouldParseJson === true) {
if ((shouldParseJson === 'auto' && IS_JSON_REGEX.test(data)) || shouldParseJson === true) {
data = JSON.parse(data);
}

Expand Down

0 comments on commit 09499be

Please sign in to comment.