Skip to content

assertcheck v0.5.15


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

ts
check(config)
  .hasKeys(["host", "port"])
  .noNilValues()
  .dig("database.pool.max", 10)

Extends

Type Parameters

Type ParameterDescription
T extends objectThe type of the wrapped object.

Constructors

Constructor

ts
new ObjectChecker<T>(value): ObjectChecker<T>;

Defined in: src/checker.ts:59

Parameters

ParameterType
valueT

Returns

ObjectChecker<T>

Inherited from

Checker.constructor

Properties

PropertyModifierTypeInherited fromDefined in
valuereadonlyTChecker.valuesrc/checker.ts:59

Methods

allValuesMatch()

ts
allValuesMatch(predicate, opts?): this;

Defined in: src/checker.ts:350

Parameters

ParameterType
predicate(v, k) => boolean
opts?Opts

Returns

this

See

assert.allValuesMatch


containsSubset()

ts
containsSubset(subset, opts?): this;

Defined in: src/checker.ts:338

Parameters

ParameterType
subsetPartial<T>
opts?Opts

Returns

this

See

assert.containsSubset


deepEqual()

ts
deepEqual(expected, opts?): this;

Defined in: src/checker.ts:332

Parameters

ParameterType
expectedT
opts?Opts

Returns

this

See

assert.deepEqual


dig()

ts
dig(
   path, 
   expected, 
   opts?): this;

Defined in: src/checker.ts:356

Parameters

ParameterType
pathstring | string[]
expectedunknown
opts?Opts

Returns

this

See

assert.dig


hasExactKeys()

ts
hasExactKeys<K>(keys, opts?): ObjectChecker<Record<K, unknown>>;

Defined in: src/checker.ts:320

Type Parameters

Type Parameter
K extends string

Parameters

ParameterType
keysK[]
opts?Opts

Returns

ObjectChecker<Record<K, unknown>>

See

assert.hasExactKeys


hasKey()

ts
hasKey<K>(key, opts?): ObjectChecker<T & Record<K, unknown>>;

Defined in: src/checker.ts:308

Type Parameters

Type Parameter
K extends string

Parameters

ParameterType
keyK
opts?Opts

Returns

ObjectChecker<T & Record<K, unknown>>

See

assert.hasKey


hasKeys()

ts
hasKeys<K>(keys, opts?): ObjectChecker<T & Record<K, unknown>>;

Defined in: src/checker.ts:314

Type Parameters

Type Parameter
K extends string

Parameters

ParameterType
keysK[]
opts?Opts

Returns

ObjectChecker<T & Record<K, unknown>>

See

assert.hasKeys


hasOnlyKeys()

ts
hasOnlyKeys(allowed, opts?): this;

Defined in: src/checker.ts:326

Parameters

ParameterType
allowedstring[]
opts?Opts

Returns

this

See

assert.hasOnlyKeys


noNilValues()

ts
noNilValues(opts?): this;

Defined in: src/checker.ts:344

Parameters

ParameterType
opts?Opts

Returns

this

See

assert.noNilValues


notEmpty()

ts
notEmpty(opts?): this;

Defined in: src/checker.ts:302

Parameters

ParameterType
opts?Opts

Returns

this

See

assert.notEmpty


tap()

ts
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

ParameterTypeDescription
fn(v) => voidA function that receives the wrapped value.

Returns

this

The current checker instance for chaining.

Example

ts
check(orders)
  .tap(v => console.log("orders:", v))
  .all(o => o.status === "paid")

Inherited from

Checker.tap

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.