mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
# add dist
This commit is contained in:
118
ng2-components/ng2-alfresco-documentslist/dist/node_modules/jsonfile/index.js
generated
vendored
Normal file
118
ng2-components/ng2-alfresco-documentslist/dist/node_modules/jsonfile/index.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
var _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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
var jsonfile = {
|
||||
spaces: null,
|
||||
readFile: readFile,
|
||||
readFileSync: readFileSync,
|
||||
writeFile: writeFile,
|
||||
writeFileSync: writeFileSync
|
||||
}
|
||||
|
||||
module.exports = jsonfile
|
Reference in New Issue
Block a user