assertcheck / ArrayChecker
Class: ArrayChecker<T>
Defined in: src/checker.ts:104
Chainable assertion wrapper for arrays. Returned by check when the value is an array.
Example
check(users)
.len(5)
.uniqueBy("id")
.all(u => u.verified)
.sortedBy("name")Extends
Checker<T[]>
Type Parameters
| Type Parameter | Description |
|---|---|
T | The element type of the wrapped array. |
Constructors
Constructor
new ArrayChecker<T>(value): ArrayChecker<T>;Defined in: src/checker.ts:52
Parameters
| Parameter | Type |
|---|---|
value | T[] |
Returns
ArrayChecker<T>
Inherited from
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
value | readonly | T[] | Checker.value | src/checker.ts:52 |
Methods
all()
all(predicate, opts?): this;Defined in: src/checker.ts:131
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
opts? | Opts |
Returns
this
See
allInstanceOf()
allInstanceOf<U, TArgs>(ctor, opts?): ArrayChecker<U>;Defined in: src/checker.ts:231
Type Parameters
| Type Parameter |
|---|
U |
TArgs extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
ctor | (...args) => U |
opts? | Opts |
Returns
ArrayChecker<U>
See
any()
any(predicate, opts?): this;Defined in: src/checker.ts:136
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
opts? | Opts |
Returns
this
See
containsAll()
containsAll(items, opts?): this;Defined in: src/checker.ts:191
Parameters
| Parameter | Type |
|---|---|
items | T[] |
opts? | Opts |
Returns
this
See
containsNone()
containsNone(items, opts?): this;Defined in: src/checker.ts:196
Parameters
| Parameter | Type |
|---|---|
items | T[] |
opts? | Opts |
Returns
this
See
count()
count(
predicate,
n,
opts?): this;Defined in: src/checker.ts:211
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
n | number |
opts? | Opts |
Returns
this
See
elementsMatch()
elementsMatch(expected, opts?): this;Defined in: src/checker.ts:186
Parameters
| Parameter | Type |
|---|---|
expected | T[] |
opts? | Opts |
Returns
this
See
first()
first(expected, opts?): this;Defined in: src/checker.ts:171
Parameters
| Parameter | Type |
|---|---|
expected | T |
opts? | Opts |
Returns
this
See
flat()
flat(opts?): this;Defined in: src/checker.ts:201
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
groupedBy()
groupedBy(
iteratee,
expectedGroups,
opts?): this;Defined in: src/checker.ts:206
Parameters
| Parameter | Type |
|---|---|
iteratee | ValueIteratee<T> |
expectedGroups | string[] |
opts? | Opts |
Returns
this
See
includes()
includes(item, opts?): this;Defined in: src/checker.ts:126
Parameters
| Parameter | Type |
|---|---|
item | T |
opts? | Opts |
Returns
this
See
increasing()
increasing(this, opts?): ArrayChecker<number>;Defined in: src/checker.ts:216
Parameters
| Parameter | Type |
|---|---|
this | ArrayChecker<number> |
opts? | Opts |
Returns
ArrayChecker<number>
See
last()
last(expected, opts?): this;Defined in: src/checker.ts:176
Parameters
| Parameter | Type |
|---|---|
expected | T |
opts? | Opts |
Returns
this
See
len()
len(n, opts?): this;Defined in: src/checker.ts:111
Parameters
| Parameter | Type |
|---|---|
n | number |
opts? | Opts |
Returns
this
See
longerThan()
longerThan(n, opts?): this;Defined in: src/checker.ts:116
Parameters
| Parameter | Type |
|---|---|
n | number |
opts? | Opts |
Returns
this
See
narrow()
protected narrow<U, A>(fn, ...args): U;Defined in: src/checker.ts:80
Same as run, but re-types the checker after a narrowing assertion.
Type Parameters
| Type Parameter |
|---|
U |
A extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
fn | (v, ...args) => void |
...args | A |
Returns
U
Inherited from
nonDecreasing()
nonDecreasing(this, opts?): ArrayChecker<number>;Defined in: src/checker.ts:221
Parameters
| Parameter | Type |
|---|---|
this | ArrayChecker<number> |
opts? | Opts |
Returns
ArrayChecker<number>
See
none()
none(predicate, opts?): this;Defined in: src/checker.ts:141
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
opts? | Opts |
Returns
this
See
noNils()
noNils(opts?): ArrayChecker<NonNullable<T>>;Defined in: src/checker.ts:161
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
ArrayChecker<NonNullable<T>>
See
notEmpty()
notEmpty(opts?): this;Defined in: src/checker.ts:106
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
one()
one(predicate, opts?): this;Defined in: src/checker.ts:146
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
opts? | Opts |
Returns
this
See
partition()
partition(
predicate,
expectedMatch,
expectedRest,
opts?): this;Defined in: src/checker.ts:244
Parameters
| Parameter | Type |
|---|---|
predicate | (v) => boolean |
expectedMatch | number |
expectedRest | number |
opts? | Opts |
Returns
this
See
run()
protected run<A>(fn, ...args): this;Defined in: src/checker.ts:74
Applies an assert.* function to the wrapped value, then returns this for chaining.
Type Parameters
| Type Parameter |
|---|
A extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
fn | (v, ...args) => void |
...args | A |
Returns
this
Inherited from
shorterThan()
shorterThan(n, opts?): this;Defined in: src/checker.ts:121
Parameters
| Parameter | Type |
|---|---|
n | number |
opts? | Opts |
Returns
this
See
sortedBy()
sortedBy(iteratee, opts?): this;Defined in: src/checker.ts:166
Parameters
| Parameter | Type |
|---|---|
iteratee | ValueIteratee<T> |
opts? | Opts |
Returns
this
See
subset()
subset(sub, opts?): this;Defined in: src/checker.ts:181
Parameters
| Parameter | Type |
|---|---|
sub | T[] |
opts? | Opts |
Returns
this
See
sumBy()
sumBy(
iteratee,
expected,
opts?): this;Defined in: src/checker.ts:226
Parameters
| Parameter | Type |
|---|---|
iteratee | string | ((value) => number) |
expected | number |
opts? | Opts |
Returns
this
See
tap()
tap(fn): this;Defined in: src/checker.ts:68
Runs a side-effect function with the wrapped value and returns this to allow chaining. Useful for logging or debugging mid-chain.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | (v) => void | A function that receives the wrapped value. |
Returns
this
The current checker instance for chaining.
Example
check(orders)
.tap(v => console.log("orders:", v))
.all(o => o.status === "paid")Inherited from
unique()
unique(opts?): this;Defined in: src/checker.ts:151
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
uniqueBy()
uniqueBy(iteratee, opts?): this;Defined in: src/checker.ts:156
Parameters
| Parameter | Type |
|---|---|
iteratee | ValueIteratee<T> |
opts? | Opts |
Returns
this
See
zippedWith()
zippedWith<B>(
other,
predicate,
opts?): this;Defined in: src/checker.ts:239
Type Parameters
| Type Parameter |
|---|
B |
Parameters
| Parameter | Type |
|---|---|
other | B[] |
predicate | (a, b) => boolean |
opts? | Opts |
Returns
this