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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016-present, Belexos GmbH
1
+ Copyright 2016-present, tbillenstein
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
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 Browser.
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/belexos/hookney/blob/master/hookney.js) unminified, including comments
31
- * [`hookney.min.js`](https://github.com/belexos/hookney/blob/master/hookney.min.js) minified version
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.5/lodash.min.js"></script>
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.5/lodash.min.js"></script>
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 'options' parameter.
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 'options' parameter, please refer to 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 'reviver' is supported.
204
- Please refer to the [JSON.parse() documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
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 'options' parameter.
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 'options' parameter, please refer to 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 'replacer' and 'space' are supported.
250
- Please refer to the [JSON.stringify() documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
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/belexos/hookney/blob/master/spec/HookneySpec.js) for more examples.
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 are using [Jasmine testing framework](https://jasmine.github.io/index.html) and [Istanbul test coverage framework](https://istanbul.js.org/).
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 `grunt` in project directory to build `hookney.min.js` from `hookney.js`.
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/belexos/hookney/issues) for requests.
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 able to reproduce the issue.
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. When the bug is fixed, your pull request can then be merged.
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 in the issue which will reproduce the bug.
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: [support@belexos.com](mailto:support@belexos.com)
298
- * Follow us on Twitter: [@belexos](http://twitter.com/belexos)
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, Belexos GmbH. `Hookney` is licensed under the [MIT License](https://github.com/belexos/hookney/blob/master/LICENSE).
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 Browser.
2
+ * Hookney - Helper around self referencing JSON objects for Node.js and the browser.
3
3
  *
4
- * @copyright: Copyright (c) 2016-present, Belexos GmbH
4
+ * @copyright: Copyright (c) 2016-present, tbillenstein
5
5
  *
6
- * @author: Br00ze <br00ze@belexos.com> (http://belexos.com)
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.4, Copyright (c) 2016-present, Belexos GmbH. MIT licensed. */
2
- !function(a){function b(){"use strict";function a(c){var g,h,i,k;if(d(c))for(g in c)c.hasOwnProperty(g)&&(h=c[g],d(h)?a(h):e(h)?a(h):f(h)&&(c[g]=b(j,h)));else if(e(c))for(k=c.length,i=0;i<k;i++)h=c[i],d(h)?a(h):e(h)?a(h):f(h)&&(c[i]=b(j,h))}function b(c,d){const e=new RegExp(c,"gm").exec(d);var g;return e&&(g=i.get(k,e[1]),d=d===e[0]?g:d.replace(e[0],f(g)?g:JSON.stringify(g)),f(d)?d=b(c,d):"object"==typeof d&&a(d)),d}const c=arguments.length,k={};var l;for(l=0;l<c;l++)i.merge(k,arguments[l]);this.json=function(){return k},this.stringify=function(a,b){return JSON.stringify(k,a,b)},this.resolveReferences=function(){return a(k),this},g&&(this.writeFile=function(a,b,c){const d=this;c||(c=b,b={}),b=b||{},b.encoding||(b.encoding="utf8"),h.writeFile(a,this.stringify(b.replacer,b.space),b,function(a){a?c(a,null):c(null,d)})},this.writeFileSync=function(a,b){return b=b||{},b.encoding||(b.encoding="utf8"),h.writeFileSync(a,this.stringify(b.replacer,b.space),b),this})}function c(a){var b,c,d,e,f=/"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,g=!1,h=!1,i=!1,j=[],k=0,l=0;for(f.lastIndex=0;b=f.exec(a);)d=RegExp.leftContext,e=RegExp.rightContext,h||i||(c=d.substring(l),g||(c=c.replace(/(\n|\r|\s)*/g,"")),j[k++]=c),l=f.lastIndex,'"'!==b[0]||h||i?"/*"!==b[0]||g||h||i?"*/"!==b[0]||g||!h||i?"//"!==b[0]||g||h||i?"\n"!==b[0]&&"\r"!==b[0]||g||h||!i?h||i||/\n|\r|\s/.test(b[0])||(j[k++]=b[0]):i=!1:i=!0:h=!1:h=!0:(c=d.match(/(\\)*$/),g&&c&&c[0].length%2!=0||(g=!g),l--,e=a.substring(l));return j[k++]=e,j.join("")}function d(a){return"object"==typeof a&&!Array.isArray(a)}function e(a){return Array.isArray(a)}function f(a){return"string"==typeof a}const g="object"==typeof module&&module&&"object"==typeof module.exports,h=g?require("fs"):null,i=g?require("lodash"):a._,j="\\$\\{self\\:(.*?)\\}";g?module.exports=b:a.Hookney=b,b.from=function(){const a=arguments.length,c={};var d;for(d=0;d<a;d++)i.merge(c,arguments[d]);return new b(c)},b.fromString=function(a,d){var e={};return a&&f(a)&&a.length&&(a=c(a),e=JSON.parse(a,d)),new b(e)},g&&(b.fromFile=function(a,d,e){e||(e=d,d={}),d=d||{},d.encoding||(d.encoding="utf8"),h.readFile(a,d,function(f,g){if(f)return void e(f,null);g=c(g);try{e(null,b.fromString(g,d.reviver))}catch(f){f.message=a+": "+f.message,e(f,null)}})},b.fromFileSync=function(a,d){var e;d=d||{},d.encoding||(d.encoding="utf8"),e=h.readFileSync(a,d),e=c(e);try{return b.fromString(e,d.reviver)}catch(b){throw b.message=a+": "+b.message,b}})}(this);
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",
4
- "description": "Hookney is a helper around self referencing JSON objects for Node.js and the Browser.",
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
- "test": "nyc ./node_modules/.bin/jasmine",
11
- "build": "grunt build"
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/belexos/hookney.git"
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": "Br00ze <br00ze@belexos.com> (http://belexos.com)",
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.14"
54
+ "lodash": "^4.17.20"
48
55
  },
49
56
  "devDependencies": {
50
- "grunt": "^1.0.4",
51
- "grunt-contrib-uglify": "^2.3.0",
57
+ "grunt": "^1.6.1",
58
+ "grunt-contrib-jshint": "^3.2.0",
52
59
  "grunt-contrib-watch": "^1.1.0",
53
- "jasmine": "^3.5.0",
54
- "nyc": "^15.0.0"
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
  }