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

@finibit/types

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@finibit/types

Dynamic type checking utilities for JavaScript

unpublished
latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

@finibit/types

Dynamic type checking utilities for JavaScript.

Introduction

The @finibit/types package provides various functions for checking and ensuring dynamic types of JavaScript values.

Installation

Using NPM:

npm i @finibit/types

Usage

import { ensureArray, ensureFunction } from '@finibit/types'

function map (arr, fn) {
  ensureArray(arr)
  ensureFunction(fn)  
  return arr.map(fn)
}

API

isNull(v)

Checks whether v is null.

import { isNull } from '@finibit/types'

isNull(null) === true

isUndefined(v)

Checks whether v is undefined.

import { isUndefined } from '@finibit/types'

isUndefined() === true
isUndefined(undefined) === true

isBoolean(v)

Checks whether v is either true or false.

import { isBoolean } from '@finibit/types'

isBoolean(true) === true
isBoolean(false) === true

isInteger(v)

Checks whether v is an integer using Number.isSafeInteger.

import { isInteger } from '@finibit/types'

isInteger(1) === true
isInteger(0.1) === false
isInteger(NaN) === false
isInteger(Infinity) === false

isNumber(v)

Checks whether v is a number, excluding infinite values.

import { isNumber } from '@finibit/types'

isNumber(1) === true
isNumber(NaN) === false
isNumber(Infinity) === false

isString(v)

Checks whether v is a string, excluding String object.

import { isString } from '@finibit/types'

isString('') === true

isArray(v)

Checks whether v is an array using Array.isArray.

import { isArray } from '@finibit/types'

isArray([]) === true

isFunction(v)

Checks whether v is a function.

import { isFunction } from '@finibit/types'

isFunction(() => null) === true

isObject(v)

Checks whether v is a non-null object or a function.

import { isObject } from '@finibit/types'

isObject({}) === true
isObject([]) === true
isObject(() => null) === true
isObject(null) === false
isObject('') === false

isSymbol(v)

Checks whether v is a Symbol.

import { isSymbol } from '@finibit/types'

isSymbol(Symbol('test')) === true

isIterable(v)

Checks whether v is iterable, e.g. implements the iterable protocol

import { isIterable } from '@finibit/types'

isIterable('') === true
isIterable([]) === true
isIterable({}) === false

isPromise(v)

Checks whether v is promise-like, e.g. implements then method.

import { isPromise } from '@finibit/types'

isPromise(Promise.resolve()) === true
isPromise({ then: () => null }) === true

ensure*(v)

Additionally, every is* function has a ensure* counterpart, which throw TypeError exceptions if v is not a correct type.

import { ensureIterable } from '@finibit/types'

ensureIterable(null) // throws TypeError('Expected iterable but got null')

typeOf(v)

Similarly to typeof operator, returns the type of v. It handles several special cases:

import { typeOf } from '@finibit/types'

typeOf(null) === 'null'
typeOf(NaN) === 'NaN'
typeOf(Infinity) === 'infinity'

Keywords

type

FAQs

Package last updated on 16 Jul 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