typefence
Basic runtime type checking
Table of Contents
Install
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
Usage
Kitchen sink
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,
} 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
const isPrimitiveType = isSome(isStr, isBool, isNum);
isPrimitiveType("str"); // true
Negation
Every function has a negated alternative for convenience:
import { isNotNullish } from "typefence";
isNotNullish({}); // true
API
For all configuration options, please see the API docs.
Contributing
Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.