import { getSuperClassInfo } from './getSuperClassInfo' ; let _uid = 0 ; const _globalTypes = { } ; export function isClass ( target ) { return ( target instanceof Function && [ 'class' , 'function' ] . includes ( target . toString ( ) . match ( /\w+/g ) [ 0 ] ) ) ; } param key param prefix export function getGlobalType ( key , prefix = '' ) { if ( ! key ) throw new Error ( 'no key.' ) ; if ( [ 'string' , 'symbol' , 'object' ] . includes ( typeof key ) ) { return key ; } if ( key . hasOwnProperty ( '__type' ) ) { return key [ '__type' ] ; } let type ; const info = key . toString ( ) . match ( /\w+/g ) ; if ( ! [ 'class' , 'function' ] . includes ( info [ 0 ] ) ) { throw new Error ( 'data MUST be a class or string.' ) ; } type = prefix + info [ 1 ] ; if ( _globalTypes [ type ] ) { type = type + '_' + _uid ++ ; } _globalTypes [ type ] = true ; Object . defineProperty ( key , '__type' , { configurable : false , enumerable : false , writable : false , value : type , } ) ; return type ; } export function isExtendOf ( classType , superClassType ) { if ( ! isClass ( classType ) || ! isClass ( superClassType ) ) { throw new Error ( 'classType and superClassType MUST be a class.' ) ; } const type = getGlobalType ( superClassType ) ; return ! ! getSuperClassInfo ( classType ) . find ( cls => cls . type === type ) ; } export function symbolString ( key ) { return typeof key === 'symbol' ? key . toString ( ) : key ; }