/* eslint-disable no-param-reassign */ import { App } from './types'; const isBaseType = ['string', 'number', 'undefined', 'boolean', 'symbol', 'function'].reduce( (result: App.Dict, type: string) => { result[type] = (obj: any) => typeof obj === type; return result; }, {}, ); export const isString = isBaseType.string; export const isNumber = isBaseType.number; export const isUndefined = isBaseType.undefined; export const isBoolean = isBaseType.boolean; export const isSymbol = isBaseType.symbol; export const isFunction = isBaseType.function; export const isObject = (obj: any) => Object.prototype.toString.call(obj) === '[object Object]'; export const isArray = (obj: any) => Array.isArray(obj); export const isNull = (obj: any) => obj === null; export const hasChildren = (child: any) => ( Array.isArray(child) && child.length > 0) || (!isNull(child) && !isUndefined(child)); export const isRegExp = (obj: any) => Object.prototype.toString.call(obj) === '[object RegExp]'; export const isEmpty = (obj: string) => isNull(obj) || isUndefined(obj) || obj === ''; export const isExactEmpty = (target: string | any[] | null | undefined) => { if (target === undefined || target === null // eslint-disable-next-line no-self-compare || target !== target || /^\s*$/.test(target as string) || target === 'undefined' || target === 'null' || (Array.isArray(target) && target.length === 0) || (isObject(target) && Object.keys(target).length === 0) ) { return true; } return false; }; const isType = { ...isBaseType, isObject, isArray, isNull, hasChildren, isRegExp, }; export default isType;