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

@miyauci/isx

v1.5.0

Published

Collection of validation functions for JavaScript data

Downloads

4,013

Readme

isx

deno land GitHub release (latest by date) codecov GitHub

test NPM

Collection of validation functions for JavaScript data.

This is a very small collection of validate functions. It provides a custom type guard whenever it can.

Module structure and capability

Module can be divided into two categories.

Top-type module

Top-type module can accept any JavaScript data. In other words, it accepts the unknown type, which is top-type.

Most of them can be used to identify the type by a type guard.

The module directly under namespace is it.

Sub-type module

Sub-type modules are modules that perform type-dependent operations. It can use type-specific methods and compare values.

For example, the module under number is a sub-type module that takes a number type as an argument.

isString

badge

Whether the input is string or not.

import { isString } from "https://deno.land/x/isx@$VERSION/is_string.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isString("hello world"), true);
assertEquals(isString(1000), false);

isNumber

badge

Whether the input is number or not.

import { isNumber } from "https://deno.land/x/isx@$VERSION/is_number.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNumber(1000), true);
assertEquals(isNumber("hello world"), false);

isBigint

badge

Whether the input is bigint or not.

import { isBigint } from "https://deno.land/x/isx@$VERSION/is_bigint.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isBigint(1000n), true);
assertEquals(isBigint(undefined), false);

isNull

badge

Whether the input is null or not.

import { isNull } from "https://deno.land/x/isx@$VERSION/is_null.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNull(null), true);
assertEquals(isNull(undefined), false);

isUndefined

badge

Whether the input is undefined or not.

import { isUndefined } from "https://deno.land/x/isx@$VERSION/is_undefined.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isUndefined(undefined), true);
assertEquals(isUndefined(null), false);

isBoolean

badge

Whether the input is boolean or not.

import { isBoolean } from "https://deno.land/x/isx@$VERSION/is_boolean.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isBoolean(true), true);
assertEquals(isBoolean(null), false);

isFunction

badge

Whether the input is Function or not.

import { isFunction } from "https://deno.land/x/isx@$VERSION/is_function.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isFunction(() => {}), true);
assertEquals(isFunction({}), false);

isObject

badge

Whether the input is object or not.

import { isObject } from "https://deno.land/x/isx@$VERSION/is_object.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isObject({}), true);
assertEquals(isObject(null), false);

isSymbol

badge

Whether the input is symbol or not.

import { isSymbol } from "https://deno.land/x/isx@$VERSION/is_symbol.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isSymbol(Symbol("symbol")), true);
assertEquals(isSymbol(null), false);

isNullable

badge

Whether the input is null or undefined or not.

import { isNullable } from "https://deno.land/x/isx@$VERSION/is_nullable.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNullable(null), true);
assertEquals(isNullable(undefined), true);
assertEquals(isNullable({}), false);

isPrimitive

badge

Whether the input is Primitive or not.

import { isPrimitive } from "https://deno.land/x/isx@$VERSION/is_primitive.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isPrimitive(true), true);
assertEquals(isPrimitive(() => {}), false);
type Primitive =
  | number
  | string
  | boolean
  | bigint
  | undefined
  | null
  | symbol;

isArray

badge

Whether the input is array or not.

Use only if input contains ReadOnlyArray. It improves type inference. Otherwise, use Array.isArray.

This exists only because of TypeScript bug #17002. When this is fixed, this function will no longer be provided.

import { isArray } from "https://deno.land/x/isx@$VERSION/is_array.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isArray([]), true);
assertEquals(isArray({}), false);

isPromise

badge

Whether the input is Promise or not.

import { isPromise } from "https://deno.land/x/isx@$VERSION/is_promise.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isPromise(Promise.resolve()), true);
assertEquals(isPromise({}), false);

isDate

badge

Whether the input is Date or not.

import { isDate } from "https://deno.land/x/isx@$VERSION/is_date.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isDate(new Date()), true);
assertEquals(isDate({}), false);

isError

badge

Whether the input is Error or not.

import { isError } from "https://deno.land/x/isx@$VERSION/is_error.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isError(Error()), true);
assertEquals(isError(new SyntaxError()), true);
assertEquals(isError(new Date()), false);

isNonNullable

badge

Whether the input is NonNullable or not.

import { isNonNullable } from "https://deno.land/x/isx@$VERSION/is_non_nullable.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNonNullable(""), true);
assertEquals(isNonNullable(null), false);
assertEquals(isNonNullable(undefined), false);

isRegExp

badge

Whether the input is RegExp of not.

import { isRegExp } from "https://deno.land/x/isx@$VERSION/is_reg_exp.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isRegExp(new RegExp("")), true);
assertEquals(isRegExp({}), false);

Numeric subtypes

Validates a subtype of number or bigint.

isPositiveNumber

badge

Whether the input is positive number or not.

import { isPositiveNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_positive_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isPositiveNumber(1));
assert(isPositiveNumber(Infinity));
assertFalse(isPositiveNumber(0));

isNonPositiveNumber

badge

Whether the input is non-positive number or not. Non-positive number means less than or equal to zero.

import { isNonPositiveNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_non_positive_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNonPositiveNumber(0));
assert(isNonPositiveNumber(-1));
assertFalse(isNonPositiveNumber(1));

isNegativeNumber

badge

Whether the input is negative number or not.

import { isNegativeNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_negative_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNegativeNumber(-1));
assertFalse(isNegativeNumber(0));

isNonNegativeNumber

badge

Whether the input is non-negative number or not. Non-negative number means greater than or equal to zero.

import { isNonNegativeNumber } from "https://deno.land/x/isx@$VERSION/numeric/is_non_negative_number.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isNonNegativeNumber(0));
assert(isNonNegativeNumber(1));
assertFalse(isNonNegativeNumber(-1));

isUnitInterval

badge

Whether the input is unit interval or not. The unit interval refers to the interval between 0 and 1 on the real number line.

import { isUnitInterval } from "https://deno.land/x/isx@$VERSION/numeric/is_unit_interval.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";
assert(isUnitInterval(0));
assert(isUnitInterval(1.0));
assertFalse(isUnitInterval(-1));

Number subtypes

Validates a subtype of number. All validate functions must satisfy ⊂ number.

isOdd

badge

Whether the input is odd or not.

import { isOdd } from "https://deno.land/x/isx@$VERSION/number/is_odd.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isOdd(1), true);
assertEquals(isOdd(0), false);

isEven

badge

Whether the input is even or not.

import { isEven } from "https://deno.land/x/isx@$VERSION/number/is_even.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isEven(0), true);
assertEquals(isEven(1), false);

isPositiveInteger

badge

Whether the input is positive integer or not.

import { isPositiveInteger } from "https://deno.land/x/isx@$VERSION/number/is_positive_integer.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isPositiveInteger(1), true);
assertEquals(isPositiveInteger(0), false);

isNonNegativeInteger

badge

Whether the input is non negative integer or not.

import { isNonNegativeInteger } from "https://deno.land/x/isx@$VERSION/number/is_non_negative_integer.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isNonNegativeInteger(0), true);
assertEquals(isNonNegativeInteger(1.0), true);
assertEquals(isNonNegativeInteger(-1), false);

Object subtypes

Validates a subtype of object. All validate functions must satisfy ⊂ object.

isAsyncIterable

badge

Whether the input is AsyncIterable or not.

import { isAsyncIterable } from "https://deno.land/x/isx@$VERSION/object/is_async_iterable.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(
  isAsyncIterable({
    async *[Symbol.asyncIterator]() {
      yield "hello";
    },
  }),
  true,
);
assertEquals(isAsyncIterable({}), false);

isIterable

badge

Whether the input is Iterable or not.

import { isIterable } from "https://deno.land/x/isx@$VERSION/object/is_iterable.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isIterable(""), true);
assertEquals(isIterable({}), false);

Iterable subtypes

Validates a subtype of Iterable. All validate functions must satisfy ⊂ Iterable<unknown>.

isEmpty

badge

Wether the input is empty or not.

import { isEmpty } from "https://deno.land/x/isx@$VERSION/iterable/is_empty.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isEmpty(""));
assert(isEmpty([]));
assert(isEmpty(new Set()));

string:

If the input is a string, it has a "" type guard.

array:

If the input is a array, it has a [] type guard.

isNotEmpty

badge

Whether the input is not empty or not.

import { isNotEmpty } from "https://deno.land/x/isx@$VERSION/iterable/is_not_empty.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isNotEmpty("a"));
assert(isNotEmpty([0, 1]));

array:

If the input is a T[], it has a [T, ...T[]] type guard.

isSingle

badge

Whether the input is single element or not.

import { isSingle } from "https://deno.land/x/isx@$VERSION/iterable/is_single.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isSingle("a"));
assert(isSingle([0]));
assertFalse(isSingle([0, 1, 2]));

array:

If the input is a T[], it has a [T] type guard.

Date subtypes

Validates a subtype of Date. All validate functions must satisfy ⊂ Date.

isValidDate

badge

Whether the input is valid Date or not.

import { isValidDate } from "https://deno.land/x/isx@$VERSION/date/is_valid_date.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(isValidDate(new Date("2000/1/1")), true);
assertEquals(isValidDate(new Date("invalid")), false);

Bundle size

Bundle size is not exact. It is only a guide.

Usually, the actual bundle size is smaller than the indicated value.

Where is mod?

There is no single entry point such as mod.

This prevents the inclusion of many unnecessary modules.

License

MIT © 2021 Tomoki Miyauchi