object-shape-tester
Version:
Test object properties and value types.
20 lines (19 loc) • 868 B
TypeScript
import { type PartialWithUndefined } from '@augment-vir/common';
import { type ShapeDefinition } from './define-shape/shape-specifiers.js';
import { type CheckShapeValidityOptions } from './verify-shape/verify-shape.js';
/**
* Parse a JSON string and verify it against the given shape definition.
*
* @category Main
* @example
*
* ```ts
* import {parseJsonWithShape, defineShape} from 'object-shape-tester';
*
* const result = parseJsonWithShape('{"a": "hello"}', defineShape({a: ''}));
* ```
*
* @throws If the parsed JSON does not match the shape definition or if the JSON parsing throws an
* error.
*/
export declare function parseJsonWithShape<const Shape extends ShapeDefinition<any, any>>(json: string, shape: Readonly<Shape>, options?: PartialWithUndefined<CheckShapeValidityOptions>, failureMessage?: string | undefined): Shape['runtimeType'];