@brillout/json-serializer 0.5.18 → 0.5.19
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/parse.js +2 -2
- package/dist/cjs/stringify.d.ts +1 -1
- package/dist/cjs/stringify.js +11 -11
- package/dist/esm/parse.js +1 -1
- package/dist/esm/stringify.d.ts +1 -1
- package/dist/esm/stringify.js +5 -5
- package/package.json +2 -1
package/dist/cjs/parse.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
4
|
exports.parseTransform = parseTransform;
|
|
5
|
-
const
|
|
5
|
+
const types_js_1 = require("./types.js");
|
|
6
6
|
function parse(str, options = {}) {
|
|
7
7
|
// We don't use the reviver option in `JSON.parse(str, reviver)` because it doesn't support `undefined` values
|
|
8
8
|
const value = JSON.parse(str);
|
|
@@ -41,7 +41,7 @@ function reviver(value, options) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
for (const { match, deserialize } of
|
|
44
|
+
for (const { match, deserialize } of types_js_1.types) {
|
|
45
45
|
if (match(value)) {
|
|
46
46
|
return deserialize(value, parser);
|
|
47
47
|
}
|
package/dist/cjs/stringify.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { stringify };
|
|
2
2
|
export { isJsonSerializerError };
|
|
3
|
-
import { type Iterable, type Path } from './utils/replacerWithPath';
|
|
3
|
+
import { type Iterable, type Path } from './utils/replacerWithPath.js';
|
|
4
4
|
declare function stringify(value: unknown, { forbidReactElements, space, valueName, sortObjectKeys, replacer: replacerUserProvided, }?: {
|
|
5
5
|
forbidReactElements?: boolean;
|
|
6
6
|
space?: number;
|
package/dist/cjs/stringify.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringify = stringify;
|
|
4
4
|
exports.isJsonSerializerError = isJsonSerializerError;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
5
|
+
const types_js_1 = require("./types.js");
|
|
6
|
+
const isReactElement_js_1 = require("./utils/isReactElement.js");
|
|
7
|
+
const isCallable_js_1 = require("./utils/isCallable.js");
|
|
8
|
+
const isObject_js_1 = require("./utils/isObject.js");
|
|
9
|
+
const replacerWithPath_js_1 = require("./utils/replacerWithPath.js");
|
|
10
10
|
function stringify(value, { forbidReactElements, space, valueName, sortObjectKeys, replacer: replacerUserProvided, } = {}) {
|
|
11
11
|
// The only error `JSON.stringify()` can throw is `TypeError "cyclic object value"`.
|
|
12
12
|
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#exceptions
|
|
@@ -14,7 +14,7 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
14
14
|
// - Cyclic references
|
|
15
15
|
// - Functions
|
|
16
16
|
// - React elements
|
|
17
|
-
const serializer = (val) => JSON.stringify(val, (0,
|
|
17
|
+
const serializer = (val) => JSON.stringify(val, (0, replacerWithPath_js_1.replacerWithPath)(replacer), space);
|
|
18
18
|
return serializer(value);
|
|
19
19
|
function replacer(key, valueAfterJSON, path) {
|
|
20
20
|
const valueOriginal = this[key];
|
|
@@ -27,7 +27,7 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
27
27
|
return value;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
if (forbidReactElements && (0,
|
|
30
|
+
if (forbidReactElements && (0, isReactElement_js_1.isReactElement)(value)) {
|
|
31
31
|
throw genErr({
|
|
32
32
|
value,
|
|
33
33
|
valueType: 'React element',
|
|
@@ -35,7 +35,7 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
35
35
|
rootValueName: valueName,
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
if ((0,
|
|
38
|
+
if ((0, isCallable_js_1.isCallable)(value)) {
|
|
39
39
|
const functionName = value.name;
|
|
40
40
|
throw genErr({
|
|
41
41
|
value,
|
|
@@ -45,13 +45,13 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
45
45
|
problematicValueName: path.length === 0 ? functionName : undefined,
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
for (const { is, serialize } of
|
|
48
|
+
for (const { is, serialize } of types_js_1.types.slice().reverse()) {
|
|
49
49
|
if (is(value)) {
|
|
50
50
|
//@ts-ignore
|
|
51
51
|
return serialize(value, serializer);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
if (sortObjectKeys && (0,
|
|
54
|
+
if (sortObjectKeys && (0, isObject_js_1.isObject)(value)) {
|
|
55
55
|
const copy = {};
|
|
56
56
|
Object.keys(value)
|
|
57
57
|
.sort()
|
|
@@ -81,7 +81,7 @@ function genErr({ value, valueType, path, rootValueName, problematicValueName, }
|
|
|
81
81
|
}
|
|
82
82
|
const stamp = '_isJsonSerializerError';
|
|
83
83
|
function isJsonSerializerError(thing) {
|
|
84
|
-
return (0,
|
|
84
|
+
return (0, isObject_js_1.isObject)(thing) && thing[stamp] === true;
|
|
85
85
|
}
|
|
86
86
|
function getSubjectName({ path, rootValueName, problematicValueName, }) {
|
|
87
87
|
const pathString = getPathString(path, !rootValueName);
|
package/dist/esm/parse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { parse };
|
|
2
2
|
// Used by Vike: https://github.com/vikejs/vike/blob/b4ba6b70e6bdc2e1f460c0d2e4c3faae5d0a733c/vike/shared/page-configs/serialize/parseConfigValuesSerialized.ts#L13
|
|
3
3
|
export { parseTransform };
|
|
4
|
-
import { types } from './types';
|
|
4
|
+
import { types } from './types.js';
|
|
5
5
|
function parse(str, options = {}) {
|
|
6
6
|
// We don't use the reviver option in `JSON.parse(str, reviver)` because it doesn't support `undefined` values
|
|
7
7
|
const value = JSON.parse(str);
|
package/dist/esm/stringify.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { stringify };
|
|
2
2
|
export { isJsonSerializerError };
|
|
3
|
-
import { type Iterable, type Path } from './utils/replacerWithPath';
|
|
3
|
+
import { type Iterable, type Path } from './utils/replacerWithPath.js';
|
|
4
4
|
declare function stringify(value: unknown, { forbidReactElements, space, valueName, sortObjectKeys, replacer: replacerUserProvided, }?: {
|
|
5
5
|
forbidReactElements?: boolean;
|
|
6
6
|
space?: number;
|
package/dist/esm/stringify.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { stringify };
|
|
2
2
|
export { isJsonSerializerError };
|
|
3
|
-
import { types } from './types';
|
|
4
|
-
import { isReactElement } from './utils/isReactElement';
|
|
5
|
-
import { isCallable } from './utils/isCallable';
|
|
6
|
-
import { isObject } from './utils/isObject';
|
|
7
|
-
import { replacerWithPath } from './utils/replacerWithPath';
|
|
3
|
+
import { types } from './types.js';
|
|
4
|
+
import { isReactElement } from './utils/isReactElement.js';
|
|
5
|
+
import { isCallable } from './utils/isCallable.js';
|
|
6
|
+
import { isObject } from './utils/isObject.js';
|
|
7
|
+
import { replacerWithPath } from './utils/replacerWithPath.js';
|
|
8
8
|
function stringify(value, { forbidReactElements, space, valueName, sortObjectKeys, replacer: replacerUserProvided, } = {}) {
|
|
9
9
|
// The only error `JSON.stringify()` can throw is `TypeError "cyclic object value"`.
|
|
10
10
|
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#exceptions
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/json-serializer",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.19",
|
|
4
4
|
"description": "Same as JSON but with added support for `Date`, `undefined`, `Map`, `Set`, and more.",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": "./index.mjs",
|
|
8
9
|
"./parse": {
|