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/assertion

v1.0.0

Published

Assertion collection for JavaScript data

Downloads

4

Readme

assertion

deno land GitHub release (latest by date) codecov GitHub

test NPM

Assertion collection for JavaScript data.

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.

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.

Common

All function signatures have an asserts specifier.

All modules throw an error if the assert fails. And the errors are fully customizable.

Error message

No opinion on error message. Nothing by default.

You can give message.

import { assertNumber } from "https://deno.land/x/assertion@$VERSION/assert_number.ts";

declare const input: unknown;

assertNumber(input, `must be number`);

Error constructor

No opinion on error constructor.

By default, use Error constructor.

To throw RangeError instead, do the following.

import { assertNonNegativeInteger } from "https://deno.land/x/assertion@$VERSION/number/assert_non_negative_integer.ts";

declare const input: number;

assertNonNegativeInteger(input, `must be non-negative integer`, RangeError);

assertArray

badge

Assert the input is array.

import { assertArray } from "https://deno.land/x/assertion@$VERSION/assert_array.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertArray([]));
assertThrows(() => assertArray({}));

assertAsyncIterable

badge

Assert the input is AsyncIterable.

import { assertAsyncIterable } from "https://deno.land/x/assertion@$VERSION/assert_async_iterable.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(
  assertAsyncIterable({
    async *[Symbol.asyncIterator]() {
      yield "hello";
    },
  }),
);
assertThrows(() => assertAsyncIterable(() => {}));

assertBigint

badge

Assert the input is bigint.

import { assertBigint } from "https://deno.land/x/assertion@$VERSION/assert_bigint.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertBigint(1000n));
assertThrows(() => assertBigint(undefined));

assertBoolean

badge

Assert the input is boolean.

import { assertBoolean } from "https://deno.land/x/assertion@$VERSION/assert_boolean.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertBoolean(true));
assertThrows(() => assertBoolean(null));

assertDate

badge

Assert the input is Date.

import { assertDate } from "https://deno.land/x/assertion@$VERSION/assert_date.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertDate(new Date()));
assertThrows(() => assertDate({}));

assertError

badge

Assert the input is Error.

import { assertError } from "https://deno.land/x/assertion@$VERSION/assert_error.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertError(Error()));
assertFalse(assertError(new SyntaxError()));
assertThrows(() => assertError(new Date()));

assertFunction

badge

Assert the input is Function.

import { assertFunction } from "https://deno.land/x/assertion@$VERSION/assert_function.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertFunction(() => {}));
assertThrows(() => assertFunction({}));

assertIterable

badge

Assert the input is Iterable.

import { assertIterable } from "https://deno.land/x/assertion@$VERSION/assert_iterable.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertIterable(""));
assertThrows(() => assertIterable({}));

assertNonNullable

badge

Assert the input is not null or undefined.

import { assertNonNullable } from "https://deno.land/x/assertion@$VERSION/assert_non_nullable.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNonNullable(""));
assertThrows(() => assertNonNullable(null));
assertThrows(() => assertNonNullable(undefined));

assertNull

badge

Assert the input is null.

import { assertNull } from "https://deno.land/x/assertion@$VERSION/assert_null.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNull(null));
assertThrows(() => assertNull(undefined));

assertNullable

badge

Assert the input is null or undefined.

import { assertNullable } from "https://deno.land/x/assertion@$VERSION/assert_nullable.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNullable(null));
assertFalse(assertNullable(undefined));
assertThrows(() => assertNullable({}));

assertNumber

badge

Assert the input is number.

import { assertNumber } from "https://deno.land/x/assertion@$VERSION/assert_number.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNumber(1000));
assertThrows(() => assertNumber("hello world"));

assertObject

badge

Assert the input is object.

import { assertObject } from "https://deno.land/x/assertion@$VERSION/assert_object.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertObject({}));
assertThrows(() => assertObject(null));

assertPrimitive

badge

Assert the input is Primitive.

import { assertPrimitive } from "https://deno.land/x/assertion@$VERSION/assert_primitive.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertPrimitive(true));
assertThrows(() => assertPrimitive({}));
type Primitive =
  | number
  | string
  | boolean
  | bigint
  | undefined
  | null
  | symbol;

assertPromise

badge

Assert the input is Promise.

import { assertPromise } from "https://deno.land/x/assertion@$VERSION/assert_promise.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertPromise(Promise.resolve()));
assertThrows(() => assertPromise({}));

assertRegExp

badge

Assert the input is RegExp.

import { assertRegExp } from "https://deno.land/x/assertion@$VERSION/assert_reg_exp.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertRegExp(new RegExp("")));
assertThrows(() => assertRegExp({}));

assertString

badge

Assert the input is string.

import { assertString } from "https://deno.land/x/assertion@$VERSION/assert_string.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertString("hello world"));
assertThrows(() => assertString(1000));

assertSymbol

badge

Assert the input is symbol.

import { assertSymbol } from "https://deno.land/x/assertion@$VERSION/assert_symbol.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertSymbol(Symbol("symbol")));
assertThrows(() => assertSymbol(null));

assertUndefined

badge

Assert the input is undefined.

import { assertUndefined } from "https://deno.land/x/assertion@$VERSION/assert_undefined.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertUndefined(undefined));
assertThrows(() => assertUndefined(null));

Number subtypes

Assert a subtype of number. All assertion functions must satisfy ⊂ number.

assertEven

badge

Assert the input is even.

import { assertEven } from "https://deno.land/x/assertion@$VERSION/number/assert_even.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertEven(0));
assertThrows(() => assertEven(1));

assertNegativeNumber

badge

Assert the input is negative number.

import { assertNegativeNumber } from "https://deno.land/x/assertion@$VERSION/number/assert_negative_number.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNegativeNumber(-1));
assertThrows(() => assertNegativeNumber(0));

assertNonNegativeInteger

badge

Assert the input is non-negative integer.

import { assertNonNegativeInteger } from "https://deno.land/x/assertion@$VERSION/number/assert_non_negative_integer.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNonNegativeInteger(0));
assertFalse(assertNonNegativeInteger(1));
assertThrows(() => assertNonNegativeInteger(-1));

assertNonNegativeNumber

badge

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

import { assertNonNegativeNumber } from "https://deno.land/x/assertion@$VERSION/number/assert_non_negative_number.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNonNegativeNumber(0));
assertFalse(assertNonNegativeNumber(1.1));
assertThrows(() => assertNonNegativeNumber(-1));

assertNonPositiveNumber

badge

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

import { assertNonPositiveNumber } from "https://deno.land/x/assertion@$VERSION/number/assert_non_positive_number.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertNonPositiveNumber(0));
assertFalse(assertNonPositiveNumber(-1));
assertThrows(() => assertNonPositiveNumber(1));

assertOdd

badge

Assert the input is odd.

import { assertOdd } from "https://deno.land/x/assertion@$VERSION/number/assert_odd.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertOdd(1));
assertThrows(() => assertOdd(0));

assertPositiveNumber

badge

Assert the input is positive number.

import { assertPositiveNumber } from "https://deno.land/x/assertion@$VERSION/number/assert_positive_number.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertPositiveNumber(1));
assertThrows(() => assertPositiveNumber(0));

assertUnitInterval

badge

Assert the input is unit interval. The unit interval means to the interval between 0 and 1 on the real number line.

import { assertUnitInterval } from "https://deno.land/x/assertion@$VERSION/number/assert_unit_interval.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertUnitInterval(0));
assertFalse(assertUnitInterval(1.0));
assertThrows(() => assertUnitInterval(-1));

Iterable subtypes

Assert a subtype of Iterable. All assertion functions must satisfy ⊂ Iterable<unknown>.

assertEmpty

badge

Assert the input is empty.

import { assertEmpty } from "https://deno.land/x/assertion@$VERSION/iterable/assert_empty.ts";
import { assertFalse } from "https://deno.land/std/testing/asserts.ts";

assertFalse(assertEmpty(""));
assertFalse(assertEmpty([]));
assertFalse(assertEmpty(new Set()));

string:

If the input is a string, it has a "" assertion.

array:

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

assertNotEmpty

badge

Assert the input is not empty.

import { assertNotEmpty } from "https://deno.land/x/assertion@$VERSION/iterable/assert_not_empty.ts";
import { assertFalse } from "https://deno.land/std/testing/asserts.ts";

assertFalse(assertNotEmpty("a"));
assertFalse(assertNotEmpty([0, 1]));

array:

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

assertSingle

badge

Assert the input is single element.

import { assertSingle } from "https://deno.land/x/assertion@$VERSION/iterable/assert_single.ts";
import {
  assert,
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";

assertFalse(assertSingle("a"));
assertFalse(assertSingle([0]));
assertThrows(() => assertSingle([0, 1, 2]));

array:

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

Date subtypes

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

assertValidDate

badge

Assert the input is valid Date.

import { assertValidDate } from "https://deno.land/x/assertion@$VERSION/date/assert_valid_date.ts";
import {
  assertFalse,
  assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
assertFalse(assertValidDate(new Date("2000/1/1")));
assertThrows(() => assertValidDate(new Date("invalid")));

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

Copyright © 2023-present Tomoki Miyauchi.

Released under the MIT license