izuna/src/type.js
2025-04-09 14:51:50 -05:00

28 lines
537 B
JavaScript

import { curry } from './curry.js'
/**
* @typedef {'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function'} TypeOfValue
*/
/**
* @template T
* @param {T} x
* @returns {TypeOfValue}
*/
export const type = x => typeof x
export const is = curry(
/**
* @template T
* @param {FunctionConstructor} ctr
* @param {T} x
*/
(ctr, x) => x.constructor === ctr)
/**
* @template T
* @param {T} x
*/
export const isFn = x => type(x) === 'function'
export const isArray = Array.isArray