Comparing version 1.1.1 to 1.2.0
@@ -0,1 +1,7 @@ | ||
1.2.0 / 2014-06-29 | ||
------------------ | ||
* removed semicolons | ||
* bugfix: passed `options` to `fs.readFile` and `fs.readFileSync`. This technically changes behavior, but | ||
changes it according to docs. #12 | ||
1.1.1 / 2013-11-11 | ||
@@ -2,0 +8,0 @@ ------------------ |
@@ -1,47 +0,50 @@ | ||
var fs = require('fs'); | ||
var fs = require('fs') | ||
var me = module.exports; | ||
var me = module.exports | ||
me.spaces = 2; | ||
me.spaces = 2 | ||
me.readFile = function(file, callback) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
if (err) return callback(err, null); | ||
me.readFile = function(file, options, callback) { | ||
if (callback == undefined) { | ||
callback = options | ||
options = null | ||
} | ||
var obj = null; | ||
fs.readFile(file, options, function(err, data) { | ||
if (err) return callback(err, null) | ||
var obj = null | ||
try { | ||
obj = JSON.parse(data); | ||
obj = JSON.parse(data) | ||
} catch (err2) { | ||
callback(err2, null); | ||
return; | ||
return callback(err2, null) | ||
} | ||
callback(null, obj); | ||
callback(null, obj) | ||
}) | ||
} | ||
me.readFileSync = function(file) { | ||
return JSON.parse(fs.readFileSync(file, 'utf8')); | ||
me.readFileSync = function(file, options) { | ||
return JSON.parse(fs.readFileSync(file, options)) | ||
} | ||
me.writeFile = function(file, obj, options, callback) { | ||
if (callback == null) { // odd little swap because options is optional | ||
callback = options; | ||
options = null; | ||
if (callback == undefined) { | ||
callback = options | ||
options = null | ||
} | ||
var str = ''; | ||
var str = '' | ||
try { | ||
str = JSON.stringify(obj, null, module.exports.spaces); | ||
str = JSON.stringify(obj, null, me.spaces) | ||
} catch (err) { | ||
if (callback) { | ||
callback(err, null); | ||
} | ||
return; | ||
if (callback) return callback(err, null) | ||
} | ||
fs.writeFile(file, str, options, callback); | ||
fs.writeFile(file, str, options, callback) | ||
} | ||
me.writeFileSync = function(file, obj, options) { | ||
var str = JSON.stringify(obj, null, module.exports.spaces); | ||
return fs.writeFileSync(file, str, options); //not sure if fs.writeFileSync returns anything, but just in case | ||
} | ||
var str = JSON.stringify(obj, null, me.spaces) | ||
return fs.writeFileSync(file, str, options) //not sure if fs.writeFileSync returns anything, but just in case | ||
} |
{ | ||
"name": "jsonfile", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Easily read/write JSON files.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -29,7 +29,7 @@ [![build status](https://secure.travis-ci.org/jprichardson/node-jsonfile.png)](http://travis-ci.org/jprichardson/node-jsonfile) | ||
```javascript | ||
var jf = require('jsonfile') | ||
, util = require('util'); | ||
var jf = require('jsonfile'); | ||
var util = require('util'); | ||
var file = '/tmp/data.json'; | ||
js.readFile(file, function(err, obj) { | ||
jf.readFile(file, function(err, obj) { | ||
console.log(util.inspect(obj)); | ||
@@ -43,4 +43,4 @@ }); | ||
```javascript | ||
var jf = require('jsonfile') | ||
, util = require('util'); | ||
var jf = require('jsonfile'); | ||
var util = require('util'); | ||
@@ -111,2 +111,4 @@ var file = '/tmp/data.json'; | ||
- [1] [Federico Fissore](https://github.com/ffissore) | ||
- [1] [Ivan McCarthy](https://github.com/imcrthy) | ||
- [1] [Pablo Vallejo](https://github.com/PabloVallejo) | ||
@@ -119,3 +121,3 @@ | ||
Copyright 2012-2013, JP Richardson <jprichardson@gmail.com> | ||
Copyright 2012-2014, JP Richardson <jprichardson@gmail.com> | ||
@@ -122,0 +124,0 @@ |
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
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
5499
39
124