assertcheck / ObjectChecker
Class: ObjectChecker<T>
Defined in: src/checker.ts:300
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:59
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:59 |
Methods
allValuesMatch()
allValuesMatch(predicate, opts?): this;Defined in: src/checker.ts:350
Parameters
| Parameter | Type |
|---|---|
predicate | (v, k) => boolean |
opts? | Opts |
Returns
this
See
containsSubset()
containsSubset(subset, opts?): this;Defined in: src/checker.ts:338
Parameters
| Parameter | Type |
|---|---|
subset | Partial<T> |
opts? | Opts |
Returns
this
See
deepEqual()
deepEqual(expected, opts?): this;Defined in: src/checker.ts:332
Parameters
| Parameter | Type |
|---|---|
expected | T |
opts? | Opts |
Returns
this
See
dig()
dig(
path,
expected,
opts?): this;Defined in: src/checker.ts:356
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:320
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:308
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:314
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:326
Parameters
| Parameter | Type |
|---|---|
allowed | string[] |
opts? | Opts |
Returns
this
See
noNilValues()
noNilValues(opts?): this;Defined in: src/checker.ts:344
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
notEmpty()
notEmpty(opts?): this;Defined in: src/checker.ts:302
Parameters
| Parameter | Type |
|---|---|
opts? | Opts |
Returns
this
See
tap()
tap(fn): this;Defined in: src/checker.ts:75
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")