New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@code-workers.io/ts-guards

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@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

FAQs

Package last updated on 19 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts