parseObject
Parses a value into a non-null, non-array object. This parser uses the validateObject structural validator to ensure that the input is an object whose typeof is "object", excluding null and arrays.
The parser never throws and never mutates input. It returns a structured ParseResult<object> describing success or failure.
Signature
function parseObject(
value: unknown,
field?: string
): ParseResult<object>
Behavior
- Accepts:
- Plain objects.
- Objects with a
nullprototype. - Class instances.
- Objects with the
anyprototype. - Rejects:
- Arrays.
- Functions.
- Primitives.
nullandundefined.- Never mutates input.
- Never throws.
Returns
ok: true: And the original object when parsing succeeds.ok: false, value: null: And a list of issues when parsing fails.
Examples
parseObject({ a: 1 })
// { ok: true, value: { a: 1 }, issues: [] }
parseObject(null)
// { ok: false, value: null, issues: ["Value must be an object"] }
Notes
- This parser is intentionally broad. For stricter object parsing, use:
- parsePlainObject
- parseRecord
- parseNonEmptyRecord