assertcheck / ObjectChecker
Class: ObjectChecker<T>
Defined in: src/checker.ts:276
Chainable assertion wrapper for plain objects. Returned by check when the value is a plain object.
Remarks
Key assertions like hasKey and hasKeys narrow the type of the wrapped value, propagating the narrowing through the chain.
Example
check(config)
.hasKeys(["host", "port"])
.noNilValues()
.dig("database.pool.max", 10)Extends
Checker<T>
Type Parameters
| Type Parameter | Description |
|---|---|
T extends object | The type of the wrapped object. |
Constructors
Constructor
new ObjectChecker<T>(value): ObjectChecker<T>;Defined in: src/checker.ts:52
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
ObjectChecker<T>
Inherited from
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
value | readonly | T | Checker.value | src/checker.ts:52 |
Methods
allValuesMatch()
allValuesMatch(predicate, opts?): this;Defined in: src/checker.ts:318
Parameters
| Parameter | Type |
|---|---|
predicate | (v, k) => boolean |
opts? | Opts |
Returns
this
See
containsSubset()
containsSubset(subset, opts?): this;Defined in: src/checker.ts:308
Parameters
| Parameter | Type |
|---|---|
subset | Partial<T> |
opts? | Opts |
Returns
this
See
deepEqual()
deepEqual(expected, opts?): this;Defined in: src/checker.ts:303
Parameters
| Parameter | Type |
|---|---|
expected | T |
opts? | Opts |
Returns
this
See
dig()
dig(
path,
expected,
opts?): this;Defined in: src/checker.ts:323
Parameters
| Parameter | Type |
|---|---|
path | string | string[] |
expected | unknown |
opts? | Opts |
Returns
this
See
hasExactKeys()
hasExactKeys<K>(keys, opts?): ObjectChecker<Record<K, unknown>>;Defined in: src/checker.ts:293
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
keys | K[] |
opts? | Opts |
Returns
ObjectChecker<Record<K, unknown>>
See
hasKey()
hasKey<K>(key, opts?): ObjectChecker<T & Record<K, unknown>>;Defined in: src/checker.ts:283
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
key | K |
opts? | Opts |
Returns
ObjectChecker<T & Record<K, unknown>>
See
hasKeys()
hasKeys<K>(keys, opts?): ObjectChecker<T & Record<K, unknown>>;Defined in: src/checker.ts:288
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
keys | K[] |
opts? | Opts |
Returns
ObjectChecker<T & Record<K, unknown>>
See
hasOnlyKeys()
hasOnlyKeys(allowed, opts?): this;Defined in: src/checker.ts:298
Parameters
| Parameter | Type |
|---|---|
allowed | string[] |
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
noNilValues()
noNilValues(opts?): this;Defined in: src/checker.ts:313
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
notEmpty()
notEmpty(opts?): this;Defined in: src/checker.ts:278
Parameters
| Parameter | Type |
|---|---|
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
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")