πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

json-file-plus

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-file-plus - npm Package Compare versions

Comparing version

to
3.0.1

.eslintrc

22

.jscs.json
{
"es3": true,
"additionalRules": [],

@@ -10,4 +12,2 @@

"requirePaddingNewLinesBeforeLineComments": true,
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],

@@ -19,2 +19,16 @@

"disallowSpaceBeforeComma": true,
"disallowSpaceBeforeSemicolon": true,
"disallowNodeTypes": [
"DebuggerStatement",
"ForInStatement",
"LabeledStatement",
"SwitchCase",
"SwitchStatement",
"WithStatement"
],
"requireObjectKeysOnNewLine": true,
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },

@@ -106,4 +120,6 @@ "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },

"requirePaddingNewLinesAfterUseStrict": true
"requirePaddingNewLinesAfterUseStrict": true,
"disallowArrowFunctions": true
}

@@ -0,1 +1,10 @@

[3.0.1](https://github.com/ljharb/node-json-file/releases/tag/v3.0.1) / 2015-08-18
==================
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
* [Deps] update `node.extend`
* [Dev Deps] update `object-keys`, `covert`, `tape`, jscs`
* [Tests] up to `io.js` `v3.0`
* [Tests] add `npm run eslint` and `@ljharb/eslint-config`
* [Tests] add `npm run security`
[3.0.0](https://github.com/ljharb/node-json-file/releases/tag/v3.0.0) / 2015-05-03

@@ -2,0 +11,0 @@ ==================

16

index.js

@@ -0,3 +1,4 @@

'use strict';
var fs = require('fs');
var path = require('path');
var extend = require('node.extend');

@@ -7,3 +8,3 @@ var is = require('is');

var JSONFile = function (filename, raw) {
var JSONFile = function JSONFile(filename, raw) {
var hasTrailingNewline = (/\n\n$/).test(raw);

@@ -65,10 +66,11 @@ var indentMatch = String(raw).match(/^[ \t]+/m);

if (!err) {
try { file = new JSONFile(filename, raw); }
catch (e) { err = e; }
}
if (err) {
deferred.reject(err);
} else {
deferred.resolve(file);
try {
file = new JSONFile(filename, raw);
deferred.resolve(file);
} catch (e) {
deferred.reject(e);
}
}

@@ -75,0 +77,0 @@ });

{
"name": "json-file-plus",
"version": "3.0.0",
"version": "3.0.1",
"author": "Jordan Harband",

@@ -9,6 +9,9 @@ "description": "Read from and write to a JSON file, minimizing diffs and preserving formatting.",

"scripts": {
"test": "npm run lint && node test/test.js",
"test": "npm run lint && node test/test.js && npm run security",
"coverage": "covert test/test.js",
"coverage-quiet": "covert test/test.js --quiet",
"lint": "jscs *.js test/*.js"
"lint": "npm run jscs && npm run eslint",
"eslint": "eslint *.js test/*.js",
"jscs": "jscs *.js test/*.js",
"security": "nsp package"
},

@@ -30,11 +33,14 @@ "repository": {

"is": "^3.0.1",
"node.extend": "^1.1.3",
"node.extend": "^1.1.5",
"promiseback": "^2.0.1"
},
"devDependencies": {
"tape": "^4.0.0",
"tape": "^4.2.0",
"foreach": "^2.0.5",
"object-keys": "^1.0.3",
"covert": "^1.0.1",
"jscs": "^1.13.1"
"object-keys": "^1.0.7",
"covert": "^1.1.0",
"jscs": "^2.1.0",
"eslint": "^1.2.0",
"@ljharb/eslint-config": "^1.0.5",
"nsp": "^1.0.3"
},

@@ -41,0 +47,0 @@ "engines": {

@@ -58,3 +58,3 @@ #json-file-plus <sup>[![Version Badge][npm-version-svg]][npm-url]</sup>

[npm-url]: https://npmjs.org/package/json-file-plus
[npm-version-svg]: http://vb.teelaun.ch/ljharb/node-json-file.svg
[npm-version-svg]: http://versionbadg.es/ljharb/node-json-file.svg
[travis-svg]: https://travis-ci.org/ljharb/node-json-file.svg

@@ -61,0 +61,0 @@ [travis-url]: https://travis-ci.org/ljharb/node-json-file

@@ -0,1 +1,3 @@

'use strict';
var test = require('tape');

@@ -11,5 +13,5 @@ var path = require('path');

foo: 'bar',
null: null,
true: true,
false: false,
'null': null,
'true': true,
'false': false,
arr: [1, 2, 3],

@@ -27,8 +29,8 @@ obj: {

t.plan(6);
t.throws(function () { jsonFile(testFilename, undefined); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, null); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, true); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, /a/g); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, []); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, {}); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, undefined); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, null); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, true); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, /a/g); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, []); }, TypeError, 'requires a function');
t['throws'](function () { jsonFile(testFilename, {}); }, TypeError, 'requires a function');
t.end();

@@ -52,4 +54,4 @@ });

var expectedError = {
code: 'ENOENT',
errno: err.errno,
code: 'ENOENT',
path: 'NOT A REAL FILE'

@@ -70,3 +72,3 @@ };

t.ok(err instanceof SyntaxError, 'error is a SyntaxError');
t.equal(err.message, 'Unexpected token v', 'gives the expected error');
t.equal(err.message, 'Unexpected token \'', 'gives the expected error');
t.equal(file, undefined, 'file is undefined');

@@ -90,6 +92,6 @@ t.end();

s1t.plan(3);
jsonFile(noNewlineFilename, function (err, file) {
s1t.error(err, 'no error');
s1t.notOk(file.format.trailing, 'reads no trailing newline');
s1t.equal(file.format.indent, ' ', 'reads three spaces');
jsonFile(noNewlineFilename, function (noErr, noNewlineFile) {
s1t.error(noErr, 'no error');
s1t.notOk(noNewlineFile.format.trailing, 'reads no trailing newline');
s1t.equal(noNewlineFile.format.indent, ' ', 'reads three spaces');
s1t.end();

@@ -127,7 +129,8 @@ });

test('#get(): with key, callback', function (st) {
st.plan(keys(testContents).length + 1);
st.plan(2 * keys(testContents).length + 1);
jsonFile(testFilename, function (err, file) {
st.error(err, 'no error');
forEach(testContents, function (keyContents, key) {
file.get(key, function (err, data) {
file.get(key, function (noError, data) {
st.error(noError, 'no error');
st.deepEqual(data, keyContents, 'data from callback get("' + key + '") matches');

@@ -152,6 +155,7 @@ });

test('#get(): without key, callback', function (s2t) {
s2t.plan(3);
jsonFile(testFilename, function (err, file) {
s2t.error(err, 'no error');
file.get(function (err, data) {
s2t.plan(4);
jsonFile(testFilename, function (noLoadError, file) {
s2t.error(noLoadError, 'no error');
file.get(function (noError, data) {
s2t.error(noError, 'no error');
s2t.deepEqual(data, file.data, 'data from async get() matches');

@@ -188,8 +192,8 @@ s2t.notEqual(data, file.data, 'data from async get() is not the same reference');

var error = new TypeError('object must be a plain object');
st.throws(function () { return file.set(null); }, error, 'throws when given non-object');
st.throws(function () { return file.set(true); }, error, 'throws when given non-object');
st.throws(function () { return file.set([]); }, error, 'throws when given non-object');
st.throws(function () { return file.set(function () {}); }, error, 'throws when given non-object');
st.throws(function () { return file.set('foo'); }, error, 'throws when given non-object');
st.throws(function () { return file.set(/f/); }, error, 'throws when given non-object');
st['throws'](function () { return file.set(null); }, error, 'throws when given non-object');
st['throws'](function () { return file.set(true); }, error, 'throws when given non-object');
st['throws'](function () { return file.set([]); }, error, 'throws when given non-object');
st['throws'](function () { return file.set(function () {}); }, error, 'throws when given non-object');
st['throws'](function () { return file.set('foo'); }, error, 'throws when given non-object');
st['throws'](function () { return file.set(/f/); }, error, 'throws when given non-object');
st.end();

@@ -200,6 +204,7 @@ });

test('returns an error when no file', function (t) {
t.plan(3);
t.plan(4);
var filename = path.join(process.cwd(), 'does not exist.json');
jsonFile(filename, function (err, file) {
t.ok(err, 'error is truthy');
t.notOk(file, 'file is falsy');
t.ok(isFileNotFoundError(err), 'error number is correct');

@@ -228,8 +233,9 @@ var expectedError = {

test('saves properly', function (t) {
t.plan(5);
jsonFile(testFilename, function (err, file) {
t.plan(6);
jsonFile(testFilename, function (noLoadError, file) {
t.error(noLoadError, 'no error');
t.equal(file.filename, testFilename, 'filename equals ' + testFilename);
file.set({ foo: !testContents.foo });
file.save(function (err) {
t.error(err, 'no error');
file.save(function (noError) {
t.error(noError, 'no error');
jsonFile(testFilename, function (err, file2) {

@@ -239,7 +245,7 @@ file2.get('foo').then(function (value) {

file2.set({ foo: testContents.foo }); // restore original value
file2.save(function (err) {
t.error(err, 'save callback: no error');
file2.save(function (noSaveError) {
t.error(noSaveError, 'save callback: no error');
}).then(function () {
t.ok(true, 'save promise: success');
})['catch'](function (err) {
})['catch'](function () {
t.fail('save promise: error. should not be here.');

@@ -246,0 +252,0 @@ });

Sorry, the diff of this file is not supported yet