chore: add pkg dependencies
This commit is contained in:
88
node_modules/jsonfile/index.js
generated
vendored
Normal file
88
node_modules/jsonfile/index.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
let _fs
|
||||
try {
|
||||
_fs = require('graceful-fs')
|
||||
} catch (_) {
|
||||
_fs = require('fs')
|
||||
}
|
||||
const universalify = require('universalify')
|
||||
const { stringify, stripBom } = require('./utils')
|
||||
|
||||
async function _readFile (file, options = {}) {
|
||||
if (typeof options === 'string') {
|
||||
options = { encoding: options }
|
||||
}
|
||||
|
||||
const fs = options.fs || _fs
|
||||
|
||||
const shouldThrow = 'throws' in options ? options.throws : true
|
||||
|
||||
let data = await universalify.fromCallback(fs.readFile)(file, options)
|
||||
|
||||
data = stripBom(data)
|
||||
|
||||
let obj
|
||||
try {
|
||||
obj = JSON.parse(data, options ? options.reviver : null)
|
||||
} catch (err) {
|
||||
if (shouldThrow) {
|
||||
err.message = `${file}: ${err.message}`
|
||||
throw err
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
const readFile = universalify.fromPromise(_readFile)
|
||||
|
||||
function readFileSync (file, options = {}) {
|
||||
if (typeof options === 'string') {
|
||||
options = { encoding: options }
|
||||
}
|
||||
|
||||
const fs = options.fs || _fs
|
||||
|
||||
const shouldThrow = 'throws' in options ? options.throws : true
|
||||
|
||||
try {
|
||||
let content = fs.readFileSync(file, options)
|
||||
content = stripBom(content)
|
||||
return JSON.parse(content, options.reviver)
|
||||
} catch (err) {
|
||||
if (shouldThrow) {
|
||||
err.message = `${file}: ${err.message}`
|
||||
throw err
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function _writeFile (file, obj, options = {}) {
|
||||
const fs = options.fs || _fs
|
||||
|
||||
const str = stringify(obj, options)
|
||||
|
||||
await universalify.fromCallback(fs.writeFile)(file, str, options)
|
||||
}
|
||||
|
||||
const writeFile = universalify.fromPromise(_writeFile)
|
||||
|
||||
function writeFileSync (file, obj, options = {}) {
|
||||
const fs = options.fs || _fs
|
||||
|
||||
const str = stringify(obj, options)
|
||||
// not sure if fs.writeFileSync returns anything, but just in case
|
||||
return fs.writeFileSync(file, str, options)
|
||||
}
|
||||
|
||||
const jsonfile = {
|
||||
readFile,
|
||||
readFileSync,
|
||||
writeFile,
|
||||
writeFileSync
|
||||
}
|
||||
|
||||
module.exports = jsonfile
|
40
node_modules/jsonfile/package.json
generated
vendored
Normal file
40
node_modules/jsonfile/package.json
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "jsonfile",
|
||||
"version": "6.1.0",
|
||||
"description": "Easily read/write JSON files.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:jprichardson/node-jsonfile.git"
|
||||
},
|
||||
"keywords": [
|
||||
"read",
|
||||
"write",
|
||||
"file",
|
||||
"json",
|
||||
"fs",
|
||||
"fs-extra"
|
||||
],
|
||||
"author": "JP Richardson <jprichardson@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^8.2.0",
|
||||
"rimraf": "^2.4.0",
|
||||
"standard": "^16.0.1"
|
||||
},
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
"utils.js"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test": "npm run lint && npm run unit",
|
||||
"unit": "mocha"
|
||||
}
|
||||
}
|
14
node_modules/jsonfile/utils.js
generated
vendored
Normal file
14
node_modules/jsonfile/utils.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
function stringify (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
|
||||
const EOF = finalEOL ? EOL : ''
|
||||
const str = JSON.stringify(obj, replacer, spaces)
|
||||
|
||||
return str.replace(/\n/g, EOL) + EOF
|
||||
}
|
||||
|
||||
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')
|
||||
return content.replace(/^\uFEFF/, '')
|
||||
}
|
||||
|
||||
module.exports = { stringify, stripBom }
|
Reference in New Issue
Block a user