Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonfile

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonfile - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

5

CHANGELOG.md

@@ -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.

61

lib/jsonfile.js
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc