'use strict' ; const _typeof = { number : 'number' , string : 'string' , undefined : 'undefined' , object : 'object' , function : 'function' } ; returns export function isArray ( array ) { if ( Array . isArray ) { return Array . isArray ( array ) ; } if ( array && typeof ( array . length ) === _typeof . number && array . constructor === Array ) { return true ; } return false ; } returns export function isString ( str ) { if ( typeof ( str ) === _typeof . string || str instanceof String ) { return true ; } return false ; } returns export function isStringArray ( value ) { return isArray ( value ) && ( < any [ ] > value ) . every ( elem => isString ( elem ) ) ; } returns export function isObject ( obj ) { return typeof obj === _typeof . object && obj !== null && ! Array . isArray ( obj ) && ! ( obj instanceof RegExp ) && ! ( obj instanceof Date ) ; } returns export function isNumber ( obj ) { if ( ( typeof ( obj ) === _typeof . number || obj instanceof Number ) && ! isNaN ( obj ) ) { return true ; } return false ; } returns export function isBoolean ( obj ) { return obj === true || obj === false ; } returns export function isUndefined ( obj ) { return typeof ( obj ) === _typeof . undefined ; } returns export function isUndefinedOrNull ( obj ) { return isUndefined ( obj ) || obj === null ; } const hasOwnProperty = Object . prototype . hasOwnProperty ; returns export function isEmptyObject ( obj ) { if ( ! isObject ( obj ) ) { return false ; } for ( let key in obj ) { if ( hasOwnProperty . call ( obj , key ) ) { return false ; } } return true ; } returns export function isFunction ( obj ) { return typeof obj === _typeof . function ; } returns export function areFunctions ( ... objects ) { return objects && objects . length > 0 && objects . every ( isFunction ) ; } export type TypeConstraint = string | Function ; export function validateConstraints ( args , constraints ) { const len = Math . min ( args . length , constraints . length ) ; for ( let i = 0 ; i < len ; i ++ ) { validateConstraint ( args [ i ] , constraints [ i ] ) ; } } export function validateConstraint ( arg , constraint ) { if ( isString ( constraint ) ) { if ( typeof arg !== constraint ) { throw new Error ( `argument does not match constraint: typeof ${ constraint }` ) ; } } else if ( isFunction ( constraint ) ) { if ( arg instanceof constraint ) { return ; } if ( arg && arg . constructor === constraint ) { return ; } if ( constraint . length === 1 && constraint . call ( undefined , arg ) === true ) { return ; } throw new Error ( 'argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true' ) ; } }