Package Exports
- typefence
- typefence/dist/index.js
- typefence/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typefence) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 typefenceWith yarn:
yarn add typefenceWith pnpm:
pnpm add typefenceUsage
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"); // trueNegation
Every function has a negated alternative for convenience:
import { isNotNullish } from "typefence";
isNotNullish({}); // trueAPI
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.