/**
 * Select appropriate helpers function for particular value type.
 */ export interface IterableLink { value : any ; at ( key ) : any ; } export type Iterator = ( link : any , key : string | number ) => any ; export interface Helper { map ( link , iterator ) : any [ ] ; clone ( obj ) : any ; remove ( obj , key ) : any ; } const ArrayProto = Array . prototype , ObjectProto = Object . prototype ; export function helpers ( value ) { if ( value && typeof value === 'object' ) { switch ( Object . getPrototypeOf ( value ) ) { case ArrayProto : return arrayHelpers ; case ObjectProto : return objectHelpers ; } } return dummyHelpers ; } const dummyHelpers = { clone ( value ) { return value ; } , map ( link , fun ) { return [ ] ; } , remove ( value ) { return value ; } } ; export const objectHelpers = { map ( link , iterator ) { let mapped = [ ] ; for ( let key in link . value ) { const element = iterator ( link . at ( key ) , key ) ; element === void 0 || ( mapped . push ( element ) ) ; } return mapped ; } , remove ( object , key ) { delete object [ key ] ; return object ; } , clone ( object ) { let cloned = { } ; for ( let key in object ) { cloned [ key ] = object [ key ] ; } return cloned ; } } ; export const arrayHelpers = { clone ( array ) { return array . slice ( ) ; } , remove ( array , i ) { array . splice ( i , 1 ) ; return array ; } , map ( link , iterator ) { const length = link . value . length , mapped = Array ( length ) ; for ( var i = 0 , j = 0 ; i < length ; i ++ ) { const y = iterator ( link . at ( i ) , i ) ; y === void 0 || ( mapped [ j ++ ] = y ) ; } mapped . length === j || ( mapped . length = j ) ; return mapped ; } } ;