is
Small utility package that provides a set of functions to check if a given argument is of a certain type
Functions
detect
Returns the type of given value.
import { detect } from '@plq/is'
console.log(detect(''))
console.log(detect(1))
console.log(detect(true))
console.log(detect({}))
console.log(detect([]))
getTag
Returns the tag of given value.
import { getTag } from '@plq/is'
console.log(getTag(''))
console.log(getTag(1))
console.log(getTag(true))
console.log(getTag({}))
console.log(getTag([]))
isFunction
Checks if a given value is a function.
import { isFunction } from '@plq/is'
console.log(isFunction(() => {}))
console.log(isFunction({}))
console.log(isFunction(async () => {}))
isAsyncFunction
Checks if a given value is an asynchronous function.
javascript
import { isAsyncFunction } from '@plq/is'
console.log(isAsyncFunction(async () => {}))
console.log(isAsyncFunction(() => {}))
isGeneratorFunction
Checks if a given value is a generator function.
import { isGeneratorFunction } from '@plq/is'
console.log(isGeneratorFunction(function* () {}))
console.log(isGeneratorFunction(() => {}))
isPromise
Checks if a given value is a Promise.
import { isPromise } from '@plq/is'
console.log(isPromise(Promise.resolve()))
console.log(isPromise(async () => {}))
isPromiseLike
Checks if a given value is a Promise-like.
import { isPromiseLike } from '@plq/is'
console.log(isPromiseLike(Promise.resolve()))
console.log(isPromiseLike({ then: () => {} }))
console.log(isPromiseLike(async () => {}))
isArray
Checks if a given value is an array.
import { isArray } from '@plq/is'
console.log(isArray([]))
console.log(isArray({}))
isArrayOf
Checks if a given value is an array of a given type.
import { isArrayOf } from '@plq/is'
console.log(isArrayOf([], 'string'))
console.log(isArrayOf(['a', 'b', 'c'], 'string'))
console.log(isArrayOf(['a', 'b', 'c'], 'number'))
console.log(isArrayOf(['a', 'b', 3], 'string'))
isObject
Checks if a given value is an object.
import { isObject } from '@plq/is'
console.log(isObject({}))
console.log(isObject(() => {}))
isObjectLike
Checks if a given value is an object-like.
import { isObjectLike } from '@plq/is'
console.log(isObjectLike({}))
console.log(isObjectLike([]))
console.log(isObjectLike(() => {}))
isPlainObject
Checks if a given value is a plain object.
import { isPlainObject } from '@plq/is'
console.log(isPlainObject({}))
console.log(isPlainObject(Object.create(null)))
console.log(isPlainObject(() => {}))
isNull
Checks if a given value is null.
import { isNull } from '@plq/is'
console.log(isNull(null))
console.log(isNull(undefined))
isUndefined
Checks if a given value is undefined.
import { isUndefined } from '@plq/is'
console.log(isUndefined(undefined))
console.log(isUndefined(null))
isString
Checks if a given value is a string.
import { isString } from '@plq/is'
console.log(isString(''))
console.log(isString(1))
isNumber
Checks if a given value is a number.
import { isNumber } from '@plq/is'
console.log(isNumber(1))
console.log(isNumber(NaN))
console.log(isNumber(''))
isNaN
Checks if a given value is NaN.
import { isNaN } from '@plq/is'
console.log(isNaN(NaN))
console.log(isNaN(1))
isBigInt
Checks if a given value is a BigInt.
import { isBigInt } from '@plq/is'
console.log(isBigInt(BigInt(1)))
console.log(isBigInt(1))
isBoolean
Checks if a given value is a boolean.
import { isBoolean } from '@plq/is'
console.log(isBoolean(true))
console.log(isBoolean(false))
console.log(isBoolean(1))
isSymbol
Checks if a given value is a symbol.
import { isSymbol } from '@plq/is'
console.log(isSymbol(Symbol()))
console.log(isSymbol(1))
isDate
Checks if a given value is a date.
import { isDate } from '@plq/is'
console.log(isDate(new Date()))
console.log(isDate('2021-01-01'))
isRegExp
Checks if a given value is a regular expression.
import { isRegExp } from '@plq/is'
console.log(isRegExp(/test/))
console.log(isRegExp('test'))
isSet
Checks if a given value is a Set.
import { isSet } from '@plq/is'
console.log(isSet(new Set()))
console.log(isSet([]))
isMap
Checks if a given value is a Map.
import { isMap } from '@plq/is'
console.log(isMap(new Map()))
console.log(isMap([]))
isWeakSet
Checks if a given value is a WeakSet.
import { isWeakSet } from '@plq/is'
console.log(isWeakSet(new WeakSet()))
console.log(isWeakSet([]))
isWeakMap
Checks if a given value is a WeakMap.
import { isWeakMap } from '@plq/is'
console.log(isWeakMap(new WeakMap()))
console.log(isWeakMap([]))
isError
Checks if a given value is an error.
import { isError } from '@plq/is'
console.log(isError(new Error()))
console.log(isError('Error'))
isDataView
Checks if a given value is a DataView.
import { isDataView } from '@plq/is'
console.log(isDataView(new DataView(new ArrayBuffer(1))))
console.log(isDataView([]))
isIterable
Checks if a given value is iterable.
import { isIterable } from '@plq/is'
console.log(isIterable([]))
console.log(isIterable({}))
isAsyncIterable
Checks if a given value is an async iterable.
import { isAsyncIterable } from '@plq/is'
console.log(isAsyncIterable(async function* () {}))
console.log(isAsyncIterable([]))
isPrimitive
Checks if a given value is a primitive.
import { isPrimitive } from '@plq/is'
console.log(isPrimitive(''))
console.log(isPrimitive(1))
console.log(isPrimitive(true))
console.log(isPrimitive(Symbol()))
console.log(isPrimitive(null))
console.log(isPrimitive(undefined))
console.log(isPrimitive({}))
console.log(isPrimitive([]))
isEmpty
Checks if a given value is empty.
import { isEmpty } from '@plq/is'
console.log(isEmpty(''))
console.log(isEmpty(0))
console.log(isEmpty(NaN))
console.log(isEmpty([]))
console.log(isEmpty({}))
console.log(isEmpty(new Set()))
console.log(isEmpty(new Map()))
console.log(isEmpty(() => {}))
isEmptyString
Checks if a given value is an empty string.
import { isEmptyString } from '@plq/is'
console.log(isEmptyString(''))
console.log(isEmptyString(' '))
console.log(isEmptyString('test'))
isEmptyArray
Checks if a given value is an empty array.
import { isEmptyArray } from '@plq/is'
console.log(isEmptyArray([]))
console.log(isEmptyArray([1]))
isEmptyObject
Checks if a given value is an empty object.
import { isEmptyObject } from '@plq/is'
console.log(isEmptyObject({}))
console.log(isEmptyObject({ a: 1 }))
isEmptySet
Checks if a given value is an empty Set.
import { isEmptySet } from '@plq/is'
console.log(isEmptySet(new Set()))
console.log(isEmptySet(new Set([1])))
isEmptyMap
Checks if a given value is an empty Map.
import { isEmptyMap } from '@plq/is'
console.log(isEmptyMap(new Map()))
console.log(isEmptyMap(new Map([['a', 1]])))
isClass
Checks if a given value is a class.
import { isClass } from '@plq/is'
class Test {}
console.log(isClass(Test))
console.log(isClass(new Test()))
console.log(isClass(() => {}))
isArguments
Checks if a given value is an arguments object.
import { isArguments } from '@plq/is'
const args = (function() {
return arguments
})()
console.log(isArguments(args))
console.log(isArguments([]))
Development
Install dependencies
npm install
Lint
We use ESLint and @typescript-eslint/eslint-plugin to lint our code.
Check out .eslintrc.json
npm run lint
Run tests
We use Jest to test our code.
npm test
Build
We use TypeScript to build our code.
npm run build
Dev check list