Basic runtime type checking
Install the package locally within you project folder with your package manager:
With npm
:
npm install typefence
With yarn
:
yarn add typefence
With pnpm
:
pnpm add typefence
import {
isArr,
isArray,
isBool,
isBoolean,
isDate,
isEmpty,
isErr,
isEvery,
isFunc,
isFunction,
isJSON,
isNotStr,
isNull,
isNullish,
isNum,
isObj,
isObject,
isProm,
isPromise,
isSome,
isStr,
isString,
isSym,
isUndefined,
isPrimitive,
} from "typefence";
isArr([]); // true
isArray(new Array(10)); // true
isBool(true); // true
isBoolean(false); // true
isBool(new Boolean()); // true
isDate(new Date()); // true
isEmpty([]); // true
isEmpty(""); // true
isEmpty({}); // true
isErr(new Error("Error")); // true
isJSON('{"foo": true}'); // true
isFunc(() => {}); // true
isFunction(function noop() {}); // true
isStr(""); // true
isString("true"); // true
isNotStr(false); // true
isSym(Symbol("test")); // true
isObj({}); // true
isObject({ foo: true }); // true
isProm(Promise.resolve({})); // true
isPromise(new Promise(() => {})); // true
isNull(null); // true
isUndefined(undefined); // true
isNullish(null); // true
const isEmptyObject = isEvery(isObj, isEmpty);
isEmptyObject({}); // true
isPrimitive("str"); // true
Most functions have a negated alternative for convenience:
import { isNotNullish } from "typefence";
isNotNullish({}); // true
For all configuration options, please see the API docs.
Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.