ts-predicates
TypeScript icon, indicating that this package has built-in type declarations

1.0.14 • Public • Published

ts-predicates

Build Status Coverage Status npm version

Description:

A collection of predicate functions and utilities for creating new predicate functions in TypeScript. JavaScript UMD and TypeScript declaration file will be generated when building the package.

Installation:

npm install ts-predicates

Usage:

import { 
    isBoolean,
    isNotBoolean,
    isString,
    isNotString,
    isNumber,
    isNotNumber,
    isDefined,
    isUndefined,
    isNull,
    isNotNull,
    isObject,
    isNotObject,
    isPlainObject,
    isNotPlainObject,
    isArray,
    isNotArray,
    isEmptyArray,
    isNonEmptyArray,
    isFunction,
    isNotFunction,
    isTrue,
    isFalse,
    isTruthy,
    isFalsy,
    isDate,
    isNotDate,
    isRegExp,
    isNotRegExp,
    isSymbol,
    isNotSymbol,
    isEqual,
    isNotEqual
 } from 'ts-predicates';
 
// ...
 
isBoolean({})                  // false
isNotBoolean({})               // true
isString('foo')                // true
isNotString('foo')             // false
isNumber(5)                    // true
isNotNumber('foo')             // true
isDefined([])                  // true
isUndefined({})                // false
isNull(null)                   // true
isNotNull(null)                // false
isObject({})                   // true
isNotObject({})                // false
isPlainObject(new Array())     // false
isNotPlainObject(new Date())   // true
isArray([])                    // true
isNotArray([])                 // false
isEmptyArray([])               // true
isNonEmptyArray([])            // false
isFunction(() => {})           // true
isNotFunction(() => {})        // false
isTrue(1)                      // false
isFalse(false)                 // true
isTruthy(1)                    // true
isFalsy(0)                     // true
isDate(new Date())             // true
isNotDate(new Date())          // false
isRegExp(new RegExp(''))       // true
isNotRegExp(new RegExp(''))    // false
isSymbol(Symbol())             // true
isNotSymbol(Symbol())          // false
isEqual(1)(1)                  // true
isNotEqual({a: 1})({})         // true

Package Sidebar

Install

npm i ts-predicates

Weekly Downloads

2

Version

1.0.14

License

MIT

Unpacked Size

24.6 kB

Total Files

5

Last publish

Collaborators

  • codybonney