bfj 6.1.0 → 7.0.1

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 ADDED
@@ -0,0 +1,25 @@
1
+ cache:
2
+ key: "$CI_JOB_NAME"
3
+ untracked: true
4
+ paths:
5
+ - node_modules/
6
+
7
+ before_script:
8
+ - npm install
9
+
10
+ .test_template: &npm_test
11
+ script:
12
+ - npm run lint
13
+ - npm test
14
+
15
+ test:node8:
16
+ image: node:8
17
+ <<: *npm_test
18
+
19
+ test:node10:
20
+ image: node:10
21
+ <<: *npm_test
22
+
23
+ test:node12:
24
+ image: node:12
25
+ <<: *npm_test
package/AUTHORS CHANGED
@@ -1,4 +1,4 @@
1
- Phil Booth <pmbooth@gmail.com> (https://github.com/philbooth)
1
+ Phil Booth <pmbooth@gmail.com> (https://philbooth.me/)
2
2
  Rowan Manning (https://github.com/rowanmanning)
3
3
  Benedikt Rötsch (https://github.com/axe312ger)
4
4
 
package/CONTRIBUTING.md CHANGED
@@ -30,8 +30,8 @@
30
30
  if the change is one that you think
31
31
  needs some discussion.
32
32
 
33
- [readme]: https://github.com/philbooth/bfj/blob/master/README.md
34
- [authors]: https://github.com/philbooth/bfj/blob/master/AUTHORS
35
- [newissue]: https://github.com/philbooth/bfj/issues/new
36
- [issues]: https://github.com/philbooth/bfj/issues
33
+ [readme]: https://gitlab.com/philbooth/bfj/blob/master/README.md
34
+ [authors]: https://gitlab.com/philbooth/bfj/blob/master/AUTHORS
35
+ [newissue]: https://gitlab.com/philbooth/bfj/issues/new
36
+ [issues]: https://gitlab.com/philbooth/bfj/issues
37
37
 
package/HISTORY.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # History
2
2
 
3
+ ## 7.0.1
4
+
5
+ ### Bug fixes
6
+
7
+ * match: prevent mismatched properties when minDepth is set (4efaf1a)
8
+
9
+ ## 7.0.0
10
+
11
+ ### Breaking changes
12
+
13
+ * package: limit to node 8+ (cc42139)
14
+
15
+ ### New features
16
+
17
+ * match: support minDepth option to improve performance (6d79fe4)
18
+
19
+ ### Refactorings
20
+
21
+ * code: prefer spread syntax to Object.assign (5544086)
22
+ * code: prefer Object.entries to iterate keys and values (d101317)
23
+
24
+ ### Other changes
25
+
26
+ * package: test in node 12 (9bf4e6b)
27
+ * git: ignore test/*.json (e87eaf7)
28
+
29
+ ## 6.1.2
30
+
31
+ ### Bug fixes
32
+
33
+ * eventify: escape object keys (910ad08)
34
+
35
+ ### Other changes
36
+
37
+ * package: update deps (aafb4ff)
38
+
39
+ ## 6.1.1
40
+
41
+ ### Bug fixes
42
+
43
+ * eventify: don't serialise NaN or infinities (3c50fe4)
44
+
45
+ ### Other changes
46
+
47
+ * deps: npm update (b3c86d0)
48
+ * project: add package lock file (63df27d)
49
+ * project: migrate to gitlab (26746a0)
50
+
3
51
  ## 6.1.0
4
52
 
5
53
  ### New features
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # BFJ
2
2
 
3
- [![Package status](https://img.shields.io/npm/v/bfj.svg?style=flat-square)](https://www.npmjs.com/package/bfj)
4
- [![Build status](https://img.shields.io/travis/philbooth/bfj.svg?style=flat-square)](https://travis-ci.org/philbooth/bfj)
5
- [![License](https://img.shields.io/github/license/philbooth/bfj.svg?style=flat-square)](https://opensource.org/licenses/MIT)
3
+ [![Build status](https://gitlab.com/philbooth/bfj/badges/master/pipeline.svg)](https://gitlab.com/philbooth/bfj/pipelines)
4
+ [![Package status](https://img.shields.io/npm/v/bfj.svg)](https://www.npmjs.com/package/bfj)
5
+ [![Downloads](https://img.shields.io/npm/dm/bfj.svg)](https://www.npmjs.com/package/bfj)
6
+ [![License](https://img.shields.io/npm/l/bfj.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
8
  Big-Friendly JSON. Asynchronous streaming functions for large JSON data sets.
8
9
 
@@ -141,7 +142,7 @@ Or if you just want
141
142
  the git repo:
142
143
 
143
144
  ```
144
- git clone git@github.com:philbooth/bfj.git
145
+ git clone git@gitlab.com:philbooth/bfj.git
145
146
  ```
146
147
 
147
148
  ## How do I read a JSON file?
@@ -279,6 +280,17 @@ Predicate functions will be called with three arguments:
279
280
  If the result of the predicate is a truthy value
280
281
  then the item will be deemed a match.
281
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
+
282
294
  If there are any syntax errors in the JSON,
283
295
  a `dataError` event will be emitted.
284
296
  If any other errors occur,
@@ -920,21 +932,18 @@ with the command
920
932
 
921
933
  ## What versions of Node.js does it support?
922
934
 
923
- 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),
924
941
  only Node.js versions 6 or greater
925
- are supported
926
- because of the dependency
927
- on [Hoopy](https://github.com/philbooth/hoopy).
928
- Previous versions supported
929
- node 4 and later.
930
-
931
- A separate `node-4` branch was maintained
932
- until version `5.4.1`,
933
- which had feature parity version-for-version
934
- with releases from `master`.
935
- Releases from the `node-4` branch
936
- are available in npm
937
- 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.
938
947
 
939
948
  ## What license is it released under?
940
949
 
@@ -958,5 +967,5 @@ under the package name [`bfj-node4`](https://www.npmjs.com/package/bfj-node4).
958
967
  [mocha]: https://mochajs.org/
959
968
  [chai]: http://chaijs.com/
960
969
  [proxyquire]: https://github.com/thlorenz/proxyquire
961
- [spooks]: https://github.com/philbooth/spooks.js
970
+ [spooks]: https://gitlab.com/philbooth/spooks.js
962
971
  [license]: COPYING
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "bfj",
3
- "version": "6.1.0",
3
+ "version": "7.0.1",
4
4
  "description": "Big-friendly JSON. Asynchronous streaming functions for large JSON data sets.",
5
- "homepage": "https://github.com/philbooth/bfj",
6
- "bugs": "https://github.com/philbooth/bfj/issues",
5
+ "homepage": "https://gitlab.com/philbooth/bfj",
6
+ "bugs": "https://gitlab.com/philbooth/bfj/issues",
7
7
  "license": "MIT",
8
- "author": "Phil Booth (https://github.com/philbooth)",
8
+ "author": "Phil Booth (https://gitlab.com/philbooth)",
9
9
  "main": "./src",
10
10
  "keywords": [
11
11
  "json",
@@ -23,25 +23,25 @@
23
23
  ],
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "https://github.com/philbooth/bfj.git"
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": "^8.0.3",
34
+ "hoopy": "^0.1.4",
35
+ "tryer": "^1.0.1"
36
36
  },
37
37
  "devDependencies": {
38
- "eslint": "4.19.x",
39
- "mocha": "5.0.x",
40
- "chai": "4.1.x",
41
- "proxyquire": "1.8.x",
42
- "spooks": "2.0.x",
43
- "please-release-me": "2.0.x",
44
- "request": "2.85.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
@@ -110,7 +110,7 @@ function eventify (data, options = {}) {
110
110
  })
111
111
 
112
112
  function after (coerced) {
113
- if (isInvalidType(coerced)) {
113
+ if (isInvalid(coerced)) {
114
114
  return
115
115
  }
116
116
 
@@ -205,8 +205,15 @@ function eventify (data, options = {}) {
205
205
  })
206
206
  }
207
207
 
208
- function isInvalidType (datum) {
209
- return !! invalidTypes[typeof datum]
208
+ function isInvalid (datum) {
209
+ const type = typeof datum
210
+ return !! invalidTypes[type] || (
211
+ type === 'number' && ! isValidNumber(datum)
212
+ )
213
+ }
214
+
215
+ function isValidNumber (datum) {
216
+ return datum > Number.NEGATIVE_INFINITY && datum < Number.POSITIVE_INFINITY
210
217
  }
211
218
 
212
219
  function literal (datum) {
@@ -232,7 +239,7 @@ function eventify (data, options = {}) {
232
239
  function array (datum) {
233
240
  // For an array, collection:object and collection:array are the same.
234
241
  return collection(datum, datum, 'array', item => {
235
- if (isInvalidType(item)) {
242
+ if (isInvalid(item)) {
236
243
  return proceed(null)
237
244
  }
238
245
 
@@ -286,11 +293,11 @@ function eventify (data, options = {}) {
286
293
  return collection(datum, Object.keys(datum), 'object', key => {
287
294
  const item = datum[key]
288
295
 
289
- if (isInvalidType(item)) {
296
+ if (isInvalid(item)) {
290
297
  return Promise.resolve()
291
298
  }
292
299
 
293
- return emit(events.property, key)
300
+ return emit(events.property, escapeString(key))
294
301
  .then(() => proceed(item))
295
302
  })
296
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)
@@ -305,7 +309,7 @@ suite('integration:', () => {
305
309
 
306
310
  setup(done => {
307
311
  const jsonstream = new stream.PassThrough()
308
- request({ url: 'https://raw.githubusercontent.com/philbooth/bfj/master/package.json' })
312
+ request({ url: 'https://gitlab.com/philbooth/bfj/raw/master/package.json' })
309
313
  .pipe(bfj.unpipe((err, res) => {
310
314
  error = err
311
315
  result = res