Comparing version 0.3.4 to 0.3.5
@@ -1,35 +0,35 @@ | ||
'use strict'; | ||
'use strict' | ||
//==================================================================== | ||
// =================================================================== | ||
var Bluebird = require('bluebird'); | ||
var Bluebird = require('bluebird') | ||
var fs$readFile = require('fs-promise').readFile; | ||
var j = require('path').join; | ||
var resolvePath = require('path').resolve; | ||
var fs$readFile = require('fs-promise').readFile | ||
var j = require('path').join | ||
var resolvePath = require('path').resolve | ||
var flatten = require('lodash.flatten'); | ||
var glob = Bluebird.promisify(require('glob')); | ||
var xdgBasedir = require('xdg-basedir'); | ||
var flatten = require('lodash.flatten') | ||
var glob = Bluebird.promisify(require('glob')) | ||
var xdgBasedir = require('xdg-basedir') | ||
//==================================================================== | ||
// =================================================================== | ||
function readFile(path) { | ||
function readFile (path) { | ||
return fs$readFile(path).then(function (buffer) { | ||
return { | ||
path: path, | ||
content: buffer, | ||
}; | ||
}); | ||
content: buffer | ||
} | ||
}) | ||
} | ||
function ignoreAccessErrors(error) { | ||
function ignoreAccessErrors (error) { | ||
if (error.cause.code !== 'EACCES') { | ||
throw error; | ||
throw error | ||
} | ||
return []; | ||
return [] | ||
} | ||
//==================================================================== | ||
// =================================================================== | ||
@@ -48,4 +48,4 @@ // Default configuration entries. | ||
readFile | ||
); | ||
}, | ||
) | ||
} | ||
}, | ||
@@ -57,3 +57,3 @@ | ||
read: function (opts) { | ||
var name = opts.name; | ||
var name = opts.name | ||
@@ -63,3 +63,3 @@ return Bluebird.map( | ||
readFile | ||
); | ||
) | ||
} | ||
@@ -72,8 +72,8 @@ }, | ||
read: function (opts) { | ||
var configDir = xdgBasedir.config; | ||
var configDir = xdgBasedir.config | ||
if (!configDir) { | ||
return Bluebird.resolve([]); | ||
return Bluebird.resolve([]) | ||
} | ||
var name = opts.name; | ||
var name = opts.name | ||
@@ -83,3 +83,3 @@ return Bluebird.map( | ||
readFile | ||
); | ||
) | ||
} | ||
@@ -93,13 +93,13 @@ }, | ||
read: function (opts) { | ||
var name = opts.name; | ||
var name = opts.name | ||
// Compute the list of paths from the current directory to the | ||
// root directory. | ||
var paths = []; | ||
var dir, prev; | ||
dir = process.cwd(); | ||
var paths = [] | ||
var dir, prev | ||
dir = process.cwd() | ||
while (dir !== prev) { | ||
paths.push(j(dir, '.' + name + '.*')); | ||
prev = dir; | ||
dir = resolvePath(dir, '..'); | ||
paths.push(j(dir, '.' + name + '.*')) | ||
prev = dir | ||
dir = resolvePath(dir, '..') | ||
} | ||
@@ -109,7 +109,7 @@ | ||
return glob(path, { | ||
silent: true, | ||
}).catch(ignoreAccessErrors); | ||
}).then(flatten).map(readFile); | ||
silent: true | ||
}).catch(ignoreAccessErrors) | ||
}).then(flatten).map(readFile) | ||
} | ||
}, | ||
]; | ||
} | ||
] |
98
index.js
@@ -1,44 +0,43 @@ | ||
'use strict'; | ||
'use strict' | ||
//==================================================================== | ||
// =================================================================== | ||
var Bluebird = require('bluebird'); | ||
Bluebird.longStackTraces(); | ||
var dirname = require('path').dirname | ||
var getFileStats = require('fs-promise').stat | ||
var resolvePath = require('path').resolve | ||
var dirname = require('path').dirname; | ||
var getFileStats = require('fs-promise').stat; | ||
var resolvePath = require('path').resolve; | ||
var Bluebird = require('bluebird') | ||
var debug = require('debug')('app-conf') | ||
var flatten = require('lodash.flatten') | ||
var isObject = require('lodash.isobject') | ||
var isString = require('lodash.isstring') | ||
var map = require('lodash.map') | ||
var merge = require('lodash.merge') | ||
var flatten = require('lodash.flatten'); | ||
var isObject = require('lodash.isobject'); | ||
var isString = require('lodash.isstring'); | ||
var map = require('lodash.map'); | ||
var merge = require('lodash.merge'); | ||
var entries = require('./entries') | ||
var UnknownFormatError = require('./unknown-format-error') | ||
var unserialize = require('./serializers').unserialize | ||
var entries = require('./entries'); | ||
var UnknownFormatError = require('./unknown-format-error'); | ||
var unserialize = require('./serializers').unserialize; | ||
// =================================================================== | ||
//==================================================================== | ||
function isPath(path) { | ||
function isPath (path) { | ||
return getFileStats(path).then(function () { | ||
return true; | ||
return true | ||
}).catch(function () { | ||
return false; | ||
}); | ||
return false | ||
}) | ||
} | ||
function fixPaths(value, base) { | ||
var path; | ||
function fixPaths (value, base) { | ||
var path | ||
if (isString(value)) { | ||
path = resolvePath(base, value); | ||
path = resolvePath(base, value) | ||
return isPath(path).then(function (isPath) { | ||
if (isPath) { | ||
return path; | ||
return path | ||
} | ||
return value; | ||
}); | ||
return value | ||
}) | ||
} | ||
@@ -49,41 +48,44 @@ | ||
return fixPaths(item, base).then(function (item) { | ||
value[key] = item; | ||
}); | ||
}); | ||
return Bluebird.all(promises).return(value); | ||
value[key] = item | ||
}) | ||
}) | ||
return Bluebird.all(promises).return(value) | ||
} | ||
return Bluebird.resolve(value); | ||
return Bluebird.resolve(value) | ||
} | ||
function noop() {} | ||
function noop () {} | ||
function rethrow(error) { | ||
throw error; | ||
function rethrow (error) { | ||
throw error | ||
} | ||
//==================================================================== | ||
// =================================================================== | ||
function load(name, opts) { | ||
opts || (opts = {}); | ||
function load (name, opts) { | ||
opts || (opts = {}) | ||
var defaults = merge({}, opts.defaults || {}); | ||
var defaults = merge({}, opts.defaults || {}) | ||
var unknownFormatHandler = opts.ignoreUnknownFormats ? noop : rethrow; | ||
var unknownFormatHandler = opts.ignoreUnknownFormats ? noop : rethrow | ||
return Bluebird.map(entries, function (entry) { | ||
return entry.read({ name: name }); | ||
}).then(flatten).map(function (file) { | ||
return entry.read({ name: name }) | ||
}).then(flatten).each(function (file) { | ||
debug(file.path) | ||
return file | ||
}).map(function (file) { | ||
return Bluebird.try(unserialize, [file]).then(function (value) { | ||
return fixPaths(value, dirname(file.path)); | ||
}).catch(UnknownFormatError, unknownFormatHandler); | ||
return fixPaths(value, dirname(file.path)) | ||
}).catch(UnknownFormatError, unknownFormatHandler) | ||
}).each(function (value) { | ||
if (value) { | ||
merge(defaults, value); | ||
merge(defaults, value) | ||
} | ||
}).return(defaults); | ||
}).return(defaults) | ||
} | ||
//==================================================================== | ||
// =================================================================== | ||
exports.load = load; | ||
exports.load = load |
{ | ||
"name": "app-conf", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "", | ||
"keywords": [], | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "mocha --require must index.spec.js" | ||
@@ -19,3 +20,4 @@ }, | ||
"mock-fs": "^2.5.0", | ||
"must": "^0.12.0" | ||
"must": "^0.12.0", | ||
"standard": "^4.0.1" | ||
}, | ||
@@ -30,14 +32,15 @@ "files": [ | ||
"bluebird": "^2.2.2", | ||
"debug": "^2.2.0", | ||
"fs-promise": "^0.3.1", | ||
"glob": "^4.0.5", | ||
"lodash.findkey": "^2.4.1", | ||
"lodash.flatten": "^2.4.1", | ||
"lodash.isobject": "^2.4.1", | ||
"lodash.isstring": "^2.4.1", | ||
"lodash.keys": "^2.4.1", | ||
"lodash.map": "^2.4.1", | ||
"lodash.merge": "^2.4.1", | ||
"make-error": "^0.3.0", | ||
"glob": "^5", | ||
"lodash.findkey": "^3", | ||
"lodash.flatten": "^3", | ||
"lodash.isobject": "^3", | ||
"lodash.isstring": "^3", | ||
"lodash.keys": "^3", | ||
"lodash.map": "^3", | ||
"lodash.merge": "^3", | ||
"make-error": "^1", | ||
"xdg-basedir": "^1.0.0" | ||
} | ||
} |
@@ -1,21 +0,21 @@ | ||
'use strict'; | ||
'use strict' | ||
//==================================================================== | ||
// =================================================================== | ||
var findKey = require('lodash.findkey'); | ||
var findKey = require('lodash.findkey') | ||
var stripJsonComments; | ||
var stripJsonComments | ||
try { | ||
stripJsonComments = require('strip-json-comments'); | ||
stripJsonComments = require('strip-json-comments') | ||
} catch (error) { | ||
stripJsonComments = function identity(val) { | ||
return val; | ||
}; | ||
stripJsonComments = function identity (val) { | ||
return val | ||
} | ||
} | ||
var UnknownFormatError = require('./unknown-format-error'); | ||
var UnknownFormatError = require('./unknown-format-error') | ||
//==================================================================== | ||
// =================================================================== | ||
var serializers = Object.create(null); | ||
var serializers = Object.create(null) | ||
@@ -25,3 +25,3 @@ serializers.json = { | ||
test: function (file) { | ||
return (file.path && /\.json$/i.test(file.path)); | ||
return (file.path && /\.json$/i.test(file.path)) | ||
}, | ||
@@ -31,3 +31,3 @@ | ||
unserialize: function (file) { | ||
return JSON.parse(stripJsonComments(String(file.content))); | ||
return JSON.parse(stripJsonComments(String(file.content))) | ||
}, | ||
@@ -37,24 +37,24 @@ | ||
serialize: function (value, opts) { | ||
opts || (opts = {}); | ||
var indent = 'indent' in opts ? opts.indent : 2; | ||
opts || (opts = {}) | ||
var indent = 'indent' in opts ? opts.indent : 2 | ||
return JSON.stringify(value, null, indent); | ||
}, | ||
}; | ||
return JSON.stringify(value, null, indent) | ||
} | ||
} | ||
// Optional dependency. | ||
try { | ||
var ini = require('ini'); | ||
var ini = require('ini') | ||
serializers.ini = { | ||
test: function (file) { | ||
return (file.path && /\.ini$/i.test(file.path)); | ||
return (file.path && /\.ini$/i.test(file.path)) | ||
}, | ||
unserialize: function (file) { | ||
return ini.decode(String(file.content)); | ||
return ini.decode(String(file.content)) | ||
}, | ||
serialize: function (value) { | ||
return ini.encode(value); | ||
}, | ||
}; | ||
return ini.encode(value) | ||
} | ||
} | ||
} catch (error) {} | ||
@@ -64,54 +64,54 @@ | ||
try { | ||
var yaml = require('js-yaml'); | ||
var yaml = require('js-yaml') | ||
serializers.yaml = { | ||
test: function (file) { | ||
return (file.path && /\.yaml$/i.test(file.path)); | ||
return (file.path && /\.yaml$/i.test(file.path)) | ||
}, | ||
unserialize: function (file) { | ||
return yaml.safeLoad(String(file.content)); | ||
return yaml.safeLoad(String(file.content)) | ||
}, | ||
serialize: function (value, opts) { | ||
opts || (opts = {}); | ||
var indent = 'indent' in opts ? opts.indent : 2; | ||
opts || (opts = {}) | ||
var indent = 'indent' in opts ? opts.indent : 2 | ||
return yaml.safeDump(value, { | ||
indent: indent, | ||
}); | ||
}, | ||
}; | ||
indent: indent | ||
}) | ||
} | ||
} | ||
} catch (error) {} | ||
//-------------------------------------------------------------------- | ||
// -------------------------------------------------------------------- | ||
var detectFormat = function (file) { | ||
return findKey(serializers, function (serializer) { | ||
return serializer.test(file); | ||
}); | ||
}; | ||
return serializer.test(file) | ||
}) | ||
} | ||
var serialize = function (value, format, opts) { | ||
var buffer = serializers[format].serialize(value, opts); | ||
var buffer = serializers[format].serialize(value, opts) | ||
if (!(buffer instanceof Buffer)) { | ||
buffer = new Buffer(buffer); | ||
buffer = new Buffer(buffer) | ||
} | ||
return buffer; | ||
}; | ||
return buffer | ||
} | ||
var unserialize = function (file, format) { | ||
format || (format = detectFormat(file)); | ||
format || (format = detectFormat(file)) | ||
if (!format) { | ||
throw new UnknownFormatError('no compatible format found for '+ file.path); | ||
throw new UnknownFormatError('no compatible format found for ' + file.path) | ||
} | ||
return serializers[format].unserialize(file); | ||
}; | ||
return serializers[format].unserialize(file) | ||
} | ||
//==================================================================== | ||
// =================================================================== | ||
exports.detectFormat = detectFormat; | ||
exports.serialize = serialize; | ||
exports.unserialize = unserialize; | ||
exports.detectFormat = detectFormat | ||
exports.serialize = serialize | ||
exports.unserialize = unserialize |
@@ -1,9 +0,9 @@ | ||
'use strict'; | ||
'use strict' | ||
//==================================================================== | ||
// =================================================================== | ||
var makeError = require('make-error'); | ||
var makeError = require('make-error') | ||
//==================================================================== | ||
// =================================================================== | ||
exports = module.exports = makeError('UnknownFormatError'); | ||
exports = module.exports = makeError('UnknownFormatError') |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
9755
252
13
4
1
+ Addeddebug@^2.2.0
+ Addeddebug@2.6.9(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedlodash._arraycopy@3.0.0(transitive)
+ Addedlodash._arrayeach@3.0.0(transitive)
+ Addedlodash._arraymap@3.0.0(transitive)
+ Addedlodash._basecallback@3.3.1(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._baseeach@3.0.4(transitive)
+ Addedlodash._basefind@3.0.0(transitive)
+ Addedlodash._baseflatten@3.1.4(transitive)
+ Addedlodash._basefor@3.0.3(transitive)
+ Addedlodash._baseisequal@3.0.7(transitive)
+ Addedlodash._bindcallback@3.0.1(transitive)
+ Addedlodash._createassigner@3.1.1(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.findkey@3.0.1(transitive)
+ Addedlodash.flatten@3.0.2(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.isobject@3.0.2(transitive)
+ Addedlodash.isplainobject@3.2.0(transitive)
+ Addedlodash.isstring@3.0.1(transitive)
+ Addedlodash.istypedarray@3.0.6(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.keysin@3.0.8(transitive)
+ Addedlodash.map@3.1.4(transitive)
+ Addedlodash.merge@3.3.2(transitive)
+ Addedlodash.pairs@3.0.1(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.toplainobject@3.0.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
- Removedglob@4.5.3(transitive)
- Removedlodash._arraypool@2.4.1(transitive)
- Removedlodash._basebind@2.4.1(transitive)
- Removedlodash._basecreate@2.4.1(transitive)
- Removedlodash._basecreatecallback@2.4.1(transitive)
- Removedlodash._basecreatewrapper@2.4.1(transitive)
- Removedlodash._baseflatten@2.4.1(transitive)
- Removedlodash._baseisequal@2.4.1(transitive)
- Removedlodash._basemerge@2.4.1(transitive)
- Removedlodash._createwrapper@2.4.1(transitive)
- Removedlodash._getarray@2.4.1(transitive)
- Removedlodash._isnative@2.4.1(transitive)
- Removedlodash._maxpoolsize@2.4.1(transitive)
- Removedlodash._objecttypes@2.4.1(transitive)
- Removedlodash._releasearray@2.4.1(transitive)
- Removedlodash._setbinddata@2.4.1(transitive)
- Removedlodash._shimisplainobject@2.4.1(transitive)
- Removedlodash._shimkeys@2.4.1(transitive)
- Removedlodash._slice@2.4.1(transitive)
- Removedlodash.bind@2.4.1(transitive)
- Removedlodash.createcallback@2.4.4(transitive)
- Removedlodash.findkey@2.4.1(transitive)
- Removedlodash.flatten@2.4.1(transitive)
- Removedlodash.foreach@2.4.1(transitive)
- Removedlodash.forin@2.4.1(transitive)
- Removedlodash.forown@2.4.1(transitive)
- Removedlodash.identity@2.4.1(transitive)
- Removedlodash.isarguments@2.4.1(transitive)
- Removedlodash.isarray@2.4.1(transitive)
- Removedlodash.isfunction@2.4.1(transitive)
- Removedlodash.isobject@2.4.1(transitive)
- Removedlodash.isplainobject@2.4.1(transitive)
- Removedlodash.isstring@2.4.1(transitive)
- Removedlodash.keys@2.4.1(transitive)
- Removedlodash.map@2.4.1(transitive)
- Removedlodash.merge@2.4.1(transitive)
- Removedlodash.noop@2.4.1(transitive)
- Removedlodash.property@2.4.1(transitive)
- Removedlodash.support@2.4.1(transitive)
- Removedmake-error@0.3.0(transitive)
- Removedminimatch@2.0.10(transitive)
Updatedglob@^5
Updatedlodash.findkey@^3
Updatedlodash.flatten@^3
Updatedlodash.isobject@^3
Updatedlodash.isstring@^3
Updatedlodash.keys@^3
Updatedlodash.map@^3
Updatedlodash.merge@^3
Updatedmake-error@^1