You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
daton/lib/src/unit/RecursiveCanonical.ts

16 lines
460 B

import {Canonical} from './Canonical.ts'
/**
* Special canonical unit which deep-resolves values recursively.
*/
export class RecursiveCanonical extends Canonical<any> {
public get(key: string, fallback?: any): any | undefined {
const parts = key.split('.')
let current_value = this._items
for ( const part of parts ) {
current_value = current_value?.[part]
}
return current_value ?? fallback
}
}