Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

app-conf

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-conf - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

76

entries.js

@@ -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)
}
},
];
}
]

@@ -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')
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc