JSPM

typefence

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q33569F
  • License MIT

Basic runtime type checking

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

package version package downloads standard-readme compliant package license make a pull request

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.

License

MIT © Tiaan du Plessis