import { parse } from 'pathington' ; const O = Object ; const { create , getOwnPropertySymbols , getPrototypeOf , keys , propertyIsEnumerable } = O ; const { isArray } = Array ; type ToString = ( value : any ) => string ; const toStringFunction = Function . prototype . bind . call ( Function . prototype . call , Function . prototype . toString ) ; const toStringObject = Function . prototype . bind . call ( Function . prototype . call , O . prototype . toString ) ; constant const HAS_SYMBOL_SUPPORT = typeof Symbol === 'function' && typeof Symbol . for === 'function' ; constant const REACT_ELEMENT = HAS_SYMBOL_SUPPORT ? Symbol . for ( 'react.element' ) : 0xeac7 ; function description param array returns export const cloneArray = ( array ) : any [ ] => { const Constructor = array . constructor as ArrayConstructor ; const cloned = Constructor === Array ? [ ] : new Constructor ( ) ; for ( let index = 0 , length = array . length ; index < length ; index ++ ) { cloned [ index ] = array [ index ] ; } return cloned ; } ; function description param array param fn param initialValue returns export const reduce = ( array , fn , initialValue ) : any => { let value = initialValue ; for ( let index = 0 , length = array . length ; index < length ; index ++ ) { value = fn ( value , array [ index ] ) ; } return value ; } ; function description param object returns export const getOwnProperties = ( object ) : ( string | symbol ) [ ] => { if ( ! HAS_SYMBOL_SUPPORT ) { return keys ( object ) ; } const ownSymbols = getOwnPropertySymbols ( object ) ; if ( ! ownSymbols . length ) { return keys ( object ) ; } return keys ( object ) . concat ( reduce ( ownSymbols , ( enumerableSymbols , symbol ) : symbol [ ] => { if ( propertyIsEnumerable . call ( object , symbol ) ) { enumerableSymbols . push ( symbol ) ; } return enumerableSymbols ; } , [ ] ) ) ; } ; function description param target param source returns export const assignFallback = ( target , source ) : unchanged . Unchangeable => { if ( ! source ) { return target ; } return reduce ( getOwnProperties ( source ) , ( clonedObject , property ) => { clonedObject [ property ] = source [ property ] ; return clonedObject ; } , Object ( target ) ) ; } ; const assign = typeof O . assign === 'function' ? O . assign : assignFallback ; function description param object returns export const createWithProto = ( object ) : unchanged . Unchangeable => create ( object . __proto__ || getPrototypeOf ( object ) ) ; function description param object returns export const isCloneable = ( object ) => { if ( ! object || typeof object !== 'object' || object . $$typeof === REACT_ELEMENT ) { return false ; } const type = toStringObject ( object ) ; return type !== '[object Date]' && type !== '[object RegExp]' ; } ; function description param path returns export const isEmptyPath = ( path ) => path == null || ( isArray ( path ) && ! path . length ) ; function description param fn returns export const isGlobalConstructor = ( fn ) => typeof fn === 'function' && ! ! ~ toStringFunction ( fn ) . indexOf ( '[native code]' ) ; function description param object param context param parameters returns export const callIfFunction = ( object , context , parameters ) => typeof object === 'function' ? object . apply ( context , parameters ) : void 0 ; function description param key returns export const getNewEmptyChild = ( key ) : unchanged . Unchangeable => typeof key === 'number' ? [ ] : { } ; function description param object returns export const getNewEmptyObject = ( object ) : unchanged . Unchangeable => isArray ( object ) ? [ ] : { } ; function description param object returns export const getShallowClone = ( object ) : unchanged . Unchangeable => { if ( object . constructor === O ) { return assign ( { } , object ) ; } if ( isArray ( object ) ) { return cloneArray ( object ) ; } return isGlobalConstructor ( object . constructor ) ? { } : assign ( createWithProto ( object ) , object ) ; } ; function description param value1 param value2 returns export const isSameValueZero = ( value1 , value2 ) => value1 === value2 || ( value1 !== value1 && value2 !== value2 ) ; function description param object returns export const cloneIfPossible = ( object ) => isCloneable ( object ) ? getShallowClone ( object ) : object ; function description param object param nextKey returns export const getCloneOrEmptyObject = ( object , nextKey ) : unchanged . Unchangeable => isCloneable ( object ) ? getShallowClone ( object ) : getNewEmptyChild ( nextKey ) ; function description param value param fallbackValue returns export const getCoalescedValue = ( value , fallbackValue ) => value === void 0 ? fallbackValue : value ; function description param path returns export const getParsedPath = ( path ) : unchanged . ParsedPath => isArray ( path ) ? path : parse ( path ) ; function description param path param object param onMatch param index returns export const getCloneAtPath = ( path , object , onMatch , index ) => { const key = path [ index ] ; const nextIndex = index + 1 ; if ( nextIndex === path . length ) { onMatch ( object , key ) ; } else { object [ key ] = getCloneAtPath ( path , getCloneOrEmptyObject ( object [ key ] , path [ nextIndex ] ) , onMatch , nextIndex ) ; } return object ; } ; function description param path param object param onMatch returns export const getDeepClone = ( path , object , onMatch ) : unchanged . Unchangeable => { const parsedPath = getParsedPath ( path ) ; const topLevelClone = getCloneOrEmptyObject ( object , parsedPath [ 0 ] ) ; if ( parsedPath . length === 1 ) { onMatch ( topLevelClone , parsedPath [ 0 ] ) ; return topLevelClone ; } return getCloneAtPath ( parsedPath , topLevelClone , onMatch , 0 ) ; } ; function description param target param source param isDeep returns export const getMergedObject = ( target , source , isDeep ) : unchanged . Unchangeable => { const isObject1Array = isArray ( target ) ; if ( isObject1Array !== isArray ( source ) || ! isCloneable ( target ) ) { return cloneIfPossible ( source ) ; } if ( isObject1Array ) { return target . concat ( source ) ; } const targetClone = target . constructor === O || isGlobalConstructor ( target . constructor ) ? { } : createWithProto ( target ) ; return reduce ( getOwnProperties ( source ) , ( clone , key ) : unchanged . Unchangeable => { clone [ key ] = isDeep && isCloneable ( source [ key ] ) ? getMergedObject ( target [ key ] , source [ key ] , isDeep ) : source [ key ] ; return clone ; } , assign ( targetClone , target ) ) ; } ; function description param path param object param noMatchValue returns export const getValueAtPath = ( path , object , noMatchValue ? ) => { const parsedPath = getParsedPath ( path ) ; if ( parsedPath . length === 1 ) { return object ? getCoalescedValue ( object [ parsedPath [ 0 ] ] , noMatchValue ) : noMatchValue ; } let ref = object ; let key = parsedPath [ 0 ] ; for ( let index = 0 ; index < parsedPath . length - 1 ; index ++ ) { if ( ! ref || ! ref [ key ] ) { return noMatchValue ; } ref = ref [ key ] ; key = parsedPath [ index + 1 ] ; } return ref ? getCoalescedValue ( ref [ key ] , noMatchValue ) : noMatchValue ; } ; function description param path param object param fn returns export const getFullPath = ( path , object , fn ? ) : unchanged . Path => { const isPathEmpty = isEmptyPath ( path ) ; const valueAtPath = isPathEmpty ? object : fn ? fn ( getValueAtPath ( path , object ) ) : getValueAtPath ( path , object ) ; return isArray ( valueAtPath ) ? isArray ( path ) ? path . concat ( [ valueAtPath . length ] ) : `${ isPathEmpty ? '' : path }[${ valueAtPath . length }]` : path ; } ; function description param array param splicedIndex export const splice = ( array , splicedIndex ) : void => { if ( array . length ) { const cutoff = array . length - 1 ; let index = splicedIndex ; while ( index < cutoff ) { array [ index ] = array [ index + 1 ] ; ++ index ; } array . length = cutoff ; } } ; function description throws export const throwInvalidFnError = ( ) : never => { throw new TypeError ( 'handler passed is not of type "function".' ) ; } ;