Package detail

@miyauci/isx

TomokiMiyauci9.4kMIT1.5.0

Collection of validation functions for JavaScript data

is, validate, validation, utility

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

changelog

1.5.0 (2023-07-02)

Bug Fixes

  • is_object: check a function as object (44e56bc)

Features

  • object/is_iterable: add checking iterable subtype of object (1e5b4ca)
  • object: add strict type version of isAsyncIterable (1a5155b)

1.5.0-beta.1 (2023-07-02)

Bug Fixes

  • is_object: check a function as object (44e56bc)

Features

  • object/is_iterable: add checking iterable subtype of object (1e5b4ca)
  • object: add strict type version of isAsyncIterable (1a5155b)

1.4.0 (2023-05-31)

Features

  • number: add positive integer validation function (fa38d96)
  • number: mark as duplicated (a774643)
  • numeric: add numeric validators (51999df)

1.4.0-beta.1 (2023-05-31)

Features

  • number: add positive integer validation function (fa38d96)
  • number: mark as duplicated (a774643)
  • numeric: add numeric validators (51999df)

1.3.1 (2023-04-20)

Bug Fixes

  • number: change condition of non-negative number (a4c89e9)
  • number: change condition of non-negative number (d4b5b0c)
  • number: change the condition of positive number (bca5b23)
  • number: change the condition of positive number (e2d7ff6)

1.3.1-beta.1 (2023-04-20)

Bug Fixes

  • number: change condition of non-negative number (a4c89e9)
  • number: change condition of non-negative number (d4b5b0c)
  • number: change the condition of positive number (bca5b23)
  • number: change the condition of positive number (e2d7ff6)

1.3.0 (2023-04-13)

Features

  • is_non_nullable: add isNonNullable function (d31fdc1)
  • number: add isUnitInterval function (dabacd8)

1.3.0-beta.1 (2023-04-13)

Features

  • is_non_nullable: add isNonNullable function (d31fdc1)
  • number: add isUnitInterval function (dabacd8)

1.2.0 (2023-04-11)

Features

  • is_array: add isArray function (5f3f847)

Performance Improvements

  • iterable: stop spread operator (8c5f2f6)

1.2.0-beta.1 (2023-04-11)

Features

  • is_array: add isArray function (5f3f847)

Performance Improvements

  • iterable: stop spread operator (8c5f2f6)

1.1.1 (2023-03-27)

Bug Fixes

  • iterable: add overload before readonly array type guard (73255e1), closes #4

1.1.1-beta.1 (2023-03-27)

Bug Fixes

  • iterable: add overload before readonly array type guard (73255e1), closes #4

1.1.0 (2023-03-27)

Bug Fixes

  • iterable: add readonly signature to type guard (5231d32)

Features

  • iterable: add isEmpty function for iterable (fc1d5f1)
  • iterable: add isNotEmpty function for iterable (3d2b9db)
  • iterable: add isSingle function for iterable (1b4360c)

1.1.0-beta.1 (2023-03-27)

Bug Fixes

  • iterable: add readonly signature to type guard (5231d32)

Features

  • iterable: add isEmpty function for iterable (fc1d5f1)
  • iterable: add isNotEmpty function for iterable (3d2b9db)
  • iterable: add isSingle function for iterable (1b4360c)

1.0.0 (2023-03-26)

Bug Fixes

  • _tools: fix npm build script for generate types versions (ddb39fc)
  • do not re-export for unsupported bundler (3fd20d7)
  • export isNil function globaly (cbf5536)
  • object: fix isEmptyObject logic (7873b2c)
  • string: fix export module (c2d602e)
  • unknown: fix isIterable function that exclude not Iterator (0d2224e)

Features

  • add isDate function (39a8605)
  • add isEmptyArray function (264f3e1)
  • add isEmptyString function (3d9f9e4)
  • add isFalse function (5091300)
  • add isFunction and isPrimitive functions (4fd0bd3)
  • add isNil function (ecff67f)
  • add isNull function (c182719)
  • add isObject and isEmptyObject functions (2a52bf9)
  • add isPromise and isError functions (18ed614)
  • add isTrue function (a1e5f61)
  • be Deno first codebase, add some is functions (b5e3069)
  • date: add isValidDate function (b0d2412)
  • date: export isValidDate function (daf77bc)
  • export validation for number subset (670d336)
  • iterable: add isIterable function (c7f2450)
  • mod: export isRegExp globaly (30125c8)
  • number: add isEven function (a9d900d)
  • number: add isNegativeNumber function (fb845a8)
  • number: add isNonNegativeInteger function (92fa0c5)
  • number: add isOdd function (1090064)
  • number: add isPositiveNumber function (0ff70ea)
  • numbers: add isNonNegativeNumber function (a5b09ed)
  • numbers: add isNonPositiveNumber function (9005e4d)
  • object: add hasOwn function (3dac147)
  • object: add isSize0 function (0efb1af)
  • split all modules by file (5d042f6)
  • string: add isDateString function (86cd23a)
  • string: add isHexColor function (d5266fa)
  • string: rename isHexColor to isHexColorFormat (a2fe0d6)
  • strings: add validation for hostname format (234e8a2)
  • strings: add validation for rfc 3339 date format (ef1532a)
  • strings: add validation for RFC 3339 date time format (2b675a3)
  • strings: add validation for RFC 3339 full-time format (92b36fb)
  • strings: delete all string subset (e0946e3)
  • symbol: add isSymbol function (f24e250)
  • top_types: add isEmptyObject function (cb15082)
  • top_types: add isNonNullable function (9f8b5fd)
  • toptypes: add isRegExp function (87a3d06)
  • union: add isEmpty function (6262cd4)
  • unknown: add isAsyncGenerator function (15fc58e)
  • unknown: add isAsyncIterable function (9491020)
  • unknown: add isBigint function (6286418)
  • unknown: add isEmpty function (ce708b0)
  • unknown: add isFalsy function (68c6c28)
  • unknown: add isPlainObject function (8f6f302)
  • unknown: add isTruty function (dfc14a0)
  • unknown: remove functions with excessive narrowing (c7a8cb0)
  • unknown: rename Maybe prefix to Like suffix (c8861ca)

Performance Improvements

  • strings: add pure anotation for bundler (0a3b1d0)
  • strings: remove template literal for tree-shaking (b291ae4)

1.0.0-beta.26 (2023-03-26)

Bug Fixes

  • _tools: fix npm build script for generate types versions (ddb39fc)

1.0.0-beta.25 (2023-03-25)

Features

  • split all modules by file (5d042f6)
  • strings: delete all string subset (e0946e3)

1.0.0-beta.24 (2022-10-31)

Features

  • numbers: add isNonNegativeNumber function (a5b09ed)
  • numbers: add isNonPositiveNumber function (9005e4d)

1.0.0-beta.23 (2022-10-26)

Features

  • top_types: add isEmptyObject function (cb15082)
  • top_types: add isNonNullable function (9f8b5fd)

Performance Improvements

  • strings: add pure anotation for bundler (0a3b1d0)
  • strings: remove template literal for tree-shaking (b291ae4)

1.0.0-beta.22 (2022-09-22)

Features

  • mod: export isRegExp globaly (30125c8)
  • toptypes: add isRegExp function (87a3d06)

1.0.0-beta.21 (2022-08-31)

Features

  • date: export isValidDate function (daf77bc)
  • export validation for number subset (670d336)
  • object: add hasOwn function (3dac147)
  • string: rename isHexColor to isHexColorFormat (a2fe0d6)
  • strings: add validation for hostname format (234e8a2)
  • strings: add validation for rfc 3339 date format (ef1532a)
  • strings: add validation for RFC 3339 date time format (2b675a3)
  • strings: add validation for RFC 3339 full-time format (92b36fb)
  • unknown: remove functions with excessive narrowing (c7a8cb0)
  • unknown: rename Maybe prefix to Like suffix (c8861ca)

1.0.0-beta.20 (2022-08-25)

Features

  • number: add isNonNegativeInteger function (92fa0c5)
  • unknown: add isBigint function (6286418)
  • unknown: add isFalsy function (68c6c28)
  • unknown: add isTruty function (dfc14a0)

1.0.0-beta.19 (2022-08-03)

Bug Fixes

  • unknown: fix isIterable function that exclude not Iterator (0d2224e)

Features

  • unknown: add isAsyncGenerator function (15fc58e)
  • unknown: add isAsyncIterable function (9491020)
  • unknown: add isPlainObject function (8f6f302)

1.0.0-beta.18 (2022-08-03)

Features

  • unknown: add isEmpty function (ce708b0)

1.0.0-beta.17 (2021-11-28)

Features

  • iterable: add isIterable function (c7f2450)
  • union: add isEmpty function (6262cd4)

1.0.0-beta.16 (2021-11-26)

Bug Fixes

  • string: fix export module (c2d602e)

Features

  • string: add isDateString function (86cd23a)
  • string: add isHexColor function (d5266fa)

1.0.0-beta.15 (2021-11-21)

Bug Fixes

  • do not re-export for unsupported bundler (3fd20d7)

1.0.0-beta.14 (2021-11-21)

Bug Fixes

  • object: fix isEmptyObject logic (7873b2c)

Features

  • object: add isSize0 function (0efb1af)

1.0.0-beta.13 (2021-11-20)

Features

  • number: add isEven function (a9d900d)
  • number: add isNegativeNumber function (fb845a8)
  • number: add isOdd function (1090064)
  • number: add isPositiveNumber function (0ff70ea)

1.0.0-beta.12 (2021-11-20)

Features

  • date: add isValidDate function (b0d2412)
  • symbol: add isSymbol function (f24e250)

1.0.0-beta.11 (2021-11-20)

Features

1.0.0-beta.10 (2021-11-19)

Bug Fixes

  • export isNullable function globaly (cbf5536)

1.0.0-beta.9 (2021-11-19)

Features

  • add isNullable function (ecff67f)

1.0.0-beta.8 (2021-11-19)

Features

  • add isPromise and isError functions (18ed614)

1.0.0-beta.7 (2021-11-17)

Features

1.0.0-beta.6 (2021-11-16)

Features

  • add isFunction and isPrimitive functions (4fd0bd3)

1.0.0-beta.5 (2021-11-16)

Features

  • add isObject and isEmptyObject functions (2a52bf9)

1.0.0-beta.4 (2021-11-16)

Features