import { stableHash } from './hash' ; import { isFunction } from './helper' ; import { Key } from '../types' ; export const serialize = ( key ) : [ string , any [ ] , string ] => { if ( isFunction ( key ) ) { try { key = key ( ) ; } catch ( err ) { key = '' ; } } const args = [ ] . concat ( key as any ) ; key = typeof key == 'string' ? key : ( Array . isArray ( key ) ? key . length : key ) ? stableHash ( key ) : '' ; const infoKey = key ? '$swr$' + key : '' ; return [ key , args , infoKey ] ; } ;