Checks that a parent string or array ends with a specific child. This uses reference
equality when the parent is an array. Returns the value if the check passes, otherwise
undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.endsWith('ab', 'b'); // returns `'ab'`
checkWrap.endsWith('ab', 'a'); // returns `undefined`
checkWrap.endsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
checkWrap.endsWith(['a', 'b'], 'a'); // returns `undefined`
Checks 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 value if the check passes,
otherwise undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.endsWithout('ab', 'b'); // returns `undefined`
checkWrap.endsWithout('ab', 'a'); // returns `'ab'`
checkWrap.endsWithout(['a', 'b'], 'b'); // returns `undefined`
checkWrap.endsWithout(['a', 'b'], 'a'); // returns `['a', 'b']`
Checks that an array or string has at least the given length. Returns the value if the
check passes, otherwise undefined
.
Type guards an array into an AtLeastTuple. Performs no type guarding on a string.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isLengthAtLeast(['a', 'b', 'c'], 2); // returns `['a', 'b', 'c']`
checkWrap.isLengthAtLeast(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
checkWrap.isLengthAtLeast(['a', 'b'], 3); // returns `undefined`
Checks that an array or string has exactly the given length. Returns the value if the
check passes, otherwise undefined
.
Type guards an array into a Tuple. Performs no type guarding on a string.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isLengthExactly(['a', 'b', 'c'], 2); // returns `undefined`
checkWrap.isLengthExactly(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
checkWrap.isLengthExactly(['a', 'b'], 3); // returns `undefined`
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
check passes, otherwise undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
checkWrap.output((input: number) => String(input), [10], '5'); // returns `undefined`
checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // returns `undefined`
checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`
Checks that a parent string or array starts with a specific child. This uses reference
equality when the parent is an array. Returns the value if the check passes, otherwise
undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.startsWith('ab', 'b'); // returns `undefined`
checkWrap.startsWith('ab', 'a'); // returns `'ab'`
checkWrap.startsWith(['a', 'b'], 'b'); // returns `undefined`
checkWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`
Checks that a parent string or array starts with a specific child. This uses reference
equality when the parent is an array. Returns the value if the check passes, otherwise
undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.startsWith('ab', 'b'); // returns `undefined`
checkWrap.startsWith('ab', 'a'); // returns `'ab'`
checkWrap.startsWith(['a', 'b'], 'b'); // returns `undefined`
checkWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`
If a function input is provided:
Calls that function and checks that the function throw an error, comparing the error with
the given ErrorMatchOptions, if provided. Returns the error if the check passes,
otherwise undefined
.
If a promise is provided:
Awaits the promise and checks that the promise rejected with an error, comparing the
error with the given ErrorMatchOptions, if provided. Returns the error if the
check passes, otherwise undefined
.
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.
Checks that two values are deeply equal using the deep-eql package. Returns the first value if the check 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.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.deepEquals('a', 'a'); // true
checkWrap.deepEquals('1', 1); // false
checkWrap.deepEquals({a: 'a'}, {a: 'a'}); // true
const objectExample = {a: 'a'};
checkWrap.deepEquals(objectExample, objectExample); // true
Checks that two objects are deeply equal by checking only their top-level values for
strict (non-deep, reference, using
===
)
equality. If the check passes the first object is returned. If not, undefined
is
returned.
Type guards the first value.
The first input if the assertion passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.entriesEqual({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
checkWrap.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `undefined`
const bExample = {b: 'b'};
checkWrap.entriesEqual({a: bExample}, {a: bExample}); // returns `{a: {b: 'b'}}`
Checks that a parent value has the key. Returns the parent value if the check passes,
otherwise undefined
.
Type guards the parent value.
The parent value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.hasKey({a: 0, b: 1}, 'a'); // returns `{a: 0, b: 1}`
checkWrap.hasKey({a: 0, b: 1}, 'c'); // returns `undefined`
Checks that a parent value has all the keys. Returns the parent value if the check
passes, otherwise undefined
.
Type guards the parent value.
The parent value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `{a: 0, b: 1}`
checkWrap.hasKeys({a: 0, b: 1}, ['b', 'c']); // returns `undefined`
Checks that an object/array parent includes a child value through reference equality.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
checkWrap.hasValue({child}, child); // returns `{child}`
checkWrap.hasValue({child: {a: 'a'}}, child); // returns `undefined`
checkWrap.hasValue([child], child); // returns `[child]`
Checks that an object/array parent includes all child values through reference equality.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
const child2 = {b: 'b'};
checkWrap.hasValues({child, child2}, [child, child2]); // returns `{child, child2}`
checkWrap.hasValues({child: {a: 'a'}, child2}, [child, child2]); // returns `undefined`
checkWrap.hasValues([child], [child, child2]); // returns `[child]`
Checks that a value is an instance of the given class constructor. Returns the value if
the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
checkWrap.instanceOf('abc', RegExp); // returns `undefined`
Checks that a number is above the expectation (actual > expected
). Returns the number
if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isAbove(10, 5); // returns `10`
checkWrap.isAbove(5, 5); // returns `undefined`
checkWrap.isAbove(5, 10); // returns `undefined`
Checks that a number is within ±delta
of the expectation. Returns the number if the
check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isApproximately(10, 8, 4); // returns `10`
checkWrap.isApproximately(10, 12, 4); // returns `10`
checkWrap.isApproximately(10, 8, 1); // returns `undefined`
checkWrap.isApproximately(10, 12, 1); // returns `undefined`
Checks that a value is an array. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isArray([]); // returns `[]`
checkWrap.isArray({length: 4}); // returns `undefined`
Checks that a number is at least the expectation (actual >= expected
). Returns the
number if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isAtLeast(10, 5); // returns `10`
checkWrap.isAtLeast(5, 5); // returns `5`
checkWrap.isAtLeast(5, 10); // returns `undefined`
Checks that a number is at most the expectation (actual <= expected
). Returns the
number if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isAtMost(10, 5); // returns `undefined`
checkWrap.isAtMost(5, 5); // returns `5`
checkWrap.isAtMost(5, 10); // returns `5`
Checks that a number is below the expectation (actual < expected
). Returns the number
if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isBelow(10, 5); // returns `undefined`
checkWrap.isBelow(5, 5); // returns `undefined`
checkWrap.isBelow(5, 10); // returns `5`
Checks that a value is a BigInt. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isBigInt(123n); // returns `123n`
checkWrap.isBigInt(123); // returns `undefined`
Checks that a value is a boolean. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isBoolean(true); // returns `true`
checkWrap.isBoolean('true'); // returns `undefined`
Checks that a value is empty. Supports strings, Maps, Sets, objects, and arrays.
Type guards the value.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isEmpty({}); // returns `{}`
checkWrap.isEmpty(''); // returns `''`
checkWrap.isEmpty([]); // returns `[]`
checkWrap.isEmpty('a'); // returns `undefined`
checkWrap.isEmpty({a: 'a'}); // returns `undefined`
Checks that a child value is an enum member. Returns the child value if the check passes,
otherwise undefined
.
Type guards the child value.
The child value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
enum MyEnum {
A = 'a',
B = 'b',
}
checkWrap.isEnumValue('a', MyEnum); // returns `'a'`
checkWrap.isEnumValue('A', MyEnum); // returns `undefined`
Checks that a value is an instance of the built-in Error
class and compares it to the
given ErrorMatchOptions, if provided. Returns the error if the check passes,
otherwise undefined
.
Type guards the input.
Optional
matchOptions: PartialWithNullable<The Error if the check passes, otherwise undefined
.
Checks that a value is exactly false
. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isFalse(true); // returns `false`
checkWrap.isFalse(false); // returns `true`
checkWrap.isFalse(1); // returns `false`
checkWrap.isFalse(0); // returns `false`
Checks that a value is falsy. Returns the value if the check passes, otherwise
undefined
.
Type guards the value when possible.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isFalsy(true); // returns `false`
checkWrap.isFalsy(false); // returns `true`
checkWrap.isFalsy(1); // returns `false`
checkWrap.isFalsy(0); // returns `true`
Checks that a number is finite: meaning, not NaN
and not Infinity
or -Infinity
.
Returns the number if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isFinite(10); // returns `10`
checkWrap.isFinite(parseInt('invalid')); // returns `undefined`
checkWrap.isFinite(Infinity); // returns `undefined`
checkWrap.isFinite(-Infinity); // returns `undefined`
Checks that a value is a function. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isFunction(() => {}); // returns `() => {}`
checkWrap.isFunction({}); // returns `undefined`
Checks that a value is an HttpStatus. Returns the value if the check passes,
otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isHttpStatus(400); // returns `400`
checkWrap.isHttpStatus(500); // returns `500`
checkWrap.isHttpStatus(99); // returns `undefined`
Checks that a value is an HttpStatus within a specific HttpStatusCategory.
Returns the value if the check passes, otherwise undefined
.
Type guards the value.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isHttpStatusCategory(400, HttpStatusCategory.ClientError); // returns `400`
checkWrap.isHttpStatusCategory(500, HttpStatusCategory.Success); // returns `undefined`
checkWrap.isHttpStatusCategory(99, HttpStatusCategory.Information); // returns `undefined`
Checks that child value is contained within a parent object, array, or string through reference equality.
Type guards the child when possible.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
checkWrap.isIn(child, {child}); // returns `child`
checkWrap.isIn('a', 'ab'); // returns `'a'`
checkWrap.isIn(child, [child]); // returns `child`
checkWrap.isIn(child, {child: {a: 'a'}}); // returns `undefined`
checkWrap.isIn('a', 'bc'); // returns `undefined`
Checks that a number is inside the provided min and max bounds, inclusive. Returns the
number if the check passes, otherwise undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isInBounds(5, {min: 1, max: 10}); // returns `5`
checkWrap.isInBounds(10, {min: 1, max: 10}); // returns `10`
checkWrap.isInBounds(11, {min: 1, max: 10}); // returns `undefined`
checkWrap.isInBounds(0, {min: 1, max: 10}); // returns `undefined`
Checks that a number is either Infinity
or -Infinity
. Returns the number if the check
passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isInfinite(10); // returns `undefined`
checkWrap.isInfinite(parseInt('invalid')); // returns `undefined`
checkWrap.isInfinite(Infinity); // returns `Infinity`
checkWrap.isInfinite(-Infinity); // returns `-Infinity`
Checks that a number is an integer. Returns the number if the check passes, otherwise
undefined
. This has the same limitations as
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isInteger(5); // returns `5`
checkWrap.isInteger(5.0000000000000001); // returns `5`
checkWrap.isInteger(5.1); // returns `undefined`
checkWrap.isInteger(NaN); // returns `undefined`
Checks that a key is contained within a parent value. Returns the key if the check
passes, otherwise undefined
.
Type guards the key.
The key if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isKeyof('a', {a: 0, b: 1}); // returns `'a'`
checkWrap.isKeyof('c', {a: 0, b: 1}); // returns `undefined`
Checks that a number is
NaN
.
Returns the number if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNaN(10); // returns `undefined`
checkWrap.isNaN(parseInt('invalid')); // returns `NaN`
checkWrap.isNaN(Infinity); // returns `undefined`
Checks that a number is outside ±delta
of the expectation. Returns the number if the
check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotApproximately(10, 8, 4); // returns `undefined`
checkWrap.isNotApproximately(10, 12, 4); // returns `undefined`
checkWrap.isNotApproximately(10, 8, 1); // returns `10`
checkWrap.isNotApproximately(10, 12, 1); // returns `10`
Checks that a value is not an array. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotArray([]); // returns `undefined`
checkWrap.isNotArray({length: 4}); // returns `{length: 4}`
Checks that a value is not a BigInt. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotBigInt(123n); // returns `undefined`
checkWrap.isNotBigInt(123); // returns `123`
Checks that a value is not a boolean. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotBoolean(true); // returns `undefined`
checkWrap.isNotBoolean('true'); // returns `'true'`
Checks that a value is not empty. Supports strings, Maps, Sets, objects, and arrays.
Type guards the value.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotEmpty({}); // returns `undefined`
checkWrap.isNotEmpty(''); // returns `undefined`
checkWrap.isNotEmpty([]); // returns `undefined`
checkWrap.isNotEmpty('a'); // returns `'a'`
checkWrap.isNotEmpty({a: 'a'}); // returns `{a: 'a'}`
Checks that a child value is not an enum member. Returns the child value if the check
passes, otherwise undefined
.
Type guards the child value.
The child value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
enum MyEnum {
A = 'a',
B = 'b',
}
checkWrap.isNotEnumValue('a', MyEnum); // returns `undefined`
checkWrap.isNotEnumValue('A', MyEnum); // returns `'A'`
Checks that a value is not a function. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotFunction(() => {}); // returns `undefined`
checkWrap.isNotFunction({}); // returns `{}`
Checks that child value is not contained within a parent object, array, or string through reference equality.
Type guards the child when possible.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
checkWrap.isNotIn(child, {child}); // returns `undefined`
checkWrap.isNotIn('a', 'ab'); // returns `undefined`
checkWrap.isNotIn(child, [child]); // returns `undefined`
checkWrap.isNotIn(child, {child: {a: 'a'}}); // returns `child`
checkWrap.isNotIn('a', 'bc'); // returns `'a'`
Checks that a number is not an integer. Returns the number if the check passes, otherwise
undefined
. This has the same limitations, as
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotInteger(5); // returns `undefined`
checkWrap.isNotInteger(5.0000000000000001); // returns `undefined`
checkWrap.isNotInteger(5.1); // returns `5.1`
checkWrap.isNotInteger(NaN); // returns `NaN`
Checks that a key is not contained within a parent value. Returns the key if the check
passes, otherwise undefined
.
Type guards the key.
The key if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotKeyOf('a', {a: 0, b: 1}); // returns `undefined`
checkWrap.isNotKeyOf('c', {a: 0, b: 1}); // returns `'c'`
Checks that a value is not exactly null. Returns the value if the check passes, otherwise
undefined`.
Type guards the value.
@example
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotNull(null); // returns `undefined`
checkWrap.isNotNull(undefined); // returns `undefined`
@returns The value if the check passes. Otherwise, undefined
.
Checks that a value is not a number. This includes NaN. Returns the value if the check passes, otherwise
undefined`.
Type guards the value.
@example
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotNumber(123); // returns `undefined`
checkWrap.isNotNumber(123n); // returns `123n`
@returns The value if the check passes. Otherwise, undefined
.
Checks that a value is not an object. This includes arrays. Returns the value if the
check passes, otherwise undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotObject({}); // returns `undefined`
checkWrap.isNotObject([]); // returns `[]`
Checks 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
check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotPrimitive('key'); // returns `undefined`
checkWrap.isNotPrimitive(true); // returns `undefined`
checkWrap.isNotPrimitive({}); // returns `{}`
Checks that a value is a not Promise
instance. Returns the value if the check passes,
otherwise undefined
.
Type guards the value.
import {checkWrap} from '@augment-vir/assert';
class CustomThenable {
constructor(public value: any) {}
then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
return new CustomThenable(
onFulfilled ? onFulfilled(this.value) : this.value,
);
}
}
checkWrap.isNotPromise(Promise.resolve(5)); // returns `false`
checkWrap.isNotPromise(new CustomThenable(5)); // returns `true`
checkWrap.isNotPromise(5); // returns `true`
Checks that a value is not a PromiseLike
. Returns the value if the check passes,
otherwise undefined
.
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.
import {checkWrap} from '@augment-vir/assert';
class CustomThenable {
constructor(public value: any) {}
then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
return new CustomThenable(
onFulfilled ? onFulfilled(this.value) : this.value,
);
}
}
checkWrap.isNotPromiseLike(Promise.resolve(5)); // returns `false`
checkWrap.isNotPromiseLike(new CustomThenable(5)); // returns `false`
checkWrap.isNotPromiseLike(5); // returns `true`
Checks 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 check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotPropertyKey('key'); // returns `undefined`
checkWrap.isNotPropertyKey(true); // returns `true`
checkWrap.isNotPropertyKey({}); // returns `{}`
Checks that a value is not a string. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotString(''); // returns `undefined`
checkWrap.isNotString(5); // returns `5`
Checks that a value is not a symbol. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNotSymbol(Symbol('my-symbol')); // returns `undefined`
checkWrap.checkWrap('my-symbol'); // returns `'my-symbol'`
Checks that a value is not a valid UUID. The nil or max UUIDs are included as not
valid. Returns the value if the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
import {createUuidV4} from '@augment-vir/common';
checkWrap.isNotUuid(createUuidV4()); // returns `undefined`
checkWrap.isNotUuid('29e0f18e-6115-4982-8342-0afcadf5d611'); // returns `undefined`
checkWrap.isNotUuid('00000000-0000-0000-0000-000000000000'); // returns `'00000000-0000-0000-0000-000000000000'`
checkWrap.isNotUuid('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'); // returns `'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'`
checkWrap.isNotUuid('not-a-uuid'); // returns `'not-a-uuid'`
Checks that a value is exactly null. Returns the value if the check passes, otherwise
undefined`.
Type guards the value.
@example
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNull(null); // returns `null`
checkWrap.isNull(undefined); // returns `undefined`
@returns The value if the check passes. Otherwise, undefined
.
Checks that a value is a number. This excludes NaN. Returns the value if the check passes, otherwise
undefined`.
Type guards the value.
@example
import {checkWrap} from '@augment-vir/assert';
checkWrap.isNumber(123); // returns `123`
checkWrap.isNumber(123n); // returns `undefined`
@returns The value if the check passes. Otherwise, undefined
.
Checks that a value is an object. This excludes arrays. Returns the value if the check
passes, otherwise undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isObject({}); // returns `{}`
checkWrap.isObject([]); // returns `undefined`
Checks that a number is outside the provided min and max bounds, exclusive. Returns the
number if the check passes, otherwise undefined
.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isOutBounds(5, {min: 1, max: 10}); // returns `undefined`
checkWrap.isOutBounds(10, {min: 1, max: 10}); // returns `undefined`
checkWrap.isOutBounds(11, {min: 1, max: 10}); // returns `11`
checkWrap.isOutBounds(0, {min: 1, max: 10}); // returns `0`
Checks that a value is a JavaScript
primitive. Returns the value if
the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isPrimitive('key'); // returns `'key'`
checkWrap.isPrimitive(true); // returns `true`
checkWrap.isPrimitive({}); // returns `undefined`
Checks that a value is a Promise
instance. Returns the value if the check passes,
otherwise undefined
.
Type guards the value.
import {checkWrap} from '@augment-vir/assert';
class CustomThenable {
constructor(public value: any) {}
then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
return new CustomThenable(
onFulfilled ? onFulfilled(this.value) : this.value,
);
}
}
checkWrap.isPromise(Promise.resolve(5)); // returns `true`
checkWrap.isPromise(new CustomThenable(5)); // returns `false`
checkWrap.isPromise(5); // returns `false`
Checks that a value is a PromiseLike
. Returns the value if the check passes, otherwise
undefined
.
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.
import {checkWrap} from '@augment-vir/assert';
class CustomThenable {
constructor(public value: any) {}
then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
return new CustomThenable(
onFulfilled ? onFulfilled(this.value) : this.value,
);
}
}
checkWrap.isPromiseLike(Promise.resolve(5)); // returns `true`
checkWrap.isPromiseLike(new CustomThenable(5)); // returns `true`
checkWrap.isPromiseLike(5); // returns `false`
Checks that a value is not a JavaScript
primitive. Returns the value if
the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isPrimitive('key'); // returns `undefined`
checkWrap.isPrimitive(true); // returns `undefined`
checkWrap.isPrimitive({}); // returns `{}`
Checks that a value is a string. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isString(''); // returns `''`
checkWrap.isString(5); // returns `undefined`
Checks that a value is a symbol. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes. Otherwise, undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isSymbol(Symbol('my-symbol')); // returns the created symbol
checkWrap.isSymbol('my-symbol'); // returns `undefined`
Checks that a value is exactly true
. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isTrue(true); // returns `true`
checkWrap.isTrue(false); // returns `false`
checkWrap.isTrue(1); // returns `false`
checkWrap.isTrue(0); // returns `false`
Checks that a value is truthy. Returns the value if the check passes, otherwise
undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.isTruthy(true); // passes
checkWrap.isTruthy(false); // fails
checkWrap.isTruthy(1); // passes
checkWrap.isTruthy(0); // fails
Checks that a value is a valid UUID. Does not accept the nil or max UUIDs. Returns the
value if the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
import {createUuidV4} from '@augment-vir/common';
checkWrap.isUuid(createUuidV4()); // returns the generated UUID
checkWrap.isUuid('29e0f18e-6115-4982-8342-0afcadf5d611'); // returns `'29e0f18e-6115-4982-8342-0afcadf5d611'`
checkWrap.isUuid('00000000-0000-0000-0000-000000000000'); // returns `undefined`
checkWrap.isUuid('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'); // returns `undefined`
checkWrap.isUuid('not-a-uuid'); // returns `undefined`
Checks that two values are deeply equal when stringified into JSON. This will fail or 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 check passes.
Type guards the first value.
import {checkWrap} from '@augment-vir/assert';
checkWrap.jsonEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
checkWrap.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `undefined`
Checks that a parent value does not have the key. Returns the parent value if the check
passes, otherwise undefined
.
Type guards the parent value.
The parent value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.lacksKey({a: 0, b: 1}, 'a'); // returns `undefined`
checkWrap.lacksKey({a: 0, b: 1}, 'c'); // returns `{a: 0, b: 1}`
Checks that a parent value none of the keys. Returns the parent value if the check
passes, otherwise undefined
.
Type guards the parent value.
The parent value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.lacksKeys({a: 0, b: 1}, ['b', 'c']); // returns `undefined`
checkWrap.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `{a: 0, b: 1}`
Checks that an object/array parent does not include a child value through reference equality.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
checkWrap.lacksValue({child}, child); // returns `undefined`
checkWrap.lacksValue({child: {a: 'a'}}, child); // returns `{child: {a: 'a'}}`
checkWrap.lacksValue([child], child); // returns `undefined`
Checks that an object/array parent includes none of the provided child values through reference equality.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
const child = {a: 'a'};
const child2 = {b: 'b'};
checkWrap.lacksValues({}, [child, child2]); // returns `{}`
checkWrap.lacksValues({child, child2}, [child, child2]); // returns `undefined`
checkWrap.lacksValues({child: {a: 'a'}, child2}, [child, child2]); // returns `undefined`
Checks that two values are loosely equal (using
==
).
Returns the first value if the check passes, otherwise undefined
.
Type guards the first value.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.looseEquals('a', 'a'); // returns `'a'`
checkWrap.looseEquals('1', 1); // returns `'1'`
checkWrap.looseEquals({a: 'a'}, {a: 'a'}); // returns `undefined`
const objectExample = {a: 'a'};
checkWrap.looseEquals(objectExample, objectExample); // returns `{a: 'a'}`
Checks that a string (first input, actual
) matches a RegExp (second input, expected
).
Returns the string if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.matches('hi', /^h/); // returns `'hi'`
checkWrap.matches('hi', /^g/); // returns `undefined`
Checks that a string (first input, actual
) does not match a RegExp (second input,
expected
). Returns the string if the check passes, otherwise undefined
.
Performs no type guarding.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.mismatches('hi', /^h/); // returns `undefined`
checkWrap.mismatches('hi', /^g/); // returns `'hi'`
Checks that two values are not deeply equal using the deep-eql package. Returns the first value if the check 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.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.deepEquals('a', 'a'); // false
checkWrap.deepEquals('1', 1); // true
checkWrap.deepEquals({a: 'a'}, {a: 'a'}); // false
const objectExample = {a: 'a'};
checkWrap.deepEquals(objectExample, objectExample); // false
Checks that two objects are not deeply equal by checking only their top-level values
for strict (non-deep, reference, using
===
)
equality. If the check passes the first object is returned. If not, undefined
is
returned.
Performs no type guarding.
The first input if the assertion passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // returns `undefined`
checkWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`
const bExample = {b: 'b'};
checkWrap.notEntriesEqual({a: bExample}, {a: bExample}); // returns `undefined`
Checks that a value is not an instance of the given class constructor. Returns the
value if the check passes, otherwise undefined
.
Type guards the value.
The value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.notInstanceOf(/abc/, RegExp); // returns `undefined`
checkWrap.notInstanceOf('abc', RegExp); // returns `'abc'`
Checks 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 check passes.
Performs no type guarding.
import {checkWrap} from '@augment-vir/assert';
checkWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // false
checkWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // true
Checks that two values are not loosely equal (using
==
).
Returns the first value if the check passes, otherwise undefined
.
Performs no type guarding.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.notLooseEquals('a', 'a'); // returns `undefined`
checkWrap.notLooseEquals('1', 1); // returns `undefined`
checkWrap.notLooseEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
const objectExample = {a: 'a'};
checkWrap.notLooseEquals(objectExample, objectExample); // returns `undefined`
Checks that two values are not strictly equal (using
===
).
Returns the first value if the check passes, otherwise undefined
.
Performs no type guarding.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.notStrictEquals('a', 'a'); // returns `undefined`
checkWrap.notStrictEquals('1', 1); // returns `'1'`
checkWrap.notStrictEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
const objectExample = {a: 'a'};
checkWrap.notStrictEquals(objectExample, objectExample); // returns `undefined`
Checks that two values are strictly equal (using
===
).
Returns the first value if the check passes, otherwise undefined
.
Type guards the first value.
The first value if the check passes, otherwise undefined
.
import {checkWrap} from '@augment-vir/assert';
checkWrap.strictEquals('a', 'a'); // returns `'a'`
checkWrap.strictEquals('1', 1); // returns `undefined`
checkWrap.strictEquals({a: 'a'}, {a: 'a'}); // returns `undefined`
const objectExample = {a: 'a'};
checkWrap.strictEquals(objectExample, objectExample); // returns `{a: 'a'}`
A group of guard methods that do the following:
undefined
.This can also be called as a standalone check function which checks that its input is truthy and returns it if so, else
undefined
.Example
Package
@augment-vir/assert