UNPKG

rambda

Version:

Lightweight faster alternative to Ramda

31 lines (26 loc) 868 B
export function type(input){ const typeOf = typeof input if (input === null){ return 'Null' } else if (input === undefined){ return 'Undefined' } else if (typeOf === 'boolean'){ return 'Boolean' } else if (typeOf === 'number'){ return Number.isNaN(input) ? 'NaN' : 'Number' } else if (typeOf === 'string'){ return 'String' } else if (Array.isArray(input)){ return 'Array' } else if (input instanceof RegExp){ return 'RegExp' } const asStr = input && input.toString ? input.toString() : '' if ([ 'true', 'false' ].includes(asStr)) return 'Boolean' if (!Number.isNaN(Number(asStr))) return 'Number' if (asStr.startsWith('async')) return 'Async' if (asStr === '[object Promise]') return 'Promise' if (typeOf === 'function') return 'Function' if (input instanceof String) return 'String' return 'Object' }