UNPKG

i-do-config

Version:

Provide app configuration as key-value pairs from multiple providers. Inspired by ASP.net Core

40 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("./helpers"); class ConfigurationProviderAbstract { constructor(options) { this.options = options; // eslint-disable-next-line @typescript-eslint/no-explicit-any this.values = {}; } get name() { return this.options && this.options.name || this.constructor.name; } /** * Get multiple values as key/value pairs * * @param key */ getSection(key) { key = this.sanitizeKey(key); const section = {}; for (const k in this.values) { // Make sure we retrieve a section and not a value if (k.indexOf(`${key}:`) === 0) { // Remove the prefixed key from the returned object const r = new RegExp(`${key}:`); const cleanedKey = k.replace(r, ""); if (cleanedKey.indexOf(":") === -1) { // Only add immediate values (discard nested values) section[cleanedKey] = this.values[k]; } } } return section; } sanitizeKey(key) { return helpers_1.Helpers.sanitizeConfigKey(key); } } exports.ConfigurationProviderAbstract = ConfigurationProviderAbstract; //# sourceMappingURL=abstract-provider.js.map