Package Exports
- sb-config-file
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sb-config-file) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sb-config-file
sb-config-file is a Node.js module to help you manage your JSON configuration files without worrying about concurrency issues or double writes. It uses and therefore supports the lodash.get/lodash.set way of accessing properties
API
type Options = {
prettyPrint: boolean = true,
atomicWrites: boolean = true,
}
export default class ConfigFile {
get(dotSeparatedKey: string, defaultValue = null): Promise<any>
getSync(dotSeparatedKey: string, defaultValue = null): any
set(dotSeparatedKey: string, value, strict = false): Promise<void>
setSync(dotSeparatedKey: string, value, strict = false): void
delete(dotSeparatedKey: string, strict = false): Promise<void>
deleteSync(dotSeparatedKey: string, strict = false): void
static get(filePath: string, defaultConfig: Object, options: Options): ConfigFile
}}Example Usage
const Path = require('path')
const getConfigFile = require('sb-config-file')
getConfigFile(Path.join(__dirname, 'config.json')).then(function(configFile) {
configFile.set('database.host', 'localhost')
configFile.set('database.user', 'steelbrain')
console.log(configFile.get('database.host')) // 'localhost'
console.log(configFile.get('database.user')) // 'steelbrain'
console.log(configFile.get('database')) // { host: 'localhost', user: 'steelbrain' }
configFile.delete('database.host')
console.log(configFile.get('database')) // { user: 'steelbrain' }
configFile.set('someArray', [1, 2, 3])
configFile.set('someArray.5', 50)
console.log(configFile.get('someArray.0')) // 1
console.log(configFile.get('someArray.1')) // 2
console.log(configFile.get('someArray.2')) // 3
console.log(configFile.get('someArray.3')) // undefined
console.log(configFile.get('someArray.4')) // undefined
console.log(configFile.get('someArray.5')) // 50
})LICENSE
This package is licensed under the terms of MIT License. See the LICENSE file for more info.