Hyper config
Config wrapper with merging, references, string macros, tagging, etc.
var HyperConfig = ;
Api
-
HyperConfig(object):
- refLabel: string, '~' - reference label to config parts
- annotationLabel: string, '@' - annotation label, mark control config parts
- macroBegin: string, '{' - used in macro string replacement
- macroEnd: string, '}' - used in macro string replacement
-
addConfig(object): deep merge js object to config
-
build(): build config and return config session object:
- get(string): get config part by dot-separated path string or undefined if wrong path
- getByTag(string): return array with config parts, marked by tag
Overview
- ~
- link to parts of config - ~{path} - replacement macro string
- ~disable - command to delete this config object branch
- @tag - array of tag names, group by provided tag names
"section": , "section2.subsection2.name1":
//init.jsvar Config = ; Config; var config = Config; console; //{value: 'test'}console; // undefinedconsole; // exampleconsole; // test/qweqweconsole; // ~test/~{section.subsection.value}console; // {value: 123, param: 'test/qweqwe'}console; // undefinedconsole; // [{value: 123, param: 'test/qweqwe'}]
Merge configs
var HyperConfig = ; var defaultConfig = logger: transports: console: proc: 'console.log' file: fileName: 'test' ;var envConfig = {};if processenvNODE_ENV === 'development' envConfig = logger: file: fileName: 'test-dev' ; var someConfig = 'logger.transports.file.fileName': 'test-some';// expands to {logger: {transports: { file: {fileName: 'test'}}}} var config = ; ; console; // test-some in development, test in otherconsole; // undefined
References and macros
var HyperConfig = ; var defaultConfig = console: proc: 'console.log' name: '~common.name' obj: '~common.data' email: '~common.name@-name@@mail.test' common: name: 'test' data: name: 'test data' ; var config = ; ; console; // testconsole; // test dataconfigname = 'test 2 data';console; // test 2 dataconsole; // test-name@mail.test
Tagging
var HyperConfig = ; var defaultConfig = console: proc: 'console.log' '@tags': 't2' 't1' file: name: 'testfile' '@tags': 't1' some: name: 'testsome' ; var config = ; ; console; // [{proc: 'console.log'}, {name: 'testfile'}]console; // [{proc: 'console.log'}]console; // []