@augment-vir/common
Advanced tools
Comparing version 27.0.0 to 28.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringifyJson = exports.parseJson = void 0; | ||
const run_time_assertions_1 = require("run-time-assertions"); | ||
const matches_object_shape_1 = require("./object/matches-object-shape"); | ||
const wrap_in_try_1 = require("./wrap-in-try"); | ||
function parseJson({ jsonString, errorHandler, shapeMatcher, }) { | ||
function parseJson({ jsonString, errorHandler, }) { | ||
try { | ||
const parsedJson = JSON.parse(jsonString); | ||
if (shapeMatcher != undefined) { | ||
if ((0, run_time_assertions_1.isRunTimeType)(shapeMatcher, 'object')) { | ||
(0, matches_object_shape_1.assertMatchesObjectShape)(parsedJson, shapeMatcher); | ||
} | ||
else { | ||
(0, run_time_assertions_1.assertRunTimeType)(parsedJson, (0, run_time_assertions_1.getRunTimeType)(shapeMatcher), 'parsedJson'); | ||
} | ||
} | ||
return parsedJson; | ||
@@ -19,0 +9,0 @@ } |
@@ -38,4 +38,4 @@ "use strict"; | ||
__exportStar(require("./augments/object/map-object"), exports); | ||
__exportStar(require("./augments/object/matches-object-shape"), exports); | ||
__exportStar(require("./augments/object/merge-deep"), exports); | ||
__exportStar(require("./augments/object/merge-property-arrays"), exports); | ||
__exportStar(require("./augments/object/nested-keys"), exports); | ||
@@ -42,0 +42,0 @@ __exportStar(require("./augments/object/object"), exports); |
@@ -1,15 +0,5 @@ | ||
import { assertRunTimeType, getRunTimeType, isRunTimeType } from 'run-time-assertions'; | ||
import { assertMatchesObjectShape } from './object/matches-object-shape'; | ||
import { wrapInTry } from './wrap-in-try'; | ||
export function parseJson({ jsonString, errorHandler, shapeMatcher, }) { | ||
export function parseJson({ jsonString, errorHandler, }) { | ||
try { | ||
const parsedJson = JSON.parse(jsonString); | ||
if (shapeMatcher != undefined) { | ||
if (isRunTimeType(shapeMatcher, 'object')) { | ||
assertMatchesObjectShape(parsedJson, shapeMatcher); | ||
} | ||
else { | ||
assertRunTimeType(parsedJson, getRunTimeType(shapeMatcher), 'parsedJson'); | ||
} | ||
} | ||
return parsedJson; | ||
@@ -16,0 +6,0 @@ } |
@@ -22,4 +22,4 @@ export * from './augments/ansi'; | ||
export * from './augments/object/map-object'; | ||
export * from './augments/object/matches-object-shape'; | ||
export * from './augments/object/merge-deep'; | ||
export * from './augments/object/merge-property-arrays'; | ||
export * from './augments/object/nested-keys'; | ||
@@ -26,0 +26,0 @@ export * from './augments/object/object'; |
import { JsonCompatibleValue } from './json-compatible'; | ||
import { WrapInTryOptions } from './wrap-in-try'; | ||
export declare function parseJson<ParsedJsonGeneric>({ jsonString, errorHandler, shapeMatcher, }: { | ||
export declare function parseJson<ParsedJsonGeneric>({ jsonString, errorHandler, }: { | ||
jsonString: string; | ||
errorHandler?: (error: unknown) => never | ParsedJsonGeneric; | ||
shapeMatcher?: ParsedJsonGeneric; | ||
}): ParsedJsonGeneric; | ||
@@ -8,0 +7,0 @@ export declare function stringifyJson(jsonValue: JsonCompatibleValue, { whitespace, ...tryOptions }?: { |
@@ -22,4 +22,4 @@ export * from './augments/ansi'; | ||
export * from './augments/object/map-object'; | ||
export * from './augments/object/matches-object-shape'; | ||
export * from './augments/object/merge-deep'; | ||
export * from './augments/object/merge-property-arrays'; | ||
export * from './augments/object/nested-keys'; | ||
@@ -26,0 +26,0 @@ export * from './augments/object/object'; |
{ | ||
"name": "@augment-vir/common", | ||
"version": "27.0.0", | ||
"version": "28.0.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -5,0 +5,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164734
4041