import { Serializable } from './api' ; const isSerializable = ( value ) : value is Serializable < any > => value && value . serialize instanceof Function ; const isPrimitive = ( value ) => value === null || typeof value !== 'object' ; /**
 * An agnostic serializer for design token components, producing a stable and noncircular
 * representation of the data held in components.
 */ export const serialize = < T > ( value ) : any => { if ( isSerializable ( value ) ) { return serialize ( value . serialize ( ) ) ; } if ( isPrimitive ( value ) ) { return value ; } if ( Array . isArray ( value ) ) { return value . map ( serialize ) ; } const serialized = { } ; for ( const key in value ) { serialized [ key ] = serialize ( value [ key ] ) ; } return serialized ; } ;