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

@elucidata/type

v3.0.0

Published

Enhanced typeof function

Downloads

74

Readme

type

An enhanced typeof function. Reliably returns object types, and element types for modern browsers.

import { type } from "@elucidata/type"

type(null)
// => "null"
type(window.undefinedProperty)
// => "undefined"
type("test")
// => "string"
type(new String())
// => "string"
type(1)
// => "number"
type(new Number())
// => "number"
type(true)
// => "boolean"
type(new Boolean())
// => "boolean"
type(/test/)
// => "regexp"
type(new RegExp())
// => "regexp"
type(new Date())
// => "date"
type(["test"])
// => "array"
type(new Array())
// => "array"
type({ test: "test" })
// => "object"
type(new Object())
// => "object"
type(document)
// => "document"
type(document.querySelectorAll("*"))
// => "nodelist"
type(document.body)
// => "bodyelement"
type(document.createElement("div"))
// => "divelement"
type(Symbol("test"))
// => "symbol"

Includes helper methods for each type that work as type guards if used in TypeScript:

import * as type from "@elucidata/type"

type.isObject(target)
type.isNotObject(target)

type.isBoolean(target)
type.isNotBoolean(target)

type.isNumber(target)
type.isNotNumber(target)

type.isString(target)
type.isNotString(target)

type.isFunction(target)
type.isNotFunction(target)

type.isArray(target)
type.isNotArray(target)

type.isDate(target)
type.isNotDate(target)

type.isRegExp(target)
type.isNotRegExp(target)

type.isUndefined(target)
type.isNotUndefined(target)

type.isNull(target)
type.isNotNull(target)

type.isNodeList(target)
type.isNotNodeList(target)

type.isSymbol(target)
type.isNotSymbol(target)

type.isElement(target)
type.isNotElement(target)

// is[Not]Element() deals with HTMLElements

type.isElement(document.body) // => true
type.isElement({}) // => false

Installation

Pick your poison:

npm install @elucidata/type
bower install @elucidata/type

Definitions

export declare const getType: (target: any) => string
export declare const of: (target: any) => string
export declare const type: (target: any) => string

export declare const isBoolean: (target: any) => target is boolean
export declare const isNotBoolean: (target: any) => target is unknown
export declare const isNumber: (target: any) => target is number
export declare const isNotNumber: (target: any) => target is unknown
export declare const isString: (target: any) => target is string
export declare const isNotString: (target: any) => target is unknown
export declare const isFunction: (target: any) => target is Function
export declare const isNotFunction: (target: any) => target is unknown
export declare const isArray: (target: any) => target is any[]
export declare const isNotArray: (target: any) => target is unknown
export declare const isDate: (target: any) => target is Date
export declare const isNotDate: (target: any) => target is unknown
export declare const isRegExp: (target: any) => target is RegExp
export declare const isNotRegExp: (target: any) => target is unknown
export declare const isUndefined: (target: any) => target is undefined
export declare const isNotUndefined: (target: any) => target is unknown
export declare const isNull: (target: any) => target is null
export declare const isNotNull: (target: any) => target is unknown
export declare const isNodeList: (target: any) => target is NodeList
export declare const isNotNodeList: (target: any) => target is unknown
export declare const isObject: (target: any) => target is Object
export declare const isNotObject: (target: any) => target is unknown
export declare const isSymbol: (target: any) => target is Symbol
export declare const isNotSymbol: (target: any) => target is unknown
export declare const isEmpty: (target: any) => boolean
export declare const isNotEmpty: (target: any) => boolean
export declare const isElement: (target: any) => target is HTMLElement
export declare const isNotElement: (target: any) => target is unknown