UNPKG

object-shape-tester

Version:
18 lines (17 loc) 626 B
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'];