Skip to main content
Module

x/rambda/type.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { _isArray } from './_internals/_isArray'
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 (_isArray(input)){ return 'Array' } else if (typeOf === 'symbol'){ return 'Symbol' } 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'}