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

@langlois/is-a

v4.3.0

Published

A small JavaScript library to help with JavaScript's data typing.

Downloads

9

Readme

Javascript Type Verification Library

A small JavaScript library to help with JavaScript's data typing.

Project setup

npm i @langlois/is-a

Run your tests

npm run test

Lints and fixes files

npm run lint

Usage

import { isA } from '@langlois/is-a'

isA.array([]) // true

isA.array('[]') // false

API

Arguments

Returns true if passed a function's arguments list.

function () {
	isA.arguments(arguments) // true

	isA.arguments(arguments[0]) // false
}

Array

Returns true if passed an array.

isA.array([]) // true

Boolean

Returns true if passed a boolean.

isA.boolean(true) // true

isA.boolean(false) // true

Date

Returns true if passed a date.

const today = new Date()

isA.date(today) // true

Email

Returns true if the string passed is a valid email address.

The regex for determining if an email is valid is taken from the HTML spec.

const email = '[email protected]'

isA.email(email) // true

Error

Returns true if passed an error.

const error = new Error()

isA.error(error) // true

Function

Returns true if passed a function.

const myFunction = () => undefined

isA.function(myFunction) // true

Map

Returns true if passed a map.

const myMap = new Map()

isA.map(myMap) // true

NaN

Returns true if passed NaN.

isA.NaN(NaN) // true

Null

Returns true if passed null.

isA.null(null) // true

Number

Returns true if passed a number, excluding NaN.

isA.number(123) // true

isA.number(NaN) // false

Numerical

Returns true if passed a number or a string representing a number, excluding NaN.

isA.numerical(23) // true

isA.numerical('23') // true

isA.numerical('-23') // true

isA.numerical(NaN) // false

Object

Returns true if passed an object.

isA.object({}) // true

Everything in JavaScript is an Object and that means that many data types return typeof x === 'object' as true as well as x instanceof Object as true. However, it isn't really useful to treat certain things as if they were objects when developing so this function will return false for the following data types:

  • dates
  • errors
  • maps
  • regExps
  • sets
  • weakMaps
  • weakSets
isA.object(new Date()) // false
isA.object(new Error()) // false
isA.object(new Map()) // false
isA.object(/\d/) // false
isA.object(new Set()) // false
isA.object(new WeakMap()) // false
isA.object(new WeakSet()) // false

RegExp

Returns true if passed a regExp.

const myRegExp = /\d/

isA.regExp(myRegExp) // true

Set

Returns true if passed a set.

const mySet = new Set()

isA.set(mySet) //  true

String

Returns true if passed a string.

isA.string('hello, world') //  true

Symbol

Returns true if passed a symbol.

const mySymbol = Symbol()

isA.symbol(mySymbol) //  true

Undefined

Returns true if passed undefined.

isA.undefined(undefined) //  true

URI

Returns true if passed a URL instance or a string that can become a valid URL instance.

const myUrl = new URL('https://langlois.dev')

isA.uri(myUrl) //  true
isA.uri('https://langlois.dev') // true

WeakMap

Returns true if passed a weakMap.

const myWeakMap = new WeakMap()

isA.weakMap(myWeakMap) //  true

WeakSet

Returns true if passed a weakSet.

const myWeakSet = new WeakSet()

isA.weakSet(myWeakSet) //  true