export * from './symbols' ; /** Give `any` its own class */ export abstract class Any { protected _ : any ; } /** Resolve object intersections */ export type Id < T > = { [ P in keyof T ] : T [ P ] ; } ; /** Any property name */ export type AnyProp = keyof any ; /** Any array type */ export type AnyArray = ReadonlyArray < any > ; /** Used in place of `object` when necessary */ export type Dictionary < T > = { [ key ] : T | undefined ; [ index ] : T | undefined ; } ; /** Add `dispose` method to type T */ export type Disposable < T extends object = any > = Id < T & IDisposable > ; /** Object with `dispose` method */ export interface IDisposable { dispose : ( ) => void ; } /** `Object#hasOwnProperty` bound to `Function#call` */ export const has = Function . call . bind ( Object . hasOwnProperty ) as ( obj : object , prop : AnyProp ) => boolean ; /** Create a function that reuses a property descriptor */ export const createDescriptor = ( desc ) => { const attr = has ( desc , 'get' ) ? 'get' : 'value' ; return ( obj , prop , value ) => { desc [ attr ] = value ; Object . defineProperty ( obj , prop , desc ) ; desc [ attr ] = undefined ; return obj ; } ; } ; /** For defining a non-enumerable property */ export const definePrivate = createDescriptor ( { value : undefined } ) ; /** Function that ignores its arguments and always returns nothing */ export const noop = Function . prototype as ( ... args : any [ ] ) => void ; export const getProto = Object . getPrototypeOf ; export const isArray = Array . isArray ; export function isFunction ( value ) { return typeof value === 'function' ; } export function isObject ( value ) { return value && typeof value === 'object' ; } export function isPlainObject ( value ) { if ( value ) { const proto = getProto ( value ) ; return proto === null || proto === Object . prototype ; } return false ; } export interface IThenable < T = any > { then ( onFulfill , onReject ? ) : IThenable < T > ; } export function isThenable ( value ) { return typeof value [ 'then' ] == 'function' ; } export function shallowCopy < T extends object > ( obj ) { if ( isArray ( obj ) ) { return obj . slice ( ) as any ; } else { let copy = Object . create ( getProto ( obj ) ) ; each ( obj , prop => copyProp ( obj , prop , copy ) ) ; return copy ; } } export function copyProp ( src , prop , dest ) { let desc = Object . getOwnPropertyDescriptor ( src , prop ) ! ; if ( desc . get ) { throw Error ( 'Getters are only allowed on prototypes' ) ; } if ( desc . enumerable ) { dest [ prop ] = desc . value ; } else { Object . defineProperty ( dest , prop , { value : desc . value , writable : true , configurable : true , } ) ; } return desc ; } /** Iterate over the keys of an object */ export function each ( obj , iter ) { if ( isArray ( obj ) ) { for ( let i = 0 ; i < obj . length ; i ++ ) iter ( i ) ; } else if ( typeof Reflect !== 'undefined' ) { Reflect . ownKeys ( obj ) . forEach ( iter ) ; } else { Object . getOwnPropertyNames ( obj ) . forEach ( iter ) ; Object . getOwnPropertySymbols ( obj ) . forEach ( iter ) ; } }