object-shape-tester
Version:
Test object properties and value types.
18 lines (17 loc) • 626 B
TypeScript
import { type ShapeDefinition } from './define-shape/shape-specifiers.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>): Shape['runtimeType'];