Gathering detailed insights and metrics for config-chain
Gathering detailed insights and metrics for config-chain
Gathering detailed insights and metrics for config-chain
Gathering detailed insights and metrics for config-chain
npm install config-chain
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
102 Stars
75 Commits
26 Forks
6 Watching
3 Branches
11 Contributors
Updated on 29 Aug 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-0.2%
1,928,681
Compared to previous day
Last week
2.9%
10,283,892
Compared to previous week
Last month
14.4%
42,162,443
Compared to previous month
Last year
16.9%
426,502,484
Compared to previous year
2
1
A module for loading custom configurations
This module is frozen.
In general, we recommend using rc instead, but as npm depends on this, it cannot be changed.
1yarn add config-chain 2 3# npm users 4npm install --save config-chain
1const cc = require('config-chain'); 2 3console.log(cc.env('TERM_', process.env)); 4/* 5{ SESSION_ID: 'w1:5F38', 6 PROGRAM_VERSION: '3.1.2', 7 PROGRAM: 'iTerm.app' } 8*/
The .env
function gets all the keys on the provided object which are
prefixed by the specified prefix, removes the prefix, and puts the values on a new object.
1 2 // npm install config-chain 3 4 var cc = require('config-chain') 5 , opts = require('optimist').argv //ALWAYS USE OPTIMIST FOR COMMAND LINE OPTIONS. 6 , env = opts.env || process.env.YOUR_APP_ENV || 'dev' //SET YOUR ENV LIKE THIS. 7 8 // EACH ARG TO CONFIGURATOR IS LOADED INTO CONFIGURATION CHAIN 9 // EARLIER ITEMS OVERIDE LATER ITEMS 10 // PUTS COMMAND LINE OPTS FIRST, AND DEFAULTS LAST! 11 12 //strings are interpereted as filenames. 13 //will be loaded synchronously 14 15 var conf = 16 cc( 17 //OVERRIDE SETTINGS WITH COMMAND LINE OPTS 18 opts, 19 20 //ENV VARS IF PREFIXED WITH 'myApp_' 21 22 cc.env('myApp_'), //myApp_foo = 'like this' 23 24 //FILE NAMED BY ENV 25 path.join(__dirname, 'config.' + env + '.json'), 26 27 //IF `env` is PRODUCTION 28 env === 'prod' 29 ? path.join(__dirname, 'special.json') //load a special file 30 : null //NULL IS IGNORED! 31 32 //SUBDIR FOR ENV CONFIG 33 path.join(__dirname, 'config', env, 'config.json'), 34 35 //SEARCH PARENT DIRECTORIES FROM CURRENT DIR FOR FILE 36 cc.find('config.json'), 37 38 //PUT DEFAULTS LAST 39 { 40 host: 'localhost' 41 port: 8000 42 }) 43 44 var host = conf.get('host') 45 46 // or 47 48 var host = conf.store.host 49
Finally, flexible configurations! 👌
1var cc = require('config-chain') 2 3// all the stuff you did before 4var config = cc({ 5 some: 'object' 6 }, 7 cc.find('config.json'), 8 cc.env('myApp_') 9 ) 10 // CONFIGS AS A SERVICE, aka "CaaS", aka EVERY DEVOPS DREAM OMG! 11 .addUrl('http://configurator:1234/my-configs') 12 // ASYNC FTW! 13 .addFile('/path/to/file.json') 14 15 // OBJECTS ARE OK TOO, they're SYNC but they still ORDER RIGHT 16 // BECAUSE PROMISES ARE USED BUT NO, NOT *THOSE* PROMISES, JUST 17 // ACTUAL PROMISES LIKE YOU MAKE TO YOUR MOM, KEPT OUT OF LOVE 18 .add({ another: 'object' }) 19 20 // DIE A THOUSAND DEATHS IF THIS EVER HAPPENS!! 21 .on('error', function (er) { 22 // IF ONLY THERE WAS SOMETHIGN HARDER THAN THROW 23 // MY SORROW COULD BE ADEQUATELY EXPRESSED. /o\ 24 throw er 25 }) 26 27 // THROW A PARTY IN YOUR FACE WHEN ITS ALL LOADED!! 28 .on('load', function (config) { 29 console.awesome('HOLY SHIT!') 30 })
MAKE A CHAIN AND ADD ALL THE ARGS.
If the arg is a STRING, then it shall be a JSON FILENAME.
RETURN THE CHAIN!
Join the args into a JSON filename!
SYNC I/O!
SEEK the RELATIVE PATH by climbing the TREE OF DIRECTORIES.
RETURN THE FOUND PATH!
SYNC I/O!
Parse the content string, and guess the type from either the specified type or the filename.
RETURN THE RESULTING OBJECT!
NO I/O!
Get all the keys on the provided object which are prefixed by the specified prefix, removes the prefix, and puts the values on a new object.
RETURN THE RESULTING OBJECT!
NO I/O!
The ConfigChain class for CRAY CRAY JQUERY STYLE METHOD CHAINING!
One of these is returned by the main exported function, as well.
It inherits (prototypically) from ProtoList, and also inherits (parasitically) from EventEmitter
It has all the methods from both, and except where noted, they are unchanged.
A list of all the places where it got stuff. The keys are the names passed to addFile or addUrl etc, and the value is an object with some info about the data source.
Filename is the name of the file. Name is an arbitrary string to be used later if you desire. Type is either 'ini' or 'json', and will try to guess intelligently if omitted.
Loaded files can be saved later.
Same as the filename thing, but with a url.
Can't be saved later.
Add all the keys from the env object that start with the prefix.
Parse the string and add it to the set. (Mainly used internally.)
Add the object to the set.
The root from which all the other config objects in the set descend prototypically.
Put your defaults here.
Set the key to the value on the named config object. If name is unset, then set it on the first config object in the set. (That is, the one with the highest priority, which was added first.)
Get the key from the named config object explicitly, or from the resolved configs if not specified.
Write the named config object back to its origin.
Currently only supported for env and file config types.
For files, encode the data according to the type.
When one or more files are saved, emits save
event when they're all
saved.
When the config chain has loaded all the specified files and urls and such, the 'load' event fires.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/22 approved changesets -- score normalized to 2
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@best-shot/core
Create 'best-shot' config chain
proto-list
A utility for managing a prototype chain
@polkadot/apps-config
General config for various services, including settings, external links & types. This is a central source of all the configuration settings that can be tweaked. This also means that it can be customized (via PR) to support any additional chains. The inter
jest-chain-transform
Support for multiple transform scripts of jest