Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@analytics/type-utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@analytics/type-utils

Tiny runtime type checking utils

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
73K
decreased by-55.81%
Maintainers
1
Weekly downloads
 
Created
Source

Type Utilities

A tiny tree shakable utility library for runtime type checking.

The entire package weighs in at 657 bytes.

See live demo.

Why this package?

This package exposes re-usable runtime type checking functions. This is useful for shrinking bundle sizes.

How to install

Install @analytics/types-utils from npm.

npm install @analytics/types-utils

API

Below is the api for @analytics/types-utils.

isBrowser

Check if currently in browser context

import { isBrowser } from '@analytics/types-utils'

if (isBrowser) {
  console.log('do things in browser env')
}

isString

Check if value is string

import { isString } from '@analytics/types-utils'

const xyz = 'hi'
console.log(isString(xyz))
// true

isNumber

Check if value is number

import { isNumber } from '@analytics/types-utils'

const xyz = 123
console.log(isNumber(xyz))
// true

isBoolean

Check if value is boolean

import { isBoolean } from '@analytics/types-utils'

const myBool = true
console.log(isBoolean(myBool))
// true

isArray

Check if value is array

import { isArray } from '@analytics/types-utils'

const myArr = ['x', 'y']
console.log(isArray(myArr))
// true

isObject

Check if value is object

import { isObject } from '@analytics/types-utils'

const myObj = { cool: 'hello' }
console.log(isObject(myObj))
// true

isUndefined

Check if value is undefined

import { isUndefined } from '@analytics/types-utils'

let myval
console.log(isUndefined(myval))
// true

isRegex

Check if value is regular expression.

import { isRegex } from '@analytics/types-utils'

let myval = /pattern/gm
console.log(isRegex(myval))
// true

isNoOp

Check if value is a noOp function.

import { isNoOp } from '@analytics/types-utils'

function empty () { }
console.log(isNoOp(isNoOp))
// true

isTruthy

Check if value is truthy.

import { isTruthy } from '@analytics/types-utils'

console.log(isTruthy('')) // false
console.log(isTruthy('false')) // false
console.log(isTruthy('FALSE')) // false
console.log(isTruthy(0)) // false
console.log(isTruthy(null)) // false
console.log(isTruthy(undefined)) // false
console.log(isTruthy('true')) // true
console.log(isTruthy(1)) // true
console.log(isTruthy({})) // true
console.log(isTruthy([])) // true
console.log(isTruthy(function() { })) // true

isElement

Check if value is a a DOM node.

import { isElement } from '@analytics/types-utils'

const formElement = document.querySelector('.my-form')
console.log(isElement(formElement))
// true

isNodeList

Check if value is a list of DOM nodes.

import { isNodeList } from '@analytics/types-utils'

const buttons = document.querySelectorAll('button')
console.log(isNodeList(buttons))
// true

isForm

Check if value is a noOp function.

import { isForm } from '@analytics/types-utils'

const formElement = document.querySelector('.my-form')
console.log(isForm(formElement))
// true

Keywords

FAQs

Package last updated on 17 Oct 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc