import { IExpiryData } from './metadata' ; export function encode ( str ) { return encodeURIComponent ( str ) ; } export function decode ( str ) { return decodeURIComponent ( str ) ; } export const COOKIE_SEP = '; ' ; export function isInPast ( date ) { return date <= new Date ( ) ; } export function isString ( str ) { return typeof str === 'string' ; } export function toString ( obj ) { return typeof obj . toUTCString === 'function' ? obj . toUTCString ( ) : obj . toString ( ) ; } export function isNil ( item ) { return item === undefined || item === null ; } export function isNumber ( item ) { return typeof item === 'number' ; } export function isExpired ( data ) { if ( ! data . config ) return false ; const { expires } = data . config ; if ( ! expires ) return false ; return isInPast ( expires instanceof Date ? expires : new Date ( expires ) ) ; } export function is ( ctor , value ) { return value && value . constructor === ctor || value instanceof ctor ; } export function convertFromJSON ( data ) { if ( typeof data !== 'string' ) { return data ; } else { try { return JSON . parse ( data ) ; } catch ( e ) { return data ; } } } export function serializeDataToString ( data ) { return typeof data === 'object' ? JSON . stringify ( data ) : data . toString ( ) ; }