Function assertWrap

A group of guard methods that do the following:

  1. Run the method's assertion on the given inputs.
  2. If the assertion fails, throws an error.
  3. If the assertion succeeds, the first input is returned and (when possible) type guarded.

This can also be called as a standalone assertion function which asserts that its input is truthy and returns it if so.

import {assertWrap} from '@augment-vir/assert';

// `result1` will be `['a']`
const result1 = assertWrap.deepEquals(['a'], ['a']);

const value: unknown = 'some value' as unknown;
// `result2` will be `'some value'` and it will have the type of `string`
const result2 = assertWrap.isString(value);

const value2: unknown = 'some value' as unknown;
// this will throw an error
const result3 = assertWrap.isNumber(value2);

AssertionError When the assertion fails.

Properties

endsWith: {
    <const ArrayElement>(
        parent: readonly ArrayElement[],
        child: ArrayElement,
        failureMessage?: string,
    ): typeof parent;
    (parent: string, child: string, failureMessage?: string): typeof parent;
    (
        parent: string | readonly string[],
        child: string,
        failureMessage?: string,
    ): typeof parent;
} = ...

Asserts that a parent string or array ends with a specific child. This uses reference equality when the parent is an array. Returns the parent if the assertion passes.

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.endsWith('ab', 'b'); // returns `'ab'`
assertWrap.endsWith('ab', 'a'); // throws an error
assertWrap.endsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
assertWrap.endsWith(['a', 'b'], 'a'); // throws an error

The parent value if it does end with the child.

AssertionError If the parent does not end with the child.

endsWithout: {
    <const ArrayElement>(
        parent: readonly ArrayElement[],
        child: ArrayElement,
        failureMessage?: string,
    ): typeof parent;
    (parent: string, child: string, failureMessage?: string): typeof parent;
    (
        parent: string | readonly string[],
        child: string,
        failureMessage?: string,
    ): typeof parent;
} = ...

Asserts that a parent string or array does not end with a specific child. This uses reference equality when the parent is an array. Returns the parent if the assertion passes.

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.endsWithout('ab', 'b'); // throws an error
assertWrap.endsWithout('ab', 'a'); // returns `'ab'`
assertWrap.endsWithout(['a', 'b'], 'b'); // throws an error
assertWrap.endsWithout(['a', 'b'], 'a'); // returns `['a', 'b']`

The parent value if it does not end with the child.

AssertionError If the parent ends with the child.

isLengthAtLeast: {
    <Element, Length extends number>(
        actual: readonly (undefined | Element)[],
        length: Length,
    ): AtLeastTuple<Element, Length>;
    <Actual extends string | AnyObject>(actual: Actual, length: number): Actual;
} = ...

Asserts that an array or string has at least the given length. Returns the value if the assertion passes.

Type guards an array into an AtLeastTuple. Performs no type guarding on a string.

import {assertWrap} from '@augment-vir/assert';

assertWrap.isLengthAtLeast(['a', 'b', 'c'], 2); // returns `['a', 'b', 'c']`
assertWrap.isLengthAtLeast(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
assertWrap.isLengthAtLeast(['a', 'b'], 3); // throws an error

The value if it has at least the given length.

AssertionError If the value is less than the given length.

isLengthExactly: {
    <Element, Length extends number>(
        actual: readonly (undefined | Element)[],
        length: Length,
    ): Tuple<Element, Length>;
    <Actual extends string | AnyObject>(actual: Actual, length: number): Actual;
} = ...

Asserts that an array or string has exactly the given length. Returns the value if the assertion passes.

Type guards an array into a Tuple. Performs no type guarding on a string.

import {assertWrap} from '@augment-vir/assert';

assertWrap.isLengthExactly(['a', 'b', 'c'], 2); // throws an error
assertWrap.isLengthExactly(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
assertWrap.isLengthExactly(['a', 'b'], 3); // throws an error

The value if it has exactly the given length.

AssertionError If the value is not exactly the given length.

output: {
    <const FunctionToCall extends AnyFunction>(
        functionToCall: FunctionToCall,
        inputs: Parameters<NoInfer<FunctionToCall>>,
        expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>,
        failureMessage?: string,
    ): OutputReturn<
        FunctionToCall,
        Awaited<ReturnType<NoInfer<FunctionToCall>>>,
    >;
    <const FunctionToCall extends AnyFunction>(
        asserter: CustomOutputAsserter<NoInfer<FunctionToCall>>,
        functionToCall: FunctionToCall,
        inputs: Parameters<NoInfer<FunctionToCall>>,
        expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>,
        failureMessage?: string,
    ): OutputReturn<
        FunctionToCall,
        Awaited<ReturnType<NoInfer<FunctionToCall>>>,
    >;
} = assertWrapOutput

Asserts that the output of the given function deeply equals expectations. A custom asserter can optionally be provided as the first argument to change the expectation checking from the default "deeply equals" to whatever you want. Returns the output if the assertion passes.

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
assertWrap.output((input: number) => String(input), [10], '5'); // throws an error

assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // throws an error
assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`

The output if the assertion passes.

AssertionError If the assertion fails.

startsWith: {
    <const ArrayElement>(
        parent: readonly ArrayElement[],
        child: ArrayElement,
        failureMessage?: string,
    ): typeof parent;
    (parent: string, child: string, failureMessage?: string): typeof parent;
    (
        parent: string | readonly string[],
        child: string,
        failureMessage?: string,
    ): typeof parent;
} = ...

Checks that a parent string or array starts with a specific child. This uses reference equality when the parent is an array. Returns the parent if the assertion passes.

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.startsWith('ab', 'b'); // throws an error
assertWrap.startsWith('ab', 'a'); // returns `'ab'`
assertWrap.startsWith(['a', 'b'], 'b'); // throws an error
assertWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`

The parent value if it starts with the child.

AssertionError If the parent does not start with the child.

startsWithout: {
    <const ArrayElement>(
        parent: readonly ArrayElement[],
        child: ArrayElement,
        failureMessage?: string,
    ): typeof parent;
    (parent: string, child: string, failureMessage?: string): typeof parent;
    (
        parent: string | readonly string[],
        child: string,
        failureMessage?: string,
    ): typeof parent;
} = ...

Asserts that a parent string or array starts with a specific child. This uses reference equality when the parent is an array. Returns the parent if the assertion passes.

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.startsWith('ab', 'b'); // returns `'ab'`
assertWrap.startsWith('ab', 'a'); // throws an error
assertWrap.startsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
assertWrap.startsWith(['a', 'b'], 'a'); // throws an error

The parent value if it does not start with the child.

AssertionError If the parent does start with the child.

throws: {
    (
        this: void,
        callbackOrPromise: () => never,
        matchOptions?: PartialWithNullable<
            {
                matchConstructor: ErrorConstructor
                | new (...args: any[]) => Error;
                matchMessage: string | RegExp;
            },
        >,
        failureMessage?: string,
    ): Error;
    (
        this: void,
        callbackOrPromise: Promise<any> | () => Promise<any>,
        matchOptions?: PartialWithNullable<
            {
                matchConstructor: ErrorConstructor
                | new (...args: any[]) => Error;
                matchMessage: string | RegExp;
            },
        >,
        failureMessage?: string,
    ): Promise<Error>;
    (
        this: void,
        callback: () => any,
        matchOptions?: PartialWithNullable<
            {
                matchConstructor: ErrorConstructor
                | new (...args: any[]) => Error;
                matchMessage: string | RegExp;
            },
        >,
        failureMessage?: string,
    ): Error;
    (
        this: void,
        callback: Promise<any> | () => any,
        matchOptions?: PartialWithNullable<
            {
                matchConstructor: ErrorConstructor
                | new (...args: any[]) => Error;
                matchMessage: string | RegExp;
            },
        >,
        failureMessage?: string,
    ): MaybePromise<Error>;
} = throwsAssertWrap

If a function input is provided:

Calls that function and asserts that the function throw an error, comparing the error with the given ErrorMatchOptions, if provided. Returns the Error if the assertion passes.

If a promise is provided:

Awaits the promise and asserts that the promise rejected with an error, comparing the error with the given ErrorMatchOptions, if provided. Returns the Error if the assertion passes.

This assertion will automatically type itself as async vs async based on the input. (A promise or async function inputs results in async. Otherwise, sync.)

Performs no type guarding.

import {assertWrap} from '@augment-vir/assert';

assertWrap.throws(() => {
throw new Error();
}); // returns the thrown error
assertWrap.throws(
() => {
throw new Error();
},
{matchMessage: 'hi'},
); // throws an error
await assertWrap.throws(Promise.reject()); // returns the rejection
assertWrap.throws(() => {}); // throws an error

The Error if the assertion passes.

AssertionError If the assertion fails.

Methods

  • Asserts that two values are deeply equal using the deep-eql package. Returns the first value if the assertion passes.

    Note that this check may be expensive, depending on what values it is passed. Whenever possible, use simpler equality checks instead (see the see section below).

    Type guards the first value.

    Type Parameters

    • Actual
    • Expected

    Parameters

    • this: void
    • actual: Actual
    • expected: Expected
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, Expected>

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.deepEquals('a', 'a'); // returns `'a'`

    assertWrap.deepEquals('1', 1); // throws an error

    assertWrap.deepEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`

    const objectExample = {a: 'a'};
    assertWrap.deepEquals(objectExample, objectExample); // returns `{a: 'a'}`

    AssertionError If both inputs are not deeply equal.

  • Asserts that a parent value has the key. Returns the parent if the assertion passes.

    Type guards the parent value.

    Type Parameters

    • const Parent
    • const Key extends PropertyKey

    Parameters

    • this: void
    • parent: Parent
    • key: Key
    • OptionalfailureMessage: string

    Returns CombineTypeWithKey<Key, Parent>

    The parent if it has the key.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.hasKey({a: 0, b: 1}, 'a'); // returns `{a: 0, b: 1}`
    assertWrap.hasKey({a: 0, b: 1}, 'c'); // throws an error

    AssertionError If the parent does not have the key.

  • Asserts that a parent value has all the keys. Returns the parent if the assertion passes.

    Type guards the parent value.

    Type Parameters

    • const Keys extends PropertyKey
    • const Parent

    Parameters

    • this: void
    • parent: Parent
    • keys: readonly Keys[]
    • OptionalfailureMessage: string

    Returns CombineTypeWithKey<Keys, Parent>

    The parent if it has all the keys.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `{a: 0, b: 1}`
    assertWrap.hasKeys({a: 0, b: 1}, ['b', 'c']); // throws an error

    AssertionError If the parent does not have all the keys.

  • Asserts that an object/array parent includes a child value through reference equality. Returns the parent value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Parent extends string | object

    Parameters

    • this: void
    • parent: Parent
    • value: unknown
    • OptionalfailureMessage: string

    Returns Parent

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};

    assertWrap.hasValue({child}, child); // returns `{child}`;
    assertWrap.hasValue({child: {a: 'a'}}, child); // throws an error
    assertWrap.hasValue([child], child); // returns `[child]`;

    AssertionError If the assertion fails.

  • Asserts that an object/array parent includes all child values through reference equality. Returns the parent value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Parent extends string | object

    Parameters

    • this: void
    • parent: Parent
    • values: unknown[]
    • OptionalfailureMessage: string

    Returns Parent

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};
    const child2 = {b: 'b'};

    assertWrap.hasValues({child, child2}, [child, child2]); // returns `{child, child2}`;
    assertWrap.hasValues({child: {a: 'a'}, child2}, [child, child2]); // throws an error
    assertWrap.hasValues([child], [child, child2]); // returns `[child]`;

    AssertionError If the assertion fails.

  • Asserts that a value is an instance of the given class constructor. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • const Instance

    Parameters

    • this: void
    • instance: unknown
    • constructor: Constructor<Instance>
    • OptionalfailureMessage: string

    Returns Instance

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
    assertWrap.instanceOf('abc', RegExp); // throws an error

    AssertionError If the value is not an instance of the given class constructor.

  • Asserts that a number is above the expectation (actual > expected). Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isAbove(10, 5); // returns `10`
    assertWrap.isAbove(5, 5); // throws an error
    assertWrap.isAbove(5, 10); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a number is within ±delta of the expectation. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • delta: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isApproximately(10, 8, 4); // returns `10`
    assertWrap.isApproximately(10, 12, 4); // returns `10`
    assertWrap.isApproximately(10, 8, 1); // throws an error
    assertWrap.isApproximately(10, 12, 1); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is an array. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns ArrayNarrow<Actual>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isArray([]); // returns `[]`
    assertWrap.isArray({length: 4}); // throws an error

    AssertionError If the assertion failed.

  • Asserts that a number is at least the expectation (actual >= expected). Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isAtLeast(10, 5); // returns `10`
    assertWrap.isAtLeast(5, 5); // returns `5`
    assertWrap.isAtLeast(5, 10); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a number is at most the expectation (actual <= expected). Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isAtMost(10, 5); // throws an error
    assertWrap.isAtMost(5, 5); // returns `5`
    assertWrap.isAtMost(5, 10); // returns `5`

    AssertionError If the assertion fails.

  • Asserts that a number is below the expectation (actual < expected). Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isBelow(10, 5); // throws an error
    assertWrap.isBelow(5, 5); // throws an error
    assertWrap.isBelow(5, 10); // returns `5`

    AssertionError If the assertion fails.

  • Asserts that a value is defined (not null and not undefined). Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • input: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, undefined | null>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isDefined(0); // returns `0`
    assertWrap.isDefined(''); // returns `''`
    assertWrap.isDefined(null); // fails
    assertWrap.isDefined(undefined); // fails

    AssertionError If the assertion fails.

  • Asserts that a value is empty. Supports strings, Maps, Sets, objects, and arrays. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns NarrowToActual<Actual, Empty>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isEmpty({}); // returns `{}`;
    assertWrap.isEmpty(''); // returns `''`;
    assertWrap.isEmpty([]); // returns `[]`;

    assertWrap.isEmpty('a'); // throws an error
    assertWrap.isEmpty({a: 'a'}); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is an instance of the built-in Error class and compares it to the given ErrorMatchOptions, if provided.

    Type guards the input.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalmatchOptions: PartialWithNullable<
          {
              matchConstructor: ErrorConstructor
              | new (...args: any[]) => Error;
              matchMessage: string | RegExp;
          },
      >
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, Error>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isError(new Error()); // returns the error instance
    assertWrap.isError(new Error(), {matchMessage: 'hi'}); // throws an error
    assertWrap.isError({message: 'not an error'}); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is exactly false. Returns the value if the assertion passes.

    Type guards the value.

    Parameters

    • this: void
    • input: unknown
    • OptionalfailureMessage: string

    Returns false

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isFalse(true); // throws an error
    assertWrap.isFalse(false); // returns `false`
    assertWrap.isFalse(1); // throws an error
    assertWrap.isFalse(0); // throws an error

    AssertionError If the value is not false.

  • Asserts that a value is falsy. Returns the value if the assertion passes.

    Type guards the value when possible.

    Type Parameters

    • T

    Parameters

    • this: void
    • input: T
    • OptionalfailureMessage: string

    Returns NarrowToExpected<T, FalsyValue>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isFalsy(true); // throws an error
    assertWrap.isFalsy(false); // returns `false`
    assertWrap.isFalsy(1); // throws an error
    assertWrap.isFalsy(0); // returns `0`

    AssertionError If the value is not falsy.

  • Asserts that a number is finite: meaning, not NaN and not Infinity or -Infinity. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isFinite(10); // returns `10`
    assertWrap.isFinite(parseInt('invalid')); // throws an error
    assertWrap.isFinite(Infinity); // throws an error
    assertWrap.isFinite(-Infinity); // throws an error

    AssertionError If the assertion fails.

  • Asserts that child value is contained within a parent object, array, or string through reference equality. Returns the child value if the assertion passes.

    Type guards the child when possible.

    Type Parameters

    • Parent extends string | object
    • Child

    Parameters

    • this: void
    • child: Child
    • parent: Parent
    • OptionalfailureMessage: string

    Returns Extract<Child, Values<Parent>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};

    assertWrap.isIn(child, {child}); // returns `child`;
    assertWrap.isIn('a', 'ab'); // returns `'a'`;
    assertWrap.isIn(child, [child]); // returns `child`;

    assertWrap.isIn(child, {child: {a: 'a'}}); // throws an error
    assertWrap.isIn('a', 'bc'); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a number is inside the provided min and max bounds, inclusive. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • __namedParameters: MinMax
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isInBounds(5, {min: 1, max: 10}); // returns `5`
    assertWrap.isInBounds(10, {min: 1, max: 10}); // returns `10`
    assertWrap.isInBounds(11, {min: 1, max: 10}); // fails
    assertWrap.isInBounds(0, {min: 1, max: 10}); // fails

    AssertionError If the assertion fails.

  • Asserts that a number is either Infinity or -Infinity. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isInfinite(10); // throws an error
    assertWrap.isInfinite(parseInt('invalid')); // throws an error
    assertWrap.isInfinite(Infinity); // returns `Infinity`
    assertWrap.isInfinite(-Infinity); // returns `-Infinity`

    AssertionError If the assertion fails.

  • Asserts that a key is contained within a parent value. Returns the key if the assertion passes.

    Type guards the key.

    Type Parameters

    • const Key extends PropertyKey
    • const Parent

    Parameters

    • this: void
    • key: Key
    • parent: Parent
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Key, keyof Parent>

    The key if it is in the parent.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isKeyof('a', {a: 0, b: 1}); // returns `'a'`
    assertWrap.isKeyof('c', {a: 0, b: 1}); // throws an error

    AssertionError If the key is not in the parent.

  • Asserts that a number is NaN. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNaN(10); // throws an error
    assertWrap.isNaN(parseInt('invalid')); // returns `NaN`
    assertWrap.isNaN(Infinity); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a number is outside ±delta of the expectation. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • expected: number
    • delta: number
    • OptionalfailureMessage: string

    Returns Actual

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotApproximately(10, 8, 4); // throws an error
    assertWrap.isNotApproximately(10, 12, 4); // throws an error
    assertWrap.isNotApproximately(10, 8, 1); // returns `10`
    assertWrap.isNotApproximately(10, 12, 1); // returns `10`

    AssertionError If the assertion fails.

  • Asserts that a value is not an array. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, readonly unknown[]>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotArray([]); // throws an error
    assertWrap.isNotArray({length: 4}); // returns `{length: 4}`

    AssertionError If the assertion failed.

  • Asserts that a value is not a BigInt. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, bigint>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotBigInt(123n); // throws an error
    assertWrap.isNotBigInt(123); // returns `123`

    AssertionError If the assertion failed.

  • Asserts that a value is not a boolean. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, boolean>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotBoolean(true); // throws an error
    assertWrap.isNotBoolean('true'); // returns `'true'`

    AssertionError If the assertion failed.

  • Asserts that a value is not empty. Supports strings, Maps, Sets, objects, and arrays. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, Empty>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotEmpty({}); // throws an error
    assertWrap.isNotEmpty(''); // throws an error
    assertWrap.isNotEmpty([]); // throws an error

    assertWrap.isNotEmpty('a'); // returns `'a'`;
    assertWrap.isNotEmpty({a: 'a'}); // returns `{a: 'a'}`;

    AssertionError If the assertion fails.

  • Asserts that a value is not a function. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, AnyFunction>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotFunction(() => {}); // throws an error
    assertWrap.isNotFunction({}); // returns `{}`

    AssertionError If the assertion failed.

  • Asserts that child value is not contained within a parent object, array, or string through reference equality. Returns the child value if the assertion passes.

    Type guards the child when possible.

    Type Parameters

    • Parent extends string | object
    • Child

    Parameters

    • this: void
    • child: Child
    • parent: Parent
    • OptionalfailureMessage: string

    Returns Exclude<Child, Values<Parent>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};

    assertWrap.isNotIn(child, {child}); // throws an error
    assertWrap.isNotIn('a', 'ab'); // throws an error
    assertWrap.isNotIn(child, [child]); // throws an error

    assertWrap.isNotIn(child, {child: {a: 'a'}}); // returns `child`;
    assertWrap.isNotIn('a', 'bc'); // returns `'a'`;

    AssertionError If the assertion fails.

  • Asserts that a key is not contained within a parent value. Returns the key if the assertion passes.

    Type guards the key.

    Type Parameters

    • const Key extends PropertyKey
    • const Parent

    Parameters

    • this: void
    • key: Key
    • parent: Parent
    • OptionalfailureMessage: string

    Returns Exclude<Key, RequiredKeysOf<Parent>>

    The key if it is not in the parent.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotKeyOf('a', {a: 0, b: 1}); // throws an error
    assertWrap.isNotKeyOf('c', {a: 0, b: 1}); // returns `'c'`

    AssertionError If the key is in the parent.

  • Asserts that a value is not exactly `null. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotNull(null); // throws an error
    assertWrap.isNotNull(undefined); // returns `undefined`

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see @see

    • {@link assertWrap.isFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, null>

  • Asserts that a value is not a number. This includes `NaN. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotNumber(123); // throws an error
    assertWrap.isNotNumber(123n); // returns `123n`

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see

    • {@link assertWrap.isNotFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, number>

  • Asserts that a value is not an object. This includes arrays. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, UnknownObject>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotObject({}); // throws an error
    assertWrap.isNotObject([]); // returns `[]`

    AssertionError If the assertion failed.

  • Asserts that a value is a valid PropertyKey. PropertyKey is a built-in TypeScript type which refers to all possible key types for a JavaScript object. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, Primitive>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isPropertyKey('key'); // returns `'key'`
    assertWrap.isPropertyKey(true); // throws an error
    assertWrap.isPropertyKey({}); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is a not Promise instance. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, Promise<any>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    class CustomThenable {
    constructor(public value: any) {}

    then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
    return new CustomThenable(
    onFulfilled ? onFulfilled(this.value) : this.value,
    );
    }
    }

    assertWrap.isNotPromise(Promise.resolve(5)); // throws an error
    assertWrap.isNotPromise(new CustomThenable(5)); // returns the `CustomThenable` promise
    assertWrap.isNotPromise(5); // returns `5`

    AssertionError If the assertion fails.

  • Asserts that a value is not a PromiseLike. Returns the value if the assertion passes.

    PromiseLike is TypeScript built-in type that has a .then method and thus behaves like a promise. This is also referred to as a "thenable". This enables the use of third-party promise implementations that aren't instances of the built-in Promise class.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, PromiseLike<any>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    class CustomThenable {
    constructor(public value: any) {}

    then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
    return new CustomThenable(
    onFulfilled ? onFulfilled(this.value) : this.value,
    );
    }
    }

    assertWrap.isNotPromiseLike(Promise.resolve(5)); // throws an error
    assertWrap.isNotPromiseLike(new CustomThenable(5)); // throws an error
    assertWrap.isNotPromiseLike(5); // returns `5`

    AssertionError If the assertion fails.

  • Asserts that a value is not a valid PropertyKey. PropertyKey is a built-in TypeScript type which refers to all possible key types for a JavaScript object. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, PropertyKey>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotPropertyKey('key'); // throws an error
    assertWrap.isNotPropertyKey(true); // returns `true`
    assertWrap.isNotPropertyKey({}); // returns `{}`

    AssertionError If the assertion fails.

  • Asserts that a value is not a string. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, string>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotString(''); // throws an error
    assertWrap.isNotString(5); // returns `5`

    AssertionError If the assertion failed.

  • Asserts that a value is not a symbol. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, symbol>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotSymbol(Symbol('my-symbol')); // throws an error
    assertWrap.isNotSymbol('my-symbol'); // returns `'my-symbol'`

    AssertionError If the assertion failed.

  • Asserts that a value is not exactly `undefined. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNotUndefined(undefined); // throws an error
    assertWrap.isNotUndefined(null); // returns `null`

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see

    • {@link assertWrap.isFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, undefined>

  • Asserts that a value is not a valid UUID. The nil or max UUIDs are included as not valid. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • const Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Exclude<Actual, `${string}-${string}-${string}-${string}-${string}`>

    import {assertWrap} from '@augment-vir/assert';
    import {createUuidV4} from '@augment-vir/common';

    assertWrap.isNotUuid(createUuidV4()); // throws an error
    assertWrap.isNotUuid('29e0f18e-6115-4982-8342-0afcadf5d611'); // throws an error
    assertWrap.isNotUuid('00000000-0000-0000-0000-000000000000'); // returns `'00000000-0000-0000-0000-000000000000'`
    assertWrap.isNotUuid('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'); // returns `'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'`
    assertWrap.isNotUuid('not-a-uuid'); // returns `'not-a-uuid'`

    AssertionError If the assertion fails.

  • Asserts that a value is exactly `null. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNull(null); // returns `null`
    assertWrap.isNull(undefined); // throws an error

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see

    • {@link assertWrap.isNotFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, null>

  • Asserts that a value is nullish (null or undefined). Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • input: Actual
    • OptionalfailureMessage: string

    Returns Extract<Actual, undefined | null>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNullish(0); // fails
    assertWrap.isNullish(''); // fails
    assertWrap.isNullish(null); // returns `null`
    assertWrap.isNullish(undefined); // returns `undefined`

    AssertionError If the assertion fails.

  • Asserts that a value is a number. This excludes `NaN. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isNumber(123); // returns `123`
    assertWrap.isNumber(123n); // throws an error

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see

    • {@link assertWrap.isNotFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, number>

  • Asserts that a number is outside the provided min and max bounds, exclusive. Returns the number if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual extends number

    Parameters

    • this: void
    • actual: Actual
    • __namedParameters: MinMax
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isOutBounds(5, {min: 1, max: 10}); // fails
    assertWrap.isOutBounds(10, {min: 1, max: 10}); // fails
    assertWrap.isOutBounds(11, {min: 1, max: 10}); // returns `11`
    assertWrap.isOutBounds(0, {min: 1, max: 10}); // returns `0`

    AssertionError If the assertion fails.

  • Asserts that a value is a JavaScript primitive. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Extract<Actual, Primitive>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isPrimitive('key'); // returns `'key'`
    assertWrap.isPrimitive(true); // returns `true`
    assertWrap.isPrimitive({}); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is a Promise instance. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Extract<Actual, Promise<any>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    class CustomThenable {
    constructor(public value: any) {}

    then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
    return new CustomThenable(
    onFulfilled ? onFulfilled(this.value) : this.value,
    );
    }
    }

    assertWrap.isPromise(Promise.resolve(5)); // returns the `Promise` instance
    assertWrap.isPromise(new CustomThenable(5)); // throws an error
    assertWrap.isPromise(5); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is a PromiseLike. Returns the value if the assertion passes.

    PromiseLike is TypeScript built-in type that has a .then method and thus behaves like a promise. This is also referred to as a "thenable". This enables the use of third-party promise implementations that aren't instances of the built-in Promise class.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Extract<Actual, PromiseLike<any>>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    class CustomThenable {
    constructor(public value: any) {}

    then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
    return new CustomThenable(
    onFulfilled ? onFulfilled(this.value) : this.value,
    );
    }
    }

    assertWrap.isPromiseLike(Promise.resolve(5)); // returns the `Promise` instance
    assertWrap.isPromiseLike(new CustomThenable(5)); // returns the `CustomThenable` instance
    assertWrap.isPromiseLike(5); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a value is not a JavaScript primitive. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns Extract<Actual, PropertyKey>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isPrimitive('key'); // throws an error
    assertWrap.isPrimitive(true); // throws an error
    assertWrap.isPrimitive({}); // returns `{}`

    AssertionError If the assertion fails.

  • Asserts that a value is exactly true. Returns the value if the assertion passes.

    Type guards the value.

    Parameters

    • this: void
    • input: unknown
    • OptionalfailureMessage: string

    Returns true

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isTrue(true); // returns `true`
    assertWrap.isTrue(false); // throws an error
    assertWrap.isTrue(1); // throws an error
    assertWrap.isTrue(0); // throws an error

    AssertionError If the value is not true.

  • Asserts that a value is truthy. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • T

    Parameters

    • this: void
    • input: T
    • OptionalfailureMessage: string

    Returns Exclude<T, FalsyValue>

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isTruthy(true); // returns `true`
    assertWrap.isTruthy(false); // throws an error
    assertWrap.isTruthy(1); // returns `1`
    assertWrap.isTruthy(0); // throws an error

    AssertionError If the value is not truthy.

  • Asserts that a value is exactly `undefined. Returns the value if the assertion passes.

    Type guards the value.

    @example

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.isUndefined(undefined); // returns `undefined`
    assertWrap.isUndefined(null); // throws an error

    @returns The value if the assertion passes. @throws {@link AssertionError} If the assertion failed. @see

    • {@link assertWrap.isNotFunction} : the opposite assertion.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, undefined>

  • Asserts that a value is a valid UUID. Does not accept the nil or max UUIDs. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: unknown
    • OptionalfailureMessage: string

    Returns NarrowToExpected<Actual, `${string}-${string}-${string}-${string}-${string}`>

    import {assertWrap} from '@augment-vir/assert';
    import {createUuidV4} from '@augment-vir/common';

    assertWrap.isUuid(createUuidV4()); // returns the generated UUID
    assertWrap.isUuid('29e0f18e-6115-4982-8342-0afcadf5d611'); // returns `'29e0f18e-6115-4982-8342-0afcadf5d611'`
    assertWrap.isUuid('00000000-0000-0000-0000-000000000000'); // throws an error
    assertWrap.isUuid('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'); // throws an error
    assertWrap.isUuid('not-a-uuid'); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a parent value does not have the key. Returns the parent if the assertion passes.

    Type guards the parent value.

    Type Parameters

    • const Parent
    • const Key extends PropertyKey

    Parameters

    • this: void
    • parent: Parent
    • key: Key
    • OptionalfailureMessage: string

    Returns Exclude<Parent, Record<Key, any>>

    The parent if it does not have the key.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.lacksKey({a: 0, b: 1}, 'a'); // throws an error
    assertWrap.lacksKey({a: 0, b: 1}, 'c'); // returns `{a: 0, b: 1}`

    AssertionError If the parent has the key.

  • Asserts that a parent value none of the keys. Returns the parent if the assertion passes.

    Type guards the parent value.

    Type Parameters

    • const Parent
    • const Key extends PropertyKey

    Parameters

    • this: void
    • parent: Parent
    • keys: readonly Key[]
    • OptionalfailureMessage: string

    Returns Exclude<Parent, Partial<Record<Key, any>>>

    The parent if it does not have any of the keys.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.lacksKeys({a: 0, b: 1}, ['b', 'c']); // throws an error
    assertWrap.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `{a: 0, b: 1}`

    AssertionError If the parent has any of the keys.

  • Asserts that an object/array parent does not include a child value through reference equality. Returns the parent value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Parent extends string | object

    Parameters

    • this: void
    • parent: Parent
    • value: unknown
    • OptionalfailureMessage: string

    Returns Parent

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};

    assertWrap.lacksValue({child}, child); // throws an error
    assertWrap.lacksValue({child: {a: 'a'}}, child); // returns `{child: {a: 'a'}}`;
    assertWrap.lacksValue([child], child); // throws an error

    AssertionError If the assertion fails.

  • Asserts that an object/array parent includes none of the provided child values through reference equality. Returns the parent value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Parent extends string | object

    Parameters

    • this: void
    • parent: Parent
    • values: unknown[]
    • OptionalfailureMessage: string

    Returns Parent

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    const child = {a: 'a'};
    const child2 = {b: 'b'};

    assertWrap.lacksValues({}, [child, child2]); // returns `{}`;
    assertWrap.lacksValues({child, child2}, [child, child2]); // throws an error
    assertWrap.lacksValues({child: {a: 'a'}, child2}, [child, child2]); // throws an error

    AssertionError If the assertion fails.

  • Asserts that two values are loosely equal (using ==). Returns the first value if the assertion passes.

    Type guards the first value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • expected: unknown
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.looseEquals('a', 'a'); // returns `'a'`

    assertWrap.looseEquals('1', 1); // returns `'1'`

    assertWrap.looseEquals({a: 'a'}, {a: 'a'}); // throws an error

    const objectExample = {a: 'a'};
    assertWrap.looseEquals(objectExample, objectExample); // returns `{a: 'a'}`

    AssertionError If both inputs are not loosely equal.

  • Asserts that a string (first input, actual) matches a RegExp (second input, expected). Returns the string if the assertion passes.

    Performs no type guarding.

    Parameters

    • this: void
    • actual: string
    • expected: RegExp
    • OptionalfailureMessage: string

    Returns string

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.matches('hi', /^h/); // returns `'hi'`
    assertWrap.matches('hi', /^g/); // throws an error

    AssertionError If the assertion fails.

  • Asserts that a string (first input, actual) does not match a RegExp (second input, expected). Returns the string if the assertion passes.

    Performs no type guarding.

    Parameters

    • this: void
    • actual: string
    • expected: RegExp
    • OptionalfailureMessage: string

    Returns string

    The value if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.mismatches('hi', /^h/); // throws an error
    assertWrap.mismatches('hi', /^g/); // returns `'hi'`

    AssertionError If the assertion fails.

  • Asserts that two values are not deeply equal using the deep-eql package. Returns the first value if the assertion passes.

    Note that this check may be expensive, depending on what values it is passed. Whenever possible, use simpler equality checks instead (see the see section below).

    Type guards the first value.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • expected: unknown
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.deepEquals('a', 'a'); // returns `'a'`

    assertWrap.deepEquals('1', 1); // throws an error

    assertWrap.deepEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`

    const objectExample = {a: 'a'};
    assertWrap.deepEquals(objectExample, objectExample); // returns `{a: 'a'}`

    AssertionError If both inputs are deeply equal.

  • Asserts that two objects are not deeply equal by checking only their top-level values for strict (non-deep, reference, using ===) equality and, if so, returns the first object.

    Performs no type guarding.

    Type Parameters

    Parameters

    Returns Actual

    The first input if the assertion passes.

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // throws an error

    assertWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`

    const bExample = {b: 'b'};
    assertWrap.notEntriesEqual({a: bExample}, {a: bExample}); // throws an error

    AssertionError If both inputs are equal.

  • Asserts that a value is not an instance of the given class constructor. Returns the value if the assertion passes.

    Type guards the value.

    Type Parameters

    • const Actual
    • const Instance

    Parameters

    • this: void
    • instance: Actual
    • constructor: Constructor<Instance>
    • OptionalfailureMessage: string

    Returns Exclude<Actual, Instance>

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.notInstanceOf(/abc/, RegExp); // throws an error
    assertWrap.notInstanceOf('abc', RegExp); // returns `'abc'`

    AssertionError If the value is an instance of the given class constructor.

  • Asserts that two values are not deeply equal when stringified into JSON. This may not make any sense if the values are not valid JSON. This internally sorts all given object keys so it is insensitive to object key order. Returns the first value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • expected: unknown
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // throws an error

    assertWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `{a: {b: 'b'}}`

    AssertionError If both inputs are not equal.

  • Asserts that two values are not loosely equal (using ==). Returns the first value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • expected: unknown
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.notLooseEquals('a', 'a'); // throws an error

    assertWrap.notLooseEquals('1', 1); // throws an error

    assertWrap.notLooseEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`

    const objectExample = {a: 'a'};
    assertWrap.notLooseEquals(objectExample, objectExample); // throws an error

    AssertionError If both inputs are loosely equal.

  • Asserts that two values are not strictly equal (using ===). Returns the first value if the assertion passes.

    Performs no type guarding.

    Type Parameters

    • Actual

    Parameters

    • this: void
    • actual: Actual
    • expected: unknown
    • OptionalfailureMessage: string

    Returns Actual

    import {assertWrap} from '@augment-vir/assert';

    assertWrap.notStrictEquals('a', 'a'); // throws an error

    assertWrap.notStrictEquals('1', 1); // returns `'1'`

    assertWrap.notStrictEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`

    const objectExample = {a: 'a'};
    assertWrap.notStrictEquals(objectExample, objectExample); // throws an error

    AssertionError If both inputs are strictly equal.