@augment-vir/common 12.7.0 → 12.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/augments/json.d.ts +6 -0
- package/dist/cjs/augments/json.js +25 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/augments/json.d.ts +6 -0
- package/dist/esm/augments/json.js +21 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/types/augments/json.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJson = void 0;
|
|
4
|
+
const matches_object_shape_1 = require("./object/matches-object-shape");
|
|
5
|
+
const runtime_type_of_1 = require("./runtime-type-of");
|
|
6
|
+
function parseJson({ jsonString, errorHandler, shapeMatcher, }) {
|
|
7
|
+
try {
|
|
8
|
+
const parsedJson = JSON.parse(jsonString);
|
|
9
|
+
if (shapeMatcher != undefined) {
|
|
10
|
+
if ((0, runtime_type_of_1.isRuntimeTypeOf)(shapeMatcher, 'object')) {
|
|
11
|
+
(0, matches_object_shape_1.assertMatchesObjectShape)(parsedJson, shapeMatcher);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
(0, runtime_type_of_1.assertRuntimeTypeOf)(parsedJson, (0, runtime_type_of_1.getRuntimeTypeOf)(shapeMatcher), 'parsedJson');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return parsedJson;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(error);
|
|
21
|
+
// if the above error handler doesn't halt execution then this will
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.parseJson = parseJson;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './augments/date';
|
|
|
7
7
|
export * from './augments/environment';
|
|
8
8
|
export * from './augments/error';
|
|
9
9
|
export * from './augments/function';
|
|
10
|
+
export * from './augments/json';
|
|
10
11
|
export * from './augments/json-compatible';
|
|
11
12
|
export * from './augments/object/enum';
|
|
12
13
|
export * from './augments/object/filter-object';
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./augments/date"), exports);
|
|
|
23
23
|
__exportStar(require("./augments/environment"), exports);
|
|
24
24
|
__exportStar(require("./augments/error"), exports);
|
|
25
25
|
__exportStar(require("./augments/function"), exports);
|
|
26
|
+
__exportStar(require("./augments/json"), exports);
|
|
26
27
|
__exportStar(require("./augments/json-compatible"), exports);
|
|
27
28
|
__exportStar(require("./augments/object/enum"), exports);
|
|
28
29
|
__exportStar(require("./augments/object/filter-object"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assertMatchesObjectShape } from './object/matches-object-shape';
|
|
2
|
+
import { assertRuntimeTypeOf, getRuntimeTypeOf, isRuntimeTypeOf } from './runtime-type-of';
|
|
3
|
+
export function parseJson({ jsonString, errorHandler, shapeMatcher, }) {
|
|
4
|
+
try {
|
|
5
|
+
const parsedJson = JSON.parse(jsonString);
|
|
6
|
+
if (shapeMatcher != undefined) {
|
|
7
|
+
if (isRuntimeTypeOf(shapeMatcher, 'object')) {
|
|
8
|
+
assertMatchesObjectShape(parsedJson, shapeMatcher);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
assertRuntimeTypeOf(parsedJson, getRuntimeTypeOf(shapeMatcher), 'parsedJson');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return parsedJson;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(error);
|
|
18
|
+
// if the above error handler doesn't halt execution then this will
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './augments/date';
|
|
|
7
7
|
export * from './augments/environment';
|
|
8
8
|
export * from './augments/error';
|
|
9
9
|
export * from './augments/function';
|
|
10
|
+
export * from './augments/json';
|
|
10
11
|
export * from './augments/json-compatible';
|
|
11
12
|
export * from './augments/object/enum';
|
|
12
13
|
export * from './augments/object/filter-object';
|
package/dist/esm/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './augments/date';
|
|
|
7
7
|
export * from './augments/environment';
|
|
8
8
|
export * from './augments/error';
|
|
9
9
|
export * from './augments/function';
|
|
10
|
+
export * from './augments/json';
|
|
10
11
|
export * from './augments/json-compatible';
|
|
11
12
|
export * from './augments/object/enum';
|
|
12
13
|
export * from './augments/object/filter-object';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './augments/date';
|
|
|
7
7
|
export * from './augments/environment';
|
|
8
8
|
export * from './augments/error';
|
|
9
9
|
export * from './augments/function';
|
|
10
|
+
export * from './augments/json';
|
|
10
11
|
export * from './augments/json-compatible';
|
|
11
12
|
export * from './augments/object/enum';
|
|
12
13
|
export * from './augments/object/filter-object';
|