wj-config
Version:
Javascript configuration module for NodeJS and browser frameworks such as React that works like ASP.net configuration where data sources are specified (usually JSON files) and environment variables can contribute/overwrite values by following a naming con
30 lines (29 loc) • 831 B
JavaScript
import { DictionaryDataSource } from "./DictionaryDataSource.js";
function buildDictionary(key, value) {
if (!key) {
throw new Error('No valid path was provided.');
}
const dicFn = (k, v) => {
const dic = {};
dic[k] = v;
return dic;
};
if (typeof key === 'function') {
return async () => {
const [k, v] = await key();
return dicFn(k, v);
};
}
return dicFn(key, value);
}
export class SingleValueDataSource extends DictionaryDataSource {
constructor(path, value, hierarchySeparator = ':') {
super(buildDictionary(path, value), hierarchySeparator);
if (typeof path === 'string') {
this.name = `Single Value: ${path}`;
}
else {
this.name = 'Single Value';
}
}
}