import { Options } from "@govtechsg/jsonld" ; interface Options < T > { iteratee : ( data : { value : any ; path : string ; } ) => T ; path ? : string ; } export function traverseAndFlatten < T > ( data , options ) ; export function traverseAndFlatten < T > ( data , options ) ; export function traverseAndFlatten < T > ( data , options ) ; export function traverseAndFlatten < T > ( data , { iteratee , path = "" } ) { if ( Array . isArray ( data ) ) { return data . flatMap ( ( v , index ) => traverseAndFlatten ( v , { iteratee , path : `${ path }[${ index }]` } ) ) ; } if ( typeof data === "object" && data ) { return Object . keys ( data ) . flatMap ( ( key ) => traverseAndFlatten ( data [ key ] , { iteratee , path : path ? `${ path }.${ key }` : key } ) ) ; } if ( typeof data === "string" || typeof data === "number" || typeof data === "boolean" || data === null ) { return iteratee ( { value : data , path } ) ; } throw new Error ( `Unexpected data '${ data }' in '${ path }'` ) ; }