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

@rnacanvas/value-check

v1.14.1

Published

Check if a value meets criteria

Downloads

416

Readme

Installation

With npm:

npm install @rnacanvas/value-check

Usage

All exports of this package can be accessed as named imports.

// some example imports
import { isNumber, isString } from '@rnacanvas/value-check';
import { isNullish } from '@rnacanvas/value-check';
import { isFiniteNumber, isPositiveFiniteNumber } from '@rnacanvas/value-check';
import type { NonNullObject } from '@rnacanvas/value-check';

isNumber()

Returns true if and only if a value is of type number.

isNumber(5); // true
isNumber(Infinity); // true
isNumber(NaN); // true

isNumber('5'); // false
isNumber({}); // false
isNumber(null); // false

isFiniteNumber()

Returns true if and only if a value is of type number and it is not NaN, Infinity or -Infinity.

isFiniteNumber(6); // true
isFiniteNumber(0); // true
isFiniteNumber(-3.27); // true

isFiniteNumber(NaN); // false
isFiniteNumber(Infinity); // false
isFiniteNumber(-Infinity); // false

isFiniteNumber('5'); // false
isFiniteNumber({}); // false
isFiniteNumber(null); // false

isNonFiniteNumber()

Returns true if and only if a value is NaN, Infinity or -Infinity.

isNonFiniteNumber(NaN); // true
isNonFiniteNumber(Infinity); // true
isNonFiniteNumber(-Infinity); // true

isNonFiniteNumber(6); // false
isNonFiniteNumber(0); // false
isNonFiniteNumber(-3.27); // false

isNoNFiniteNumber('5'); // false
isNoNFiniteNumber({}); // false
isNoNFiniteNumber(null); // false

isPositiveFiniteNumber()

Returns true if and only a value is of type number and is finite and positive.

isPositiveFiniteNumber(6); // true
isPositiveFiniteNumber(0); // false
isPositiveFiniteNumber(-3.27); // false

isPositiveFiniteNumber(NaN); // false
isPositiveFiniteNumber(Infinity); // false
isPositiveFiniteNumber(-Infinity); // false

isPositiveFiniteNumber('5'); // false
isPositiveFiniteNumber({}); // false
isPositiveFiniteNumber(null); // false

isNonNegativeFiniteNumber()

Returns true if and only a value is of type number and is finite and nonnegative.

isNonNegativeFiniteNumber(6); // true
isNonNegativeFiniteNumber(0); // true
isNonNegativeFiniteNumber(-3.27); // false

isNonNegativeFiniteNumber(NaN); // false
isNonNegativeFiniteNumber(Infinity); // false
isNonNegativeFiniteNumber(-Infinity); // false

isNonNegativeFiniteNumber('5'); // false
isNonNegativeFiniteNumber({}); // false
isNonNegativeFiniteNumber(null); // false

isString()

Returns true if and only if a value is of type string.

isString(''); // true
isString('string'); // true

isString(5); // false
isString({}); // false
isString(null); // false

Nullish

The Nullish type includes the values null and undefined.

type Nullish = null | undefined;

isNullish()

Returns true if and only if a value is null or undefined.

isNullish(null); // true
isNullish(undefined); // true

isNullish(1); // false
isNullish('a'); // false
isNullish({}); // false

NonNullObject

The NonNullObject type matches values of type object that are not null.

type NonNullObject = { [name: string]: unknown };

isNonNullObject()

Returns true if and only if a value is of type object and is not null.

isNonNullObject({}); // true
isNonNullObject({ 'a': 2, 'b': 3 }); // true

isNonNullObject(null); // false
isNonNullObject(5); // false
isNonNullObject('asdf'); // false

isArray()

Returns true if and only if a value is an array.

isArray([]); // true
isArray([1, '2', 'a', {}]); // true

isArray({}); // false
isArray(2); // false
isArray(null); // false

isEmptyArray()

Returns true if and only if a value is an empty array (i.e., an array with zero items in it).

isEmptyArray([]); // true
isEmptyArray([1, 'b', 3]); // false

// not an array
isEmptyArray('[]'); // false

isNonEmptyArray()

Returns true if and only if a value is a nonempty array (i.e., an array with at least one item).

isNonEmptyArray([1, 'b', 3]); // true
isNonEmptyArray(['a']); // true

isNonEmptyArray([]); // false

// not an array
isNonEmptyArray('[1, 2, 3]'); // false

isNumbersArray()

Returns true if and only if a value is an array of numbers.

Vacuously returns true for an empty array.

isNumbersArray([]); // true
isNumbersArray([2]); // true
isNumbersArray([-1, -2, -3, -4]); // true

// nonfinite numbers
isNumbersArray([NaN, Infinity, -Infinity]); // true

isNumbersArray(2); // false
isNumbersArray(['2']); // false
isNumbersArray([1, 2, 3, '4', 5]); // false

isNonEmptyNumbersArray()

Returns true if and only if a value is an array of numbers and is nonempty.

isNonEmptyNumbersArray([1]); // true
isNonEmptyNumbersArray([1, 2, 3, 4]); // true

isNonEmptyNumbersArray([]); // false

// nonfinite numbers
isNonEmptyNumbersArray([NaN, Infinity, -Infinity]); // true

// not an array of numbers
isNonEmptyNumbersArray([1, '2', 3]); // false

// not an array (is a string)
isNonEmptyNumbersArray('[1, 2, 3]'); // false

isFiniteNumbersArray()

Returns true if and only if a value is an array of finite numbers.

Vacuously returns true for an empty array.

isFiniteNumbersArray([10]); // true
isFiniteNumbersArray([-1, 5.5, 2, 101.308]); // true

isFiniteNumbersArray([]); // true

isFiniteNumbersArray([NaN, Infinity, -Infinity]); // false

isFiniteNumbersArray(10); // false
isFiniteNumbersArray([1, '2', 3]); // false

isNonFiniteNumbersArray()

Returns true if and only if a value is an array of nonfinite numbers.

Vacuously returns true for an empty array.

isNonFiniteNumbersArray([NaN, Infinity, -Infinity]); // true

isNonFiniteNumbersArray([]); // true

isNonFiniteNumbersArray([1, 2, 3, 4]); // false
isNonFiniteNumbersArray([NaN, NaN, 3, NaN]); // false

// not an array
isNonFiniteNumbersArray(Infinity); // false

isStringsArray()

Returns true if and only if a value is an array of strings.

Vacuously returns true for an empty array.

isStringsArray(['asdf']); // true
isStringsArray(['', ' ', 'A', '4']); // true

isStringsArray([]); // true

isStringsArray(['1', '2', 3, '4']); // false

// not an array
isStringsArray('asdf'); // false

isNonEmptyStringsArray()

Returns true if and only if a value is an array of strings and is nonempty.

isNonEmptyStringsArray(['asdf']); // true
isNonEmptyStringsArray(['a', 'b', 'c', 'd']); // true

isNonEmptyStringsArray([]); // false

// not an array of strings
isNonEmptyStringsArray(['a', 'b', 3, 'd']); // false

// not an array
isNonEmptyStringsArray('asdf'); // false