import {Canonical} from './Canonical' /** * Variant of the Canonical unit whose accessor allows accessing nested * properties on the resolved objects. * * @example * The Config unit is a CanonicalRecursive unit. So, once a config file is * resolved, a particular value in the config file can be retrieved as well: * * ```typescript * // app/config/my/config.config.ts * { * foo: { * bar: 123 * } * } * ``` * * This can be accessed as: * ```typescript * config.get('my:config.foo.bar') // => 123 * ``` */ export class CanonicalRecursive extends Canonical { public get(key: string, fallback?: unknown): any | undefined { const parts = key.split('.') let currentValue = this.loadedItems for ( const part of parts ) { currentValue = currentValue?.[part] } return currentValue ?? fallback } }