UNPKG

@hapiness/config

Version:

Configuration Library to use it inside Hapiness framework

45 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const injection_js_1 = require("injection-js"); const config_1 = require("./config"); const ConfigInjectionTokens = {}; const ConfigFileInjectionToken = new injection_js_1.InjectionToken('HAPINESS_CONFIG'); class ConfigHelper { static getInjectionToken(key) { if (!key) { return ConfigFileInjectionToken; } if (!ConfigInjectionTokens[key]) { ConfigInjectionTokens[key] = new injection_js_1.InjectionToken(`HAPINESS_CONFIG_${key}`); } return ConfigInjectionTokens[key]; } static getProvider(key, value) { const provide = ConfigHelper.getInjectionToken(key); if (key) { // key and value provided, we load the value if ((typeof value === 'object' && value !== null)) { return { provide, useValue: config_1.Config.attachProtoDeep(value) }; } else // If we dont have any value but a key we check if // the key exists in config and use it as value if (config_1.Config.has(key)) { return { provide, useValue: config_1.Config.get(key) }; } } // Otherwise just return the default config object return { provide, useValue: config_1.Config.load() }; } } exports.ConfigHelper = ConfigHelper; //# sourceMappingURL=helper.js.map