hookney 1.1.4 → 1.2.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/LICENSE +1 -1
- package/README.md +49 -27
- package/hookney.js +10 -9
- package/hookney.min.js +2 -2
- package/package.json +25 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Hookney
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
-
`Hookney` is a helper around self-referencing JSON objects for Node.js and the
|
|
4
|
+
`Hookney` is a helper around self-referencing JSON objects for Node.js and the browser.
|
|
5
5
|
`Hookney` supports reading from and writing to files. JSON files may contain comments.
|
|
6
6
|
This makes `Hookney` ideal for handling configuration files.
|
|
7
7
|
|
|
@@ -27,15 +27,15 @@ const Hookney = require('hookney');
|
|
|
27
27
|
`Hookney` has a single dependency to [lodash](https://lodash.com/), which must be loaded before using `Hookney`.
|
|
28
28
|
|
|
29
29
|
You can download the latest release from the repository
|
|
30
|
-
* [`hookney.js`](https://github.com/
|
|
31
|
-
* [`hookney.min.js`](https://github.com/
|
|
30
|
+
* [`hookney.js`](https://github.com/tbillenstein/hookney/blob/master/hookney.js) unminified, including comments
|
|
31
|
+
* [`hookney.min.js`](https://github.com/tbillenstein/hookney/blob/master/hookney.min.js) minified version
|
|
32
32
|
|
|
33
33
|
Load [lodash](https://lodash.com/) from a CDN or any other source.
|
|
34
34
|
```html
|
|
35
|
-
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>
|
|
36
36
|
|
|
37
37
|
<!-- Alternative CDN -->
|
|
38
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.
|
|
38
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
|
|
39
39
|
|
|
40
40
|
<!-- Load from local node module -->
|
|
41
41
|
<script src="node_modules/lodash/lodash.min.js"></script>
|
|
@@ -161,7 +161,7 @@ const config = Hookney.fromString(text).resolveReferences().json();
|
|
|
161
161
|
// => config === { a: 1, b: "str", c: 1 }
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
### Load JSON object from file and resolve references. JSON file may contain comments.
|
|
164
|
+
### Load JSON object from a file and resolve references. JSON file may contain comments.
|
|
165
165
|
|
|
166
166
|
```js
|
|
167
167
|
// Synchronous
|
|
@@ -180,7 +180,7 @@ Hookney.fromFile("/path/to/file.json", function(err, hookney)
|
|
|
180
180
|
});
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
Hookney.fromFile() and Hookney.fromFileSync() support an optional
|
|
183
|
+
`Hookney.fromFile()` and `Hookney.fromFileSync()` support an optional `options` parameter.
|
|
184
184
|
|
|
185
185
|
```js
|
|
186
186
|
const options = {
|
|
@@ -197,14 +197,15 @@ Hookney.fromFile("/path/to/file.json", options, function(err, hookney)
|
|
|
197
197
|
});
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
For details on the
|
|
200
|
+
For details on the `options` parameter, please refer to the
|
|
201
201
|
[Node.js documentation](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback).
|
|
202
202
|
|
|
203
|
-
In addition to the options described there, 1 additional parameter
|
|
204
|
-
Please refer to the
|
|
203
|
+
In addition to the options described there, 1 additional parameter `reviver` is supported.
|
|
204
|
+
Please refer to the
|
|
205
|
+
[JSON.parse() documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
|
|
205
206
|
for details.
|
|
206
207
|
|
|
207
|
-
Hookney.fromFile() and Hookney.fromFileSync() are not available in the browser.
|
|
208
|
+
`Hookney.fromFile()` and `Hookney.fromFileSync()` are not available in the browser.
|
|
208
209
|
|
|
209
210
|
### Write JSON object to file.
|
|
210
211
|
|
|
@@ -224,7 +225,7 @@ Hookney.writeFile("/path/to/file.json", function(err)
|
|
|
224
225
|
});
|
|
225
226
|
```
|
|
226
227
|
|
|
227
|
-
writeFile() and writeFileSync() support an optional
|
|
228
|
+
`writeFile()` and `writeFileSync()` support an optional `options` parameter.
|
|
228
229
|
|
|
229
230
|
```js
|
|
230
231
|
const options = {
|
|
@@ -243,29 +244,37 @@ Hookney.writeFile("/path/to/file.json", options, function(err)
|
|
|
243
244
|
});
|
|
244
245
|
```
|
|
245
246
|
|
|
246
|
-
For details on the
|
|
247
|
+
For details on the `options` parameter, please refer to the
|
|
247
248
|
[Node.js documentation](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options).
|
|
248
249
|
|
|
249
|
-
In addition to the options described there, 2 additional parameters
|
|
250
|
-
Please refer to the
|
|
250
|
+
In addition to the options described there, 2 additional parameters `replacer` and `space` are supported.
|
|
251
|
+
Please refer to the
|
|
252
|
+
[JSON.stringify() documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
|
251
253
|
for details.
|
|
252
254
|
|
|
253
|
-
writeFile() and writeFileSync() are not available in the browser.
|
|
255
|
+
`writeFile()` and `writeFileSync()` are not available in the browser.
|
|
254
256
|
|
|
255
257
|
|
|
256
258
|
More examples
|
|
257
259
|
-------------
|
|
258
|
-
Please refer to the [test spec](https://github.com/
|
|
260
|
+
Please refer to the [test spec](https://github.com/tbillenstein/hookney/blob/master/spec/HookneySpec.js) for more examples.
|
|
259
261
|
|
|
260
262
|
|
|
261
263
|
Testing
|
|
262
264
|
-------
|
|
263
|
-
We
|
|
265
|
+
We use
|
|
266
|
+
* [JSHint](https://jshint.com/) for static code analysis.
|
|
267
|
+
* [Jasmine testing framework](https://jasmine.github.io/index.html) for testing.
|
|
268
|
+
* [Karma test runner](https://karma-runner.github.io/latest/index.html) for testing in the browser.
|
|
269
|
+
* [Istanbul test coverage framework](https://istanbul.js.org/) for tracking test coverage.
|
|
264
270
|
|
|
271
|
+
Steps to be taken
|
|
265
272
|
* Clone or download the repository.
|
|
266
|
-
* Change into project directory.
|
|
273
|
+
* Change into the project directory.
|
|
267
274
|
* Use `npm install` to install all development dependencies.
|
|
275
|
+
* Use `npm runt lint` to run static code analysis.
|
|
268
276
|
* Use `npm test` to run the tests.
|
|
277
|
+
* Use `npm run coverage` to track test coverage.
|
|
269
278
|
* The output should display successful execution results and a code coverage map.
|
|
270
279
|
|
|
271
280
|
|
|
@@ -273,33 +282,45 @@ Build
|
|
|
273
282
|
-----
|
|
274
283
|
* Clone or download the repository.
|
|
275
284
|
* Change into project directory.
|
|
276
|
-
* Use `
|
|
285
|
+
* Use `npm run build` in project directory to build `hookney.min.js` from `hookney.js`.
|
|
277
286
|
|
|
278
287
|
|
|
279
288
|
Contribution
|
|
280
289
|
------------
|
|
281
|
-
Please use [Github issues](https://github.com/
|
|
290
|
+
Please use [Github issues](https://github.com/tbillenstein/hookney/issues) for requests.
|
|
282
291
|
|
|
283
292
|
Pull requests are welcome.
|
|
284
293
|
|
|
285
294
|
|
|
286
295
|
Issues
|
|
287
296
|
------
|
|
288
|
-
We use GitHub issues to track bugs. Please ensure your bug description is clear and has sufficient instructions to be
|
|
297
|
+
We use GitHub issues to track bugs. Please ensure your bug description is clear and has sufficient instructions to be
|
|
298
|
+
able to reproduce the issue.
|
|
289
299
|
|
|
290
|
-
The absolute best way to report a bug is to submit a pull request including a new failing test which describes the bug.
|
|
300
|
+
The absolute best way to report a bug is to submit a pull request including a new failing test which describes the bug.
|
|
301
|
+
When the bug is fixed, your pull request can then be merged.
|
|
291
302
|
|
|
292
|
-
The next best way to report a bug is to provide a reduced test case on jsFiddle or jsBin or produce exact code inline
|
|
303
|
+
The next best way to report a bug is to provide a reduced test case on jsFiddle or jsBin or produce exact code inline
|
|
304
|
+
in the issue which will reproduce the bug.
|
|
293
305
|
|
|
294
306
|
|
|
295
307
|
Support
|
|
296
308
|
-------
|
|
297
|
-
* Send us an email: [
|
|
298
|
-
* Follow us on Twitter: [@
|
|
309
|
+
* Send us an email: [tb@thomasbillenstein.com](mailto:tb@thomasbillenstein.com)
|
|
310
|
+
* Follow us on Twitter: [@tbillenstein](https://x.com/tbillenstein/)
|
|
299
311
|
|
|
300
312
|
|
|
301
313
|
Changelog
|
|
302
314
|
---------
|
|
315
|
+
v1.2.0
|
|
316
|
+
* Update npm modules.
|
|
317
|
+
* Update and extend test environment.
|
|
318
|
+
* Add static code analysis tool JSHint.
|
|
319
|
+
* Add Karma test runner.
|
|
320
|
+
* Fix JSHint issues.
|
|
321
|
+
* Replace uglify-js by terser for minification.
|
|
322
|
+
* Update README.
|
|
323
|
+
|
|
303
324
|
v1.1.4
|
|
304
325
|
* Update npm modules.
|
|
305
326
|
|
|
@@ -321,4 +342,5 @@ v1.0.0
|
|
|
321
342
|
|
|
322
343
|
License
|
|
323
344
|
-------
|
|
324
|
-
Copyright (c) 2016-present,
|
|
345
|
+
Copyright (c) 2016-present, tbillenstein. `Hookney` is licensed under the
|
|
346
|
+
[MIT License](https://github.com/tbillenstein/hookney/blob/master/LICENSE).
|
package/hookney.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hookney - Helper around self referencing JSON objects for Node.js and the
|
|
2
|
+
* Hookney - Helper around self referencing JSON objects for Node.js and the browser.
|
|
3
3
|
*
|
|
4
|
-
* @copyright: Copyright (c) 2016-present,
|
|
4
|
+
* @copyright: Copyright (c) 2016-present, tbillenstein
|
|
5
5
|
*
|
|
6
|
-
* @author:
|
|
6
|
+
* @author: tbillenstein <tb@thomasbillenstein.com> (https://thomasbillenstein.com)
|
|
7
7
|
*
|
|
8
8
|
* @license This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
(function(window)
|
|
13
14
|
{
|
|
14
15
|
const nodeEnv = typeof module === 'object' && module && typeof module.exports === 'object';
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
|
|
40
41
|
for (i = 0; i < l; i++)
|
|
41
42
|
{
|
|
42
|
-
_.merge(json, arguments[i])
|
|
43
|
+
_.merge(json, arguments[i]);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
this.json = function()
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
if (!done)
|
|
69
70
|
{
|
|
70
71
|
done = options;
|
|
71
|
-
options = {}
|
|
72
|
+
options = {};
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
options = options || {};
|
|
@@ -206,7 +207,7 @@
|
|
|
206
207
|
|
|
207
208
|
for (i = 0; i < l; i++)
|
|
208
209
|
{
|
|
209
|
-
_.merge(json, arguments[i])
|
|
210
|
+
_.merge(json, arguments[i]);
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
return new Hookney(json);
|
|
@@ -232,7 +233,7 @@
|
|
|
232
233
|
if (!done)
|
|
233
234
|
{
|
|
234
235
|
done = options;
|
|
235
|
-
options = {}
|
|
236
|
+
options = {};
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
options = options || {};
|
|
@@ -286,7 +287,7 @@
|
|
|
286
287
|
catch (err)
|
|
287
288
|
{
|
|
288
289
|
err.message = path + ': ' + err.message;
|
|
289
|
-
throw err
|
|
290
|
+
throw err;
|
|
290
291
|
}
|
|
291
292
|
};
|
|
292
293
|
}
|
|
@@ -310,7 +311,7 @@
|
|
|
310
311
|
|
|
311
312
|
tokenizer.lastIndex = 0;
|
|
312
313
|
|
|
313
|
-
while (tmp = tokenizer.exec(json))
|
|
314
|
+
while ((tmp = tokenizer.exec(json)) !== null)
|
|
314
315
|
{
|
|
315
316
|
lc = RegExp.leftContext;
|
|
316
317
|
rc = RegExp.rightContext;
|
package/hookney.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! hookney V1.1
|
|
2
|
-
!function(
|
|
1
|
+
/*! hookney V1.2.1, Copyright (c) 2016-present, tbillenstein. MIT licensed. */
|
|
2
|
+
!function(e){const n="object"==typeof module&&module&&"object"==typeof module.exports,t=n?require("fs"):null,r=n?require("lodash"):e._,i="\\$\\{self\\:(.*?)\\}";function o(){"use strict";const e=arguments.length,o={};var s;for(s=0;s<e;s++)r.merge(o,arguments[s]);function l(e){var n,t,r,o;if(c(e))for(n in e)e.hasOwnProperty(n)&&(c(t=e[n])||f(t)?l(t):u(t)&&(e[n]=g(i,t)));else if(f(e))for(o=e.length,r=0;r<o;r++)c(t=e[r])||f(t)?l(t):u(t)&&(e[r]=g(i,t))}function g(e,n){const t=new RegExp(e,"gm").exec(n);var i;return t&&(i=r.get(o,t[1]),n=n===t[0]?i:n.replace(t[0],u(i)?i:JSON.stringify(i)),u(n)?n=g(e,n):"object"==typeof n&&l(n)),n}this.json=function(){return o},this.stringify=function(e,n){return JSON.stringify(o,e,n)},this.resolveReferences=function(){return l(o),this},n&&(this.writeFile=function(e,n,r){const i=this;r||(r=n,n={}),(n=n||{}).encoding||(n.encoding="utf8"),t.writeFile(e,this.stringify(n.replacer,n.space),n,function(e){e?r(e,null):r(null,i)})},this.writeFileSync=function(e,n){return(n=n||{}).encoding||(n.encoding="utf8"),t.writeFileSync(e,this.stringify(n.replacer,n.space),n),this})}function s(e){var n,t,r,i,o=/"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,s=!1,c=!1,f=!1,u=[],l=0,g=0;for(o.lastIndex=0;null!==(n=o.exec(e));)r=RegExp.leftContext,i=RegExp.rightContext,c||f||(t=r.substring(g),s||(t=t.replace(/(\n|\r|\s)*/g,"")),u[l++]=t),g=o.lastIndex,'"'!==n[0]||c||f?"/*"!==n[0]||s||c||f?"*/"!==n[0]||s||!c||f?"//"!==n[0]||s||c||f?"\n"!==n[0]&&"\r"!==n[0]||s||c||!f?c||f||/\n|\r|\s/.test(n[0])||(u[l++]=n[0]):f=!1:f=!0:c=!1:c=!0:(t=r.match(/(\\)*$/),s&&t&&t[0].length%2!=0||(s=!s),g--,i=e.substring(g));return u[l++]=i,u.join("")}function c(e){return"object"==typeof e&&!Array.isArray(e)}function f(e){return Array.isArray(e)}function u(e){return"string"==typeof e}n?module.exports=o:e.Hookney=o,o.from=function(){const e=arguments.length,n={};var t;for(t=0;t<e;t++)r.merge(n,arguments[t]);return new o(n)},o.fromString=function(e,n){var t={};return e&&u(e)&&e.length&&(e=s(e),t=JSON.parse(e,n)),new o(t)},n&&(o.fromFile=function(e,n,r){r||(r=n,n={}),(n=n||{}).encoding||(n.encoding="utf8"),t.readFile(e,n,function(t,i){if(t)r(t,null);else{i=s(i);try{r(null,o.fromString(i,n.reviver))}catch(t){t.message=e+": "+t.message,r(t,null)}}})},o.fromFileSync=function(e,n){var r;(n=n||{}).encoding||(n.encoding="utf8"),r=s(r=t.readFileSync(e,n));try{return o.fromString(r,n.reviver)}catch(n){throw n.message=e+": "+n.message,n}})}(this);
|
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookney",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "Hookney is a helper around self referencing JSON objects for Node.js and the
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Hookney is a helper around self referencing JSON objects for Node.js and the browser.",
|
|
5
5
|
"main": "hookney.js",
|
|
6
6
|
"directories": {
|
|
7
7
|
"test": "test"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"build": "grunt build",
|
|
11
|
+
"coverage": "nyc ./node_modules/.bin/jasmine",
|
|
12
|
+
"lint": "grunt jshint",
|
|
13
|
+
"test": "./node_modules/.bin/jasmine && npx karma start test/karma/karma.conf.js --single-run",
|
|
14
|
+
"test-node": "./node_modules/.bin/jasmine",
|
|
15
|
+
"test-browser": "npx karma start test/karma/karma.conf.js --single-run"
|
|
12
16
|
},
|
|
13
17
|
"repository": {
|
|
14
18
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/
|
|
19
|
+
"url": "https://github.com/tbillenstein/hookney.git"
|
|
16
20
|
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tbillenstein/hookney/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/tbillenstein/hookney#readme",
|
|
17
25
|
"keywords": [
|
|
18
26
|
"json",
|
|
19
27
|
"self",
|
|
@@ -31,9 +39,8 @@
|
|
|
31
39
|
"from file",
|
|
32
40
|
"from string"
|
|
33
41
|
],
|
|
34
|
-
"author": "
|
|
42
|
+
"author": "tbillenstein <tb@thomasbillenstein.com> (https://thomasbillenstein.com)",
|
|
35
43
|
"license": "MIT",
|
|
36
|
-
"homepage": "https://github.com/belexos/hookney#readme",
|
|
37
44
|
"nyc": {
|
|
38
45
|
"exclude": [
|
|
39
46
|
"**/*Spec.js"
|
|
@@ -44,13 +51,19 @@
|
|
|
44
51
|
]
|
|
45
52
|
},
|
|
46
53
|
"dependencies": {
|
|
47
|
-
"lodash": "^4.17.
|
|
54
|
+
"lodash": "^4.17.20"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
50
|
-
"grunt": "^1.
|
|
51
|
-
"grunt-contrib-
|
|
57
|
+
"grunt": "^1.6.1",
|
|
58
|
+
"grunt-contrib-jshint": "^3.2.0",
|
|
52
59
|
"grunt-contrib-watch": "^1.1.0",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
60
|
+
"grunt-terser": "^2.0.0",
|
|
61
|
+
"jasmine": "^5.13.0",
|
|
62
|
+
"karma": "^6.4.4",
|
|
63
|
+
"karma-chrome-launcher": "^3.2.0",
|
|
64
|
+
"karma-coverage": "^2.2.1",
|
|
65
|
+
"karma-firefox-launcher": "^2.1.3",
|
|
66
|
+
"karma-jasmine": "^5.1.0",
|
|
67
|
+
"nyc": "^17.1.0"
|
|
55
68
|
}
|
|
56
69
|
}
|