bfj 6.1.1 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc CHANGED
@@ -1,6 +1,8 @@
1
1
  env:
2
2
  es6: true
3
3
  node: true
4
+ parserOptions:
5
+ ecmaVersion: 2018
4
6
  rules:
5
7
  accessor-pairs: [ 2, { "setWithoutGet": true } ]
6
8
  array-bracket-spacing: [ 2, "always" ]
package/.gitlab-ci.yml CHANGED
@@ -12,10 +12,6 @@ before_script:
12
12
  - npm run lint
13
13
  - npm test
14
14
 
15
- test:node6:
16
- image: node:6
17
- <<: *npm_test
18
-
19
15
  test:node8:
20
16
  image: node:8
21
17
  <<: *npm_test
@@ -23,3 +19,7 @@ test:node8:
23
19
  test:node10:
24
20
  image: node:10
25
21
  <<: *npm_test
22
+
23
+ test:node12:
24
+ image: node:12
25
+ <<: *npm_test
package/HISTORY.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # History
2
2
 
3
+ ## 7.0.2
4
+
5
+ ### Other changes
6
+
7
+ * package: update dependencies (cf82fd4)
8
+
9
+ ## 7.0.1
10
+
11
+ ### Bug fixes
12
+
13
+ * match: prevent mismatched properties when minDepth is set (4efaf1a)
14
+
15
+ ## 7.0.0
16
+
17
+ ### Breaking changes
18
+
19
+ * package: limit to node 8+ (cc42139)
20
+
21
+ ### New features
22
+
23
+ * match: support minDepth option to improve performance (6d79fe4)
24
+
25
+ ### Refactorings
26
+
27
+ * code: prefer spread syntax to Object.assign (5544086)
28
+ * code: prefer Object.entries to iterate keys and values (d101317)
29
+
30
+ ### Other changes
31
+
32
+ * package: test in node 12 (9bf4e6b)
33
+ * git: ignore test/*.json (e87eaf7)
34
+
35
+ ## 6.1.2
36
+
37
+ ### Bug fixes
38
+
39
+ * eventify: escape object keys (910ad08)
40
+
41
+ ### Other changes
42
+
43
+ * package: update deps (aafb4ff)
44
+
3
45
  ## 6.1.1
4
46
 
5
47
  ### Bug fixes
package/README.md CHANGED
@@ -280,6 +280,17 @@ Predicate functions will be called with three arguments:
280
280
  If the result of the predicate is a truthy value
281
281
  then the item will be deemed a match.
282
282
 
283
+ In addition to the regular options
284
+ accepted by other parsing functions,
285
+ you can also specify `minDepth`
286
+ to only apply the selector
287
+ to certain depths.
288
+ This can improve performance
289
+ and memory usage,
290
+ if you know that
291
+ you're not interested in
292
+ parsing top-level items.
293
+
283
294
  If there are any syntax errors in the JSON,
284
295
  a `dataError` event will be emitted.
285
296
  If any other errors occur,
@@ -921,21 +932,18 @@ with the command
921
932
 
922
933
  ## What versions of Node.js does it support?
923
934
 
924
- As of [version `3.0.0`](HISTORY.md#300),
935
+ As of [version `7.0.0`](HISTORY.md#700),
936
+ only Node.js versions 8 or greater
937
+ are supported.
938
+
939
+ Between versions [`3.0.0`](HISTORY.md#300)
940
+ and [`6.1.2`](HISTORY.md#612),
925
941
  only Node.js versions 6 or greater
926
- are supported
927
- because of the dependency
928
- on [Hoopy](https://gitlab.com/philbooth/hoopy).
929
- Previous versions supported
930
- node 4 and later.
931
-
932
- A separate `node-4` branch was maintained
933
- until version `5.4.1`,
934
- which had feature parity version-for-version
935
- with releases from `master`.
936
- Releases from the `node-4` branch
937
- are available in npm
938
- under the package name [`bfj-node4`](https://www.npmjs.com/package/bfj-node4).
942
+ were supported.
943
+
944
+ Until [version `2.1.2`](HISTORY.md#212),
945
+ only Node.js versions 4 or greater
946
+ were supported.
939
947
 
940
948
  ## What license is it released under?
941
949
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bfj",
3
- "version": "6.1.1",
3
+ "version": "7.0.2",
4
4
  "description": "Big-friendly JSON. Asynchronous streaming functions for large JSON data sets.",
5
5
  "homepage": "https://gitlab.com/philbooth/bfj",
6
6
  "bugs": "https://gitlab.com/philbooth/bfj/issues",
@@ -26,22 +26,22 @@
26
26
  "url": "https://gitlab.com/philbooth/bfj.git"
27
27
  },
28
28
  "engines": {
29
- "node": ">= 6.0.0"
29
+ "node": ">= 8.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "bluebird": "^3.5.1",
33
- "check-types": "^7.3.0",
34
- "hoopy": "^0.1.2",
35
- "tryer": "^1.0.0"
32
+ "bluebird": "^3.5.5",
33
+ "check-types": "^11.1.1",
34
+ "hoopy": "^0.1.4",
35
+ "tryer": "^1.0.1"
36
36
  },
37
37
  "devDependencies": {
38
- "chai": "4.1.x",
39
- "eslint": "4.19.x",
40
- "mocha": "5.0.x",
41
- "please-release-me": "^2.0.2",
42
- "proxyquire": "1.8.x",
43
- "request": "2.85.x",
44
- "spooks": "2.0.x"
38
+ "chai": "^4.2.0",
39
+ "eslint": "^6.0.1",
40
+ "mocha": "^6.1.4",
41
+ "please-release-me": "^2.1.2",
42
+ "proxyquire": "^2.1.0",
43
+ "request": "^2.88.0",
44
+ "spooks": "^2.0.0"
45
45
  },
46
46
  "scripts": {
47
47
  "lint": "eslint src",
package/src/datastream.js CHANGED
@@ -13,5 +13,5 @@ function DataStream (read, options) {
13
13
  return new DataStream(read, options)
14
14
  }
15
15
 
16
- return BfjStream.call(this, read, Object.assign({ objectMode: true }, options))
16
+ return BfjStream.call(this, read, { ...options, objectMode: true })
17
17
  }
package/src/eventify.js CHANGED
@@ -140,7 +140,7 @@ function eventify (data, options = {}) {
140
140
  return Promise.resolve(datum)
141
141
  }
142
142
 
143
- if (check.instanceStrict(datum, Promise)) {
143
+ if (check.thenable(datum)) {
144
144
  return coerceThing(datum, 'promises', coercePromise).then(coerce)
145
145
  }
146
146
 
@@ -297,7 +297,7 @@ function eventify (data, options = {}) {
297
297
  return Promise.resolve()
298
298
  }
299
299
 
300
- return emit(events.property, key)
300
+ return emit(events.property, escapeString(key))
301
301
  .then(() => proceed(item))
302
302
  })
303
303
  }
package/src/jsonstream.js CHANGED
@@ -13,5 +13,5 @@ function JsonStream (read, options) {
13
13
  return new JsonStream(read, options)
14
14
  }
15
15
 
16
- return BfjStream.call(this, read, Object.assign({ encoding: 'utf8' }, options))
16
+ return BfjStream.call(this, read, { ...options, encoding: 'utf8' })
17
17
  }
package/src/match.js CHANGED
@@ -25,6 +25,11 @@ module.exports = match
25
25
  * passed, both the key and the value are passed to it as
26
26
  * arguments.
27
27
  *
28
+ * @option minDepth: Number indicating the minimum depth to apply the selector
29
+ * to. The default is `0`, but setting it to a higher value
30
+ * can improve performance and reduce memory usage by
31
+ * eliminating the need to actualise top-level items.
32
+ *
28
33
  * @option numbers: Boolean, indicating whether numerical keys (e.g. array
29
34
  * indices) should be coerced to strings before testing the
30
35
  * match. Only applies if the `selector` argument is a string
@@ -62,6 +67,9 @@ function match (stream, selector, options = {}) {
62
67
  let length = 0
63
68
  let index = 0
64
69
 
70
+ const minDepth = options.minDepth || 0
71
+ check.assert.greaterOrEqual(minDepth, 0)
72
+
65
73
  if (check.function(selector)) {
66
74
  selectorFunction = selector
67
75
  selector = null
@@ -152,6 +160,10 @@ function match (stream, selector, options = {}) {
152
160
  }
153
161
 
154
162
  function property (name) {
163
+ if (scopes.length < minDepth) {
164
+ return
165
+ }
166
+
155
167
  properties.push(name)
156
168
  }
157
169
 
@@ -162,6 +174,10 @@ function match (stream, selector, options = {}) {
162
174
  function value (v) {
163
175
  let key
164
176
 
177
+ if (scopes.length < minDepth) {
178
+ return
179
+ }
180
+
165
181
  if (scopes.length > 0) {
166
182
  const scope = scopes[scopes.length - 1]
167
183
 
package/src/parse.js CHANGED
@@ -161,8 +161,8 @@ function parse (stream, options = {}) {
161
161
 
162
162
  function transform (obj, key) {
163
163
  if (obj && typeof obj === 'object') {
164
- Object.keys(obj).forEach(childKey => {
165
- obj[childKey] = transform(obj[childKey], childKey)
164
+ Object.entries(obj).forEach(([ k, v ]) => {
165
+ obj[k] = transform(v, k)
166
166
  })
167
167
  }
168
168
 
package/src/read.js CHANGED
@@ -22,5 +22,5 @@ module.exports = read
22
22
  * @option Promise: The promise constructor to use, defaults to bluebird.
23
23
  **/
24
24
  function read (path, options) {
25
- return parse(fs.createReadStream(path, options), Object.assign({}, options, { ndjson: false }))
25
+ return parse(fs.createReadStream(path, options), { ...options, ndjson: false })
26
26
  }
package/src/unpipe.js CHANGED
@@ -29,7 +29,7 @@ function unpipe (callback, options) {
29
29
 
30
30
  const jsonstream = new stream.PassThrough()
31
31
 
32
- parse(jsonstream, Object.assign({}, options, { ndjson: false }))
32
+ parse(jsonstream, { ...options, ndjson: false })
33
33
  .then(data => callback(null, data))
34
34
  .catch(error => callback(error))
35
35
 
@@ -229,7 +229,11 @@ suite('integration:', () => {
229
229
  }))
230
230
  results = []
231
231
  errors = []
232
- const datastream = bfj.match(fs.createReadStream(file), (k, v) => k === 'baz' || v === 'blee')
232
+ const datastream = bfj.match(
233
+ fs.createReadStream(file),
234
+ (k, v) => k === 'baz' || v === 'blee',
235
+ { minDepth: 1 }
236
+ )
233
237
  datastream.on('data', item => results.push(item))
234
238
  datastream.on('error', error => errors.push(error))
235
239
  datastream.on('end', done)