JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 219990
  • Score
    100M100P100Q158742F
  • License MIT

Tiny runtime type checking utils

Package Exports

  • @analytics/type-utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@analytics/type-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Type Utilities

A tiny tree shakable utility library for runtime type checking in 327 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

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