json-file-plus
Advanced tools
Comparing version
@@ -48,3 +48,3 @@ { | ||
"disallowQuotedKeysInObjects": "allButReserved", | ||
"disallowQuotedKeysInObjects": { "allExcept": ["reserved"] }, | ||
@@ -162,11 +162,17 @@ "disallowSpaceAfterObjectKeys": true, | ||
"requireSpaceBeforeObjectValues": true, | ||
"requireSpaceBeforeDestructuredValues": true, | ||
"requireSpaceBeforeObjectValues": true, | ||
"requireSpaceBeforeDestructuredValues": true, | ||
"disallowSpacesInsideTemplateStringPlaceholders": true, | ||
"disallowArrayDestructuringReturn": false, | ||
"disallowArrayDestructuringReturn": false, | ||
"requireNewlineBeforeSingleStatementsInIf": false | ||
"requireNewlineBeforeSingleStatementsInIf": false, | ||
"disallowUnusedVariables": true, | ||
"requireSpacesInsideImportedObjectBraces": true, | ||
"requireUseStrict": true | ||
} | ||
@@ -0,1 +1,10 @@ | ||
[3.3.1](https://github.com/ljharb/json-file-plus/releases/tag/v3.3.1) / 2018-03-20 | ||
================== | ||
* [Fix] resolve the path before passing it into `fs.readFile`, so the error has a normalized path | ||
* [Fix] use `safer-buffer` instead of `Buffer` constructor | ||
* [Refactor] add `object.assign` | ||
* [Deps] update `is`, `node.extend` | ||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `evalmd`, `jscs`, `object-keys`, `tape` | ||
* [Tests] up to `node` `v9.8`, `v8.10`, `v6.13`; use `nvm install-latest-npm`; pin included builds to LTS | ||
[3.3.0](https://github.com/ljharb/json-file-plus/releases/tag/v3.3.0) / 2016-03-22 | ||
@@ -2,0 +11,0 @@ ================== |
15
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var extend = require('node.extend'); | ||
var assign = require('object.assign'); | ||
var is = require('is'); | ||
var promiseback = require('promiseback'); | ||
var Promise = promiseback.Deferred.Promise; | ||
var Buffer = require('safer-buffer').Buffer; | ||
@@ -30,3 +33,3 @@ var checkKey = function checkKey(key) { | ||
JSONData.prototype.get = function (key, callback) { | ||
var data = extend({}, this.data); | ||
var data = assign({}, this.data); | ||
if (is.fn(key)) { | ||
@@ -38,3 +41,3 @@ callback = key; | ||
if (is.hash(value)) { | ||
value = extend({}, value); | ||
value = assign({}, value); | ||
} | ||
@@ -47,3 +50,5 @@ var deferred = promiseback(callback); | ||
JSONData.prototype.set = function (obj) { | ||
if (!is.hash(obj)) { throw new TypeError('object must be a plain object'); } | ||
if (!is.hash(obj)) { | ||
throw new TypeError('object must be a plain object'); | ||
} | ||
extend(true, this.data, obj); | ||
@@ -68,3 +73,3 @@ }; | ||
var indent = this.format.indent || 2; | ||
return new Buffer(JSON.stringify(this.data, null, indent) + endingNewlines); | ||
return Buffer.from(JSON.stringify(this.data, null, indent) + endingNewlines); | ||
}; | ||
@@ -103,3 +108,3 @@ | ||
var deferred = promiseback(callback); | ||
fs.readFile(filename, { encoding: 'utf8' }, function (err, raw) { | ||
fs.readFile(path.resolve(filename), { encoding: 'utf8' }, function (err, raw) { | ||
var file; | ||
@@ -106,0 +111,0 @@ |
{ | ||
"name": "json-file-plus", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"author": { | ||
@@ -20,4 +20,4 @@ "name": "Jordan Harband", | ||
"scripts": { | ||
"pretest": "npm run --silent lint && evalmd README.md", | ||
"test": "npm run tests-only", | ||
"pretest": "npm run --silent lint", | ||
"test": "npm run --silent tests-only", | ||
"tests-only": "node test/test.js", | ||
@@ -27,3 +27,4 @@ "posttest": "npm run --silent security", | ||
"coverage-quiet": "covert test/test.js --quiet", | ||
"lint": "npm run jscs && npm run eslint", | ||
"prelint": "evalmd README.md", | ||
"lint": "npm run --silent jscs && npm run --silent eslint", | ||
"eslint": "eslint *.js test/*.js", | ||
@@ -47,16 +48,19 @@ "jscs": "jscs *.js test/*.js", | ||
"dependencies": { | ||
"is": "^3.1.0", | ||
"node.extend": "^1.1.5", | ||
"promiseback": "^2.0.2" | ||
"is": "^3.2.1", | ||
"node.extend": "^2.0.0", | ||
"object.assign": "^4.0.4", | ||
"promiseback": "^2.0.2", | ||
"safer-buffer": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.5.1", | ||
"@ljharb/eslint-config": "^12.2.1", | ||
"covert": "^1.1.0", | ||
"eslint": "^4.19.0", | ||
"evalmd": "^0.0.17", | ||
"foreach": "^2.0.5", | ||
"object-keys": "^1.0.9", | ||
"covert": "^1.1.0", | ||
"jscs": "^2.11.0", | ||
"eslint": "^2.4.0", | ||
"@ljharb/eslint-config": "^2.1.1", | ||
"nsp": "^2.2.1", | ||
"evalmd": "^0.0.16" | ||
"has": "^1.0.1", | ||
"jscs": "^3.0.7", | ||
"nsp": "^3.2.1", | ||
"object-keys": "^1.0.11", | ||
"tape": "^4.9.0" | ||
}, | ||
@@ -71,2 +75,1 @@ "engines": { | ||
} | ||
{ | ||
"name": "json-file-plus", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"author": { | ||
@@ -20,4 +20,4 @@ "name": "Jordan Harband", | ||
"scripts": { | ||
"pretest": "npm run --silent lint && evalmd README.md", | ||
"test": "npm run tests-only", | ||
"pretest": "npm run --silent lint", | ||
"test": "npm run --silent tests-only", | ||
"tests-only": "node test/test.js", | ||
@@ -27,3 +27,4 @@ "posttest": "npm run --silent security", | ||
"coverage-quiet": "covert test/test.js --quiet", | ||
"lint": "npm run jscs && npm run eslint", | ||
"prelint": "evalmd README.md", | ||
"lint": "npm run --silent jscs && npm run --silent eslint", | ||
"eslint": "eslint *.js test/*.js", | ||
@@ -47,16 +48,19 @@ "jscs": "jscs *.js test/*.js", | ||
"dependencies": { | ||
"is": "^3.1.0", | ||
"node.extend": "^1.1.5", | ||
"promiseback": "^2.0.2" | ||
"is": "^3.2.1", | ||
"node.extend": "^2.0.0", | ||
"object.assign": "^4.1.0", | ||
"promiseback": "^2.0.2", | ||
"safer-buffer": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.5.1", | ||
"@ljharb/eslint-config": "^12.2.1", | ||
"covert": "^1.1.0", | ||
"eslint": "^4.19.0", | ||
"evalmd": "^0.0.17", | ||
"foreach": "^2.0.5", | ||
"object-keys": "^1.0.9", | ||
"covert": "^1.1.0", | ||
"jscs": "^2.11.0", | ||
"eslint": "^2.4.0", | ||
"@ljharb/eslint-config": "^2.1.1", | ||
"nsp": "^2.2.1", | ||
"evalmd": "^0.0.16" | ||
"has": "^1.0.1", | ||
"jscs": "^3.0.7", | ||
"nsp": "^3.2.1", | ||
"object-keys": "^1.0.11", | ||
"tape": "^4.9.0" | ||
}, | ||
@@ -67,2 +71,1 @@ "engines": { | ||
} | ||
@@ -9,2 +9,3 @@ 'use strict'; | ||
var Promise = require('promiseback').Deferred.Promise; | ||
var has = require('has'); | ||
@@ -18,5 +19,3 @@ var noNewlineFilename = 'test/no-trailing-newline.json'; | ||
'null': null, | ||
obj: { | ||
nested: {} | ||
}, | ||
obj: { nested: {} }, | ||
'true': true | ||
@@ -27,4 +26,9 @@ }; | ||
var NODE_010_NOT_FOUND = 34; | ||
var WINDOWS_NODE_7_NOT_FOUND = -4058; | ||
var isFileNotFoundError = function (err) { | ||
return [NODE_010_NOT_FOUND, NODE_011_NOT_FOUND].indexOf(err.errno) > -1; | ||
return [ | ||
NODE_010_NOT_FOUND, | ||
NODE_011_NOT_FOUND, | ||
WINDOWS_NODE_7_NOT_FOUND | ||
].indexOf(err.errno) > -1; | ||
}; | ||
@@ -61,5 +65,5 @@ | ||
errno: err.errno, | ||
path: 'NOT A REAL FILE' | ||
path: path.resolve('NOT A REAL FILE') | ||
}; | ||
if (err.hasOwnProperty('syscall')) { | ||
if (has(err, 'syscall')) { | ||
expectedError.syscall = 'open'; | ||
@@ -74,6 +78,8 @@ } | ||
test('returns an exception if the file has invalid JSON', function (t) { | ||
t.plan(3); | ||
t.plan(4); | ||
jsonFile(__filename, function (err, file) { | ||
t.ok(err instanceof SyntaxError, 'error is a SyntaxError'); | ||
t.equal(err.message, 'Unexpected token \'', 'gives the expected error'); | ||
t.equal(typeof err.message, 'string', 'err.message is a string'); | ||
var expected = 'Unexpected token \''; | ||
t.equal(err.message.slice(0, expected.length), expected, 'gives the expected error'); | ||
t.equal(file, undefined, 'file is undefined'); | ||
@@ -133,3 +139,3 @@ t.end(); | ||
test('#get(): with key, callback', function (st) { | ||
st.plan(2 * keys(testContents).length + 1); | ||
st.plan((2 * keys(testContents).length) + 1); | ||
jsonFile(testFilename, function (err, file) { | ||
@@ -257,3 +263,3 @@ st.error(err, 'no error'); | ||
}; | ||
if (err.hasOwnProperty('syscall')) { | ||
if (has(err, 'syscall')) { | ||
expectedError.syscall = 'open'; | ||
@@ -260,0 +266,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39494
22.03%15
15.38%538
2.67%5
66.67%10
11.11%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated