Comparing version 0.0.1 to 1.0.0
@@ -0,3 +1,8 @@ | ||
1.0.0 / 2013-06-28 | ||
------------------ | ||
* added `.npmignore`, #1 | ||
* changed spacing default from `4` to `2` to follow Node conventions | ||
0.0.1 / 2012-09-10 | ||
------------------ | ||
* Initial release. |
var fs = require('fs'); | ||
module.exports.spaces = 4; | ||
var me = module.exports; | ||
function readFile(file, callback) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
if (err) { | ||
callback(err, null); | ||
} else { | ||
try { | ||
var obj = JSON.parse(data); | ||
callback(null, obj); | ||
} catch (err2) { | ||
callback(err2, null); | ||
} | ||
} | ||
}) | ||
} | ||
me.spaces = 2; | ||
function readFileSync(file) { | ||
var data = fs.readFileSync(file, 'utf8'); | ||
return JSON.parse(data); | ||
me.readFile = function(file, callback) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
if (err) return callback(err, null); | ||
try { | ||
var obj = JSON.parse(data); | ||
callback(null, obj); | ||
} catch (err2) { | ||
callback(err2, null); | ||
} | ||
}) | ||
} | ||
function writeFile(file, obj, callback) { | ||
var str = ''; | ||
try { | ||
str = JSON.stringify(obj, null, module.exports.spaces); | ||
} catch (err) { | ||
callback(err, null); | ||
} | ||
fs.writeFile(file, str, callback); | ||
me.readFileSync = function(file) { | ||
return JSON.parse(fs.readFileSync(file, 'utf8')); | ||
} | ||
function writeFileSync(file, obj) { | ||
var str = JSON.stringify(obj, null, module.exports.spaces); | ||
return fs.writeFileSync(file, str); //not sure if fs.writeFileSync returns anything, but just in case | ||
me.writeFile = function(file, obj, callback) { | ||
var str = ''; | ||
try { | ||
str = JSON.stringify(obj, null, module.exports.spaces); | ||
} catch (err) { | ||
callback(err, null); | ||
} | ||
fs.writeFile(file, str, callback); | ||
} | ||
module.exports.readFile = readFile; | ||
module.exports.readFileSync = readFileSync; | ||
module.exports.writeFile = writeFile; | ||
module.exports.writeFileSync = writeFileSync; | ||
me.writeFileSync = function(file, obj) { | ||
var str = JSON.stringify(obj, null, module.exports.spaces); | ||
return fs.writeFileSync(file, str); //not sure if fs.writeFileSync returns anything, but just in case | ||
} |
{ | ||
"name": "jsonfile", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Easily read/write JSON files.", | ||
@@ -22,5 +22,4 @@ "homepage": [ | ||
"devDependencies": { | ||
"mkdirp": "~0.3.4", | ||
"testutil": "~0.2.2", | ||
"mocha": "~1.4.2" | ||
"testutil": "~0.5.1", | ||
"mocha": "*" | ||
}, | ||
@@ -27,0 +26,0 @@ "main": "./lib/jsonfile.js", |
@@ -19,3 +19,3 @@ [![build status](https://secure.travis-ci.org/jprichardson/node-jsonfile.png)](http://travis-ci.org/jprichardson/node-jsonfile) | ||
npm install jsonfile | ||
npm install jsonfile --save | ||
@@ -35,3 +35,3 @@ | ||
js.readFile(file, function(err, obj) { | ||
console.log(util.inspect(obj)); | ||
console.log(util.inspect(obj)); | ||
}); | ||
@@ -62,3 +62,3 @@ ``` | ||
jf.writeFile(file, obj, function(err) { | ||
console.log(err); | ||
console.log(err); | ||
}) | ||
@@ -83,3 +83,3 @@ ``` | ||
**default:** 4 | ||
**default:** 2 | ||
@@ -89,3 +89,3 @@ ``` | ||
jf.spaces = 2; | ||
jf.spaces = 4; | ||
@@ -95,4 +95,4 @@ var file = '/tmp/data.json'; | ||
jf.writeFile(file, obj, function(err) { //json file has two space indenting now | ||
console.log(err); | ||
jf.writeFile(file, obj, function(err) { //json file has four space indenting now | ||
console.log(err); | ||
}); | ||
@@ -102,9 +102,2 @@ ``` | ||
Author | ||
------ | ||
`node-jsonfile` was written by [JP Richardson][aboutjp]. You should follow him on Twitter [@jprichardson][twitter]. Also read his coding blog [Procbits][procbits]. If you write software with others, you should checkout [Gitpilot][gitpilot] to make collaboration with Git simple. | ||
License | ||
@@ -115,3 +108,3 @@ ------- | ||
Copyright 2012, JP Richardson <jprichardson@gmail.com> | ||
Copyright 2012-2013, JP Richardson <jprichardson@gmail.com> | ||
@@ -122,4 +115,4 @@ | ||
[procbits]: http://procbits.com | ||
[gitpilot]: http://gitpilot.com | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
0
0
1
4355
6
29
110
1