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