import { Key , Options } from './types' ; function description param array param value returns function getCutoff ( array , value ) { const { length } = array ; for ( let index = 0 ; index < length ; ++ index ) { if ( array [ index ] === value ) { return index + 1 ; } } return 0 ; } private description returns export function createDefaultReplacer ( ) { const cache = [ ] ; const keys = [ ] ; return function defaultReplacer ( key , value ) { const type = typeof value ; if ( type === 'function' || type === 'symbol' ) { return value . toString ( ) ; } if ( typeof value === 'object' ) { if ( cache . length ) { const thisCutoff = getCutoff ( cache , this ) ; if ( thisCutoff === 0 ) { cache [ cache . length ] = this ; } else { cache . splice ( thisCutoff ) ; keys . splice ( thisCutoff ) ; } keys [ keys . length ] = key ; const valueCutoff = getCutoff ( cache , value ) ; if ( valueCutoff !== 0 ) { return `[ref=${ keys . slice ( 0 , valueCutoff ) . join ( '.' ) || '.' }]` ; } } else { cache [ 0 ] = value ; keys [ 0 ] = key ; } return value ; } return '' + value ; } ; } private description param arg returns export function getStringifiedArgument < Type > ( arg ) { const typeOfArg = typeof arg ; return arg && ( typeOfArg === 'object' || typeOfArg === 'function' ) ? JSON . stringify ( arg , createDefaultReplacer ( ) ) : arg ; } private description param options param options . maxArgs returns export function defaultArgumentSerializer ( args ) { let key = '|' ; for ( let index = 0 ; index < args . length ; index ++ ) { key += getStringifiedArgument ( args [ index ] ) + '|' ; } return [ key ] ; } private description param options returns export function getSerializerFunction ( options ) { return typeof options . serializer === 'function' ? options . serializer : defaultArgumentSerializer ; } private description param cacheKey param key returns export function getIsSerializedKeyEqual ( cacheKey , key ) { return cacheKey [ 0 ] === key [ 0 ] ; }