import * as assignDeep from "deep-extend" ; function excludeDefData < A extends { [ key ] : any ; } > ( data , def ) { const result = { } ; for ( const key in data ) { if ( data . hasOwnProperty ( key ) ) { if ( typeof data [ key ] === "object" && def [ key ] && ! Array . isArray ( def [ key ] ) ) { result [ key ] = excludeDefData ( data [ key ] , def [ key ] ) ; } else if ( data [ key ] !== def [ key ] ) { result [ key ] = data [ key ] ; } } } if ( Object . keys ( result ) . length === 0 ) { return undefined ; } return result ; } export function mergeDefData < A extends { [ key ] : any ; } > ( data , def ) { return assignDeep ( { } , def , data ) ; } export function stringifyQuery < A > ( key , args , def ) { let data = args ; if ( args && def ) { data = excludeDefData ( args , def ) ; } return data ? key + "=" + escape ( JSON . stringify ( data ) ) : "" ; } export function toUrl ( pathname , search ? , hash ? ) { let url = pathname ; if ( search ) { url += "?" + search . replace ( "?" , "" ) ; } if ( hash ) { url += "#" + hash . replace ( "#" , "" ) ; } return url ; } export function parseQuery < A extends { [ key ] : any ; } > ( key , search , defArgs ) { const str = key + "=" ; let [ , query ] = search . split ( str ) ; if ( query ) { query = query . split ( "&" ) [ 0 ] ; } if ( query ) { const args = JSON . parse ( unescape ( query ) ) ; if ( defArgs ) { return mergeDefData ( args , defArgs ) ; } else { return args ; } } else { return defArgs ; } } export function isForceRefresh ( hash ) { if ( hash . indexOf ( "refresh=true" ) > - 1 ) { return true ; } else if ( hash . indexOf ( "refresh=false" ) > - 1 ) { return false ; } else { return null ; } }