Initial commit
This commit is contained in:
15
node_modules/jsonfile/LICENSE
generated
vendored
Normal file
15
node_modules/jsonfile/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012-2015, JP Richardson <jprichardson@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
||||
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
||||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
133
node_modules/jsonfile/index.js
generated
vendored
Normal file
133
node_modules/jsonfile/index.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
var _fs
|
||||
try {
|
||||
_fs = require('graceful-fs')
|
||||
} catch (_) {
|
||||
_fs = require('fs')
|
||||
}
|
||||
|
||||
function readFile (file, options, callback) {
|
||||
if (callback == null) {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
if (typeof options === 'string') {
|
||||
options = {encoding: options}
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
var fs = options.fs || _fs
|
||||
|
||||
var shouldThrow = true
|
||||
// DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead
|
||||
if ('passParsingErrors' in options) {
|
||||
shouldThrow = options.passParsingErrors
|
||||
} else if ('throws' in options) {
|
||||
shouldThrow = options.throws
|
||||
}
|
||||
|
||||
fs.readFile(file, options, function (err, data) {
|
||||
if (err) return callback(err)
|
||||
|
||||
data = stripBom(data)
|
||||
|
||||
var obj
|
||||
try {
|
||||
obj = JSON.parse(data, options ? options.reviver : null)
|
||||
} catch (err2) {
|
||||
if (shouldThrow) {
|
||||
err2.message = file + ': ' + err2.message
|
||||
return callback(err2)
|
||||
} else {
|
||||
return callback(null, null)
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, obj)
|
||||
})
|
||||
}
|
||||
|
||||
function readFileSync (file, options) {
|
||||
options = options || {}
|
||||
if (typeof options === 'string') {
|
||||
options = {encoding: options}
|
||||
}
|
||||
|
||||
var fs = options.fs || _fs
|
||||
|
||||
var shouldThrow = true
|
||||
// DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead
|
||||
if ('passParsingErrors' in options) {
|
||||
shouldThrow = options.passParsingErrors
|
||||
} else if ('throws' in options) {
|
||||
shouldThrow = options.throws
|
||||
}
|
||||
|
||||
var content = fs.readFileSync(file, options)
|
||||
content = stripBom(content)
|
||||
|
||||
try {
|
||||
return JSON.parse(content, options.reviver)
|
||||
} catch (err) {
|
||||
if (shouldThrow) {
|
||||
err.message = file + ': ' + err.message
|
||||
throw err
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function writeFile (file, obj, options, callback) {
|
||||
if (callback == null) {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
options = options || {}
|
||||
var fs = options.fs || _fs
|
||||
|
||||
var spaces = typeof options === 'object' && options !== null
|
||||
? 'spaces' in options
|
||||
? options.spaces : this.spaces
|
||||
: this.spaces
|
||||
|
||||
var str = ''
|
||||
try {
|
||||
str = JSON.stringify(obj, options ? options.replacer : null, spaces) + '\n'
|
||||
} catch (err) {
|
||||
if (callback) return callback(err, null)
|
||||
}
|
||||
|
||||
fs.writeFile(file, str, options, callback)
|
||||
}
|
||||
|
||||
function writeFileSync (file, obj, options) {
|
||||
options = options || {}
|
||||
var fs = options.fs || _fs
|
||||
|
||||
var spaces = typeof options === 'object' && options !== null
|
||||
? 'spaces' in options
|
||||
? options.spaces : this.spaces
|
||||
: this.spaces
|
||||
|
||||
var str = JSON.stringify(obj, options.replacer, spaces) + '\n'
|
||||
// not sure if fs.writeFileSync returns anything, but just in case
|
||||
return fs.writeFileSync(file, str, options)
|
||||
}
|
||||
|
||||
function stripBom (content) {
|
||||
// we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
|
||||
if (Buffer.isBuffer(content)) content = content.toString('utf8')
|
||||
content = content.replace(/^\uFEFF/, '')
|
||||
return content
|
||||
}
|
||||
|
||||
var jsonfile = {
|
||||
spaces: null,
|
||||
readFile: readFile,
|
||||
readFileSync: readFileSync,
|
||||
writeFile: writeFile,
|
||||
writeFileSync: writeFileSync
|
||||
}
|
||||
|
||||
module.exports = jsonfile
|
||||
22
node_modules/jsonfile/package.json
generated
vendored
Normal file
22
node_modules/jsonfile/package.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "jsonfile",
|
||||
"version": "2.4.0",
|
||||
"description": "Easily read/write JSON files.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:jprichardson/node-jsonfile.git"
|
||||
},
|
||||
"author": "JP Richardson <jprichardson@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "2.x",
|
||||
"mock-fs": "^3.8.0",
|
||||
"rimraf": "^2.4.0",
|
||||
"standard": "^6.0.8"
|
||||
},
|
||||
"main": "index.js"
|
||||
}
|
||||
Reference in New Issue
Block a user