npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

what-is-that

v1.2.10

Published

Minimal, tiny (1.1 kb) object type identifier for both Node.js and browser written in TypeScript.

Downloads

173

Readme

what-is-that Build Status Coverage Status

Minimal, tiny (1.1 kb) object type identifier for both Node.js and browser written in TypeScript.

Feature

  • Minimal: simply detect the type for any objects.
  • Fast: it's basically an if statement.
  • Tiny: only 1.1kb of gzipped.

compatible to ES3+

Install

npm install what-is-that

Usage

import {what, isObject, isObjectLike} from 'what-is-that'

// 'Boolean'
what(true)

// 'String'
what('that')

/** Detect whether it's a Plain object or any other (ex. custom class instance) */

// 'Object'
what({is: 'that'})

class MyObj {}

const obj = new MyObj()

// 'ObjectLike'
what(obj)

// false
isObject(obj)

// true
isObjectLike(obj)

API

what(o: any): Type

Returns a string representation of the type of argument or "Unknown" if it can't be identified.

The return value will be one of the list below.

  • "Undefined"
  • "Null"
  • "Number"
  • "Boolean"
  • "String"
  • "Symbol"
  • "BigInt"
  • "Object"
  • "ObjectLike"
  • "Function"
  • "GeneratorFunction"
  • "Generator"
  • "RegExp"
  • "Date"
  • "Promise"
  • "Error"
  • "TextEncoder"
  • "TextDecoder"
  • "URL"
  • "URLSearchParams"
  • "Array"
  • "Set"
  • "Map"
  • "WeakSet"
  • "WeakMap"
  • "DataView"
  • "Buffer"
  • "ArrayBuffer"
  • "SharedArrayBuffer"
  • "Int8Array"
  • "Uint8Array"
  • "Uint8ClampedArray"
  • "Int16Array"
  • "Uint16Array"
  • "Int32Array"
  • "Uint32Array"
  • "Float32Array"
  • "Float64Array"
  • "BigInt64Array"
  • "BigUint64Array"
  • "Blob"
  • "File"
  • "Unknown"

Detection

Functions which return true if the argument is a value or instance of the corresponding object type, false if not.

  • isUndefined (o: any): o is undefined
  • isNull (o: any): o is null
  • isNumber (o: any): o is number
  • isBoolean (o: any): o is boolean
  • isString (o: any): o is string
  • isSymbol (o: any): o is Symbol
  • isBigInt (o: any): o is BigInt
  • isObject (o: any): o is Record<string, any>
  • isObjectLike (o: any): o is Record<string | number | symbol, any>
  • isFunction (o: any): o is Function
  • isGeneratorFunction (o: any): o is GeneratorFunction
  • isGenerator (o: any): o is Generator
  • isRegExp (o: any): o is RegExp
  • isDate (o: any): o is Date
  • isPromise (o: any): o is Promise
  • isError (o: any): o is Error
  • isTextEncoder (o: any): o is TextEncoder
  • isTextDecoder (o: any): o is TextDecoder
  • isURL (o: any): o is URL
  • isURLSearchParams (o: any): o is URLSearchParams
  • isArray (o: any): o is Array
  • isSet (o: any): o is Set
  • isMap (o: any): o is Map<any, any>
  • isWeakSet (o: any): o is WeakSet
  • isWeakMap (o: any): o is WeakMap<any, any>
  • isDataView (o: any): o is DataView
  • isBuffer (o: any): o is Buffer
  • isArrayBuffer (o: any): o is ArrayBuffer
  • isSharedArrayBuffer (o: any): o is SharedArrayBuffer
  • isInt8Array (o: any): o is Int8Array
  • isUint8Array (o: any): o is Uint8Array
  • isUint8ClampedArray (o: any): o is Uint8ClampedArray
  • isInt16Array (o: any): o is Int16Array
  • isUint16Array (o: any): o is Uint16Array
  • isInt32Array (o: any): o is Int32Array
  • isUint32Array (o: any): o is Uint32Array
  • isFloat32Array (o: any): o is Float32Array
  • isFloat64Array (o: any): o is Float64Array
  • isBigInt64Array (o: any): o is BigInt64Array
  • isBigUint64Array (o: any): o is BigUint64Array
  • isBlob (o: any): o is Blob
  • isFile (o: any): o is File
  • isUnknown (o: any): o is unknown

For TypeScript

There are some additional functions for generic object types which would be useful to ensure that the object is explicitly typed.

  • isObjectAs <T extends Record<string, any>>(o: any): o is T
  • isObjectLikeAs <T extends Record<string | number | symbol, any>>(o:any): o is T
  • isFunctionAs <T extends (...args: any[]) => any>(o: any): o is T
  • isGeneratorAs (o: any): o is T
  • isPromiseAs <T extends Promise>(o: any): o is T
  • isArrayAs <T extends Array>(o: any): o is T
  • isSetAs <T extends Set>(o: any): o is T
  • isMapAs <T extends Map<any, any>>(o: any): o is T
  • isWeakSetAs <T extends WeakSet>(o: any): o is T
  • isWeakMapAs <T extends WeakMap<any, any>>(o: any): o is T
  • isUnknownAs (o: any): o is T