@code-workers.io/ts-guards
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@code-workers.io/ts-guards

This library provides a small set of utility functions for checking the types of various data types like: object, array, number, boolean and string.

Get started

To get started simply add the library to your project by npm install @mikelgo/ts-guards and simply use the utility functions where you need it. E.g.:

import { isString } from "@mikelgo/ts-guards";

// somewhere in your code
function heavyComputation(arg: any) {
  if (isString(arg)) {
    // do something
  }
}

Important hint

The utility function isObject will not return true for null and array's. This is by design.

The default JavaScript-behavior of treating arrays and also null-values as objects, is in a lot of cases not what you usually want. To prevent this you, usually need additional checks like if (typeof something === 'object' && !Array.isArray(something)). This library will already take care of such things.

Included type guards

  • isArray
  • isObject
  • isBoolean
  • isNumber
  • isString
  • isFile

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @code-workers.io/ts-guards

      Weekly Downloads

      0

      Version

      1.0.0

      License

      none

      Unpacked Size

      11.2 kB

      Total Files

      26

      Last publish

      Collaborators

      • mikelgo