import {Predicate, PredicateProducer} from './type'; // ------------ @author Daniel de Oliveira ----------------- export const isNot: PredicateProducer = (f: Predicate) => (a: A) => flip(f(a)); export function isUndefinedOrEmpty(coll: Object|Array|string|undefined): boolean { if (coll === undefined) return true; if (!isObject(coll) && !isArray(coll) && !isString(coll)) throw new TypeError('arg must be string, object or array'); return coll instanceof Array ? coll.length === 0 : Object.keys(coll).length === 0; } export const isDefined: Predicate = (_: any) => _ !== undefined; export const isUndefined: Predicate = isNot(isDefined); export function isEmpty(coll: Object|Array): boolean { if (coll === undefined) throw new TypeError('arg must not be undefined'); return isUndefinedOrEmpty(coll); } export const flip = (v: boolean) => !v; export const isArray: Predicate = (as: any) => as instanceof Array; export const isObject: Predicate = (o: any) => o instanceof Object && o.constructor === Object; export const isString: Predicate = (as: any) => typeof as === 'string';