configent v2.2.0
Configent
Confident configurations
No fuzz config compilation from (ordered by ascending precedence)
- defaults
- package.json
- name.config.js
- .env
- environment
- input
/**
* package.json {"foobar": {"city": "Portsmouth"}}
* foobar.config.js {lastSeen: 'Liverpool'}
* process.env.foobar_last_seen = London
* options = { name: 'Sherlock Holmes' }
*/
const defaults = { name: 'John Doe', city: 'N/A', lastSeen: 'N/A' }
const config = configent('foobar', defaults, options)
/**
* console.log(config)
* {
* name: 'Sherlock Holmes',
* city: 'Portsmouth',
* lastSeen: 'London'
* }
* /Auto detect defaults
Configent supports multiple default configs. These are added to ./configs.
/** ./configs/routify2.config.js */
module.exports = {
supersedes: ['svelte'],
condition: ({ pkgjson }) => pkgjson.dependencies['@roxi/routify'],
config: () => ({
/** the config object used as default */
myAppName: 'Routify App'
})
}/** ./configs/svelte.config.js */
module.exports = {
condition: ({ pkgjson }) => pkgjson.dependencies['svelte'],
config: () => ({
/** the config object used as default */
myAppName: 'Svelte App'
})
}The first config with a true condition is used. To avoid conflicts, configs using the supersedes option, will run before their superseded targets.
To change the location of default configs, refer to detectDefaultsConfigPath.
API
Table of Contents
configent
Parameters
defaultsoptions default optionsinputPartial<options>? provided input (optional, default{})configentOptionsobject? configent optionsconfigentOptions.namestring name to use for configs. If left empty, name from package.json is used (optional, default'')configentOptions.cacheConfigboolean calling configent twice with same parameters will return the same instance (optional, defaulttrue)configentOptions.useDotEnvboolean include config from .env files (optional, defaulttrue)configentOptions.useEnvboolean include config from process.env (optional, defaulttrue)configentOptions.usePackageConfigboolean include config from package.json (optional, defaulttrue)configentOptions.useConfigboolean include config from name.config.js (optional, defaulttrue)configentOptions.useDetectDefaultsboolean detect defaults from context (package.json and file stucture) (optional, defaulttrue)configentOptions.detectDefaultsConfigPathstring detect defaults from context (package.json and file stucture) (optional, default'configs')configentOptions.sanitizeEnvValuefunction sanitize environment values. Convert snakecase to camelCase by default. (optional, default `str=>str.replace(/[-]a-z/g,str=>str.substr(1).toUpperCase())`)
Returns options
Vintage vector created by macrovector - www.freepik.com
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago