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

@nawael/checker.js

v1.4.0

Published

Some utilities to check any type of values

Downloads

79

Readme

checker.js

A set of boilerplate utilities for checking any type of values ​​without headaches or common mistakes

GitHub Actions Workflow Status codecov GitHub top language GitHub License NPM Downloads NPM Version npm bundle size

Banner

Installation

With pnpm

pnpm install @nawael/checker.js --save

With npm

npm install @nawael/checker.js --save

With yarn

yarn add @nawael/checker.js --save

Integration

For CommonJS

const { isArray, isString, isNumber, ... } = require('@nawael/checker.js')

For ESM

import { isArray, isString, isNumber, ... } from '@nawael/checker.js'

Usage examples

// instead of using typeof
if (typeof arg === 'object') {
  // ...some stuff
  // But if we do Object.keys(arg) we throw an error if arg is null! 😱
  // TypeError: Cannot convert undefined or null to object
}

// use isObject
import { isObject } from '@nawael/checker.js'

isObject(arg)
// ✅ true if arg = {}
// ❌ false if arg = null cause typeof null === 'object'
// ❌ false if arg = [] cause typeof [] === 'object'
// instead of using typeof
if (typeof arg === 'number') {
  // some stuff
}

// use isNumber
import { isNumber } from '@nawael/checker.js'

isNumber(arg)
// ✅ true if arg = 0 or arg = Infinity or -Infinity or
// ✅ true if arg = new Number() cause typeof new Number() === 'object'
// ❌ false if arg = NaN cause NaN is a number and we need to avoid NaN
// 😱 so we must check Object.prototype.toString.call(arg) === '[object Number]'

[!TIP] All APIs are available in the standalone "is" API

// instead of importing all API
import { isArray, isString, isNumber, ... } from '@nawael/checker.js'

// use "is" API and avoid boring imports
import { is } from '@nawael/checker.js'

is.array(arg) // isArray(arg)
is.string(arg) // isString(arg)
is.number(arg) // isNumber(arg)

// ...and so on

Available APIs

primitive checker

| APIs | standalone is | | -------------------- | --------------------- | | isBoolean(arg) | is.boolean(arg) | | isBooleanOrNull(arg) | is.booleanOrNull(arg) | | isBigInt(arg) | is.bigInt(arg) | | isNumber(arg) | is.number(arg) | | isNull(arg) | is.null(arg) | | isString(arg) | is.string(arg) | | isUndefined(arg) | is.undefined(arg) | | isSymbol(arg) | is.symbol(arg) | | isPrimitive(arg) | is.primitive(arg) |

String checker

| APIs | standalone is | | --------------------- | --------------------------- | | isStringOrNull(arg) | is.string.orNull(arg) | | isStringEmpty(arg) | is.string.empty(arg) | | isStringNotEmpty(arg) | is.string.notEmpty(arg) | | isAlpha(arg) | is.string.alpha(arg) | | isNumeric(arg) | is.string.numeric(arg) | | isAlphanumeric(arg) | is.string.alphanumeric(arg) | | isEmail(arg) | is.string.email(arg) | | isUrl(arg) | is.string.url(arg) | | isBinaryString(arg) | is.string.binary(arg) | | isBase64(arg) | is.string.base64(arg) |

Number checker

| APIs | standalone is | | ---------------------------------- | ------------------------------------------ | | isPositiveNumber(arg) | is.number.positive(arg) | | isNegativeNumber(arg) | is.number.negative(arg) | | isInfinite(arg) | is.number.infinite(arg) | | isOdd(arg) | is.number.odd(arg) | | isEven(arg) | is.number.even(arg) | | isNumberOrNull(arg) | is.number.orNull(arg) | | isDecimal(arg) | is.number.decimal(arg) | | isGreaterThan(arg, compare) | is.number.greaterThan(arg, compare) | | isGreaterEqualThan(arg, compare) | is.number.greaterEqualThan(arg, compare) | | isLessThan(arg, compare) | is.number.lessThan(arg, compare) | | isLessEqualThan(arg, compare) | is.number.lessEqualThan(arg, compare) | | isBetween(arg, start, finish) | is.number.between(arg, start, finish) | | isBetweenEqual(arg, start, finish) | is.number.betweenEqual(arg, start, finish) |

Object checker

| APIs | standalone is | | --------------------- | ----------------------- | | isObject(arg) | is.object(arg) | | isObjectOrNull(arg) | is.object.orNull(arg) | | isObjectNotEmpty(arg) | is.object.notEmpty(arg) | | isObjectEmpty(arg) | is.object.empty(arg) |

Array checker

| APIs | standalone is | | ---------------------- | ---------------------- | | isArray(arg) | is.array(arg) | | isMap(arg) | is.map(arg) | | isSet(arg) | is.set(arg) | | isArrayOrNull(arg) | is.array.orNull(arg) | | isArrayOfNumbers(arg) | is.array.number(arg) | | isArrayOfStrings(arg) | is.array.string(arg) | | isArrayOfObjects(arg) | is.array.object(arg) | | isArrayOfBooleans(arg) | is.array.boolean(arg) | | isArrayNotEmpty(arg) | is.array.notEmpty(arg) | | isArrayEmpty(arg) | is.array.empty(arg) |

Function checker

| APIs | standalone is | | ------------------------ | ----------------- | | isFunction(arg) | is.function(arg) | | isAsyncFunction(arg) | is.async(arg) | | isGeneratorFunction(arg) | is.generator(arg) |

Promise checker

| APIs | standalone is | | ------------------------ | -------------------------- | | isPromise(arg) | is.promise(arg) | | isFullfilledPromise(arg) | is.promise.fullfilled(arg) | | isRejectedPromise(arg) | is.promise.rejected(arg) | | isPendingPromise(arg) | is.promise.pending(arg) |

Misc checker

| APIs | standalone is | | ------------- | -------------- | | isDate(arg) | is.date(arg) | | isRegExp(arg) | is.regExp(arg) | | isError(arg) | is.error(arg) | | isFalsy(arg) | is.falsy(arg) | | isTruthy(arg) | is.truthy(arg) |

UUID checker

| APIs | standalone is | | ------------- | -------------- | | isUUID(arg) | is.uuid(arg) | | isUUIDv3(arg) | is.uuidv3(arg) | | isUUIDv4(arg) | is.uuidv4(arg) | | isUUIDv5(arg) | is.uuidv5(arg) |

Environment checker

| APIs | standalone is | | ------------- | -------------- | | isWindow() | is.window() | | isNode() | is.node() | | isBrowser() | is.browser() | | isJsDom() | is.jsDom() | | isWebWorker() | is.webWorker() | | isBun() | is.bun() | | isMac() | is.mac() | | isLinux() | is.linux() | | isWindows() | is.windows() |

Platform checker

| APIs | standalone is | | ----------------- | ------------------ | | isIpad() | is.ipad() | | isIphone() | is.iphone() | | isIpod() | is.ipod() | | isAndroid() | is.android() | | isAndroidPhone() | is.androidPhone() | | isAndroidTablet() | is.androidTablet() | | isMobile() | is.mobile() | | isTablet() | is.tablet() | | isDesktop() | is.desktop() | | isIos() | is.ios() |

Browser checker

| APIs | standalone is | | ------------- | -------------- | | isChrome() | is.chrome() | | isFirefox() | is.firefox() | | isOpera() | is.opera() | | isOperaMini() | is.operaMini() | | isSafari() | is.safari() | | isEdge() | is.edge() | | isIe() | is.ie() |

IP checker

| APIs | standalone is | | ----------- | ------------- | | isIPv4(arg) | is.ipv4(arg) | | isIPv6(arg) | is.ipv6(arg) | | isIP(arg) | is.ip(arg) |