UNPKG

confinode

Version:

Node application configuration reader

45 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const InternalResult_1 = require("./InternalResult"); /** * Create a proxy handler to return the appropriate result property instead of the result itself. * * @param resultProperty - The name of the property. * @returns The correct handler. */ function handle(resultProperty) { return { get: (target, property) => { const result = target[property]; return result instanceof InternalResult_1.default ? result[resultProperty] : result; }, set: () => { throw new TypeError('Configuration result is immutable'); }, deleteProperty: () => { throw new TypeError('Configuration result is immutable'); }, defineProperty: () => { throw new TypeError('Configuration result is immutable'); }, }; } /** * A result based on children elements. */ class ParentResult extends InternalResult_1.default { /** * Create the result. Children may either be in an array or in an object literal. * * @param children - The children containing the result elements. */ constructor(children) { super(); this.children = children; this.configuration = new Proxy(children, handle('configuration')); this.fileName = new Proxy(children, handle('fileName')); Object.freeze(this); } } exports.default = ParentResult; //# sourceMappingURL=ParentResult.js.map