@brillout/json-serializer 0.5.16 → 0.5.18
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/stringify.d.ts +1 -0
- package/dist/cjs/stringify.js +11 -7
- package/dist/esm/stringify.d.ts +1 -0
- package/dist/esm/stringify.js +11 -7
- package/package.json +5 -3
package/dist/cjs/stringify.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare function stringify(value: unknown, { forbidReactElements, space, valueNa
|
|
|
8
8
|
sortObjectKeys?: boolean;
|
|
9
9
|
replacer?: (this: Iterable, key: string, value: unknown, serializer: (value: unknown) => string) => {
|
|
10
10
|
replacement: unknown;
|
|
11
|
+
resolved?: boolean;
|
|
11
12
|
} | undefined;
|
|
12
13
|
}): string;
|
|
13
14
|
type ErrAddendum = {
|
package/dist/cjs/stringify.js
CHANGED
|
@@ -16,11 +16,16 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
16
16
|
// - React elements
|
|
17
17
|
const serializer = (val) => JSON.stringify(val, (0, replacerWithPath_1.replacerWithPath)(replacer), space);
|
|
18
18
|
return serializer(value);
|
|
19
|
-
function replacer(key,
|
|
19
|
+
function replacer(key, valueAfterJSON, path) {
|
|
20
|
+
const valueOriginal = this[key];
|
|
21
|
+
let value = valueOriginal;
|
|
20
22
|
{
|
|
21
|
-
const ret = replacerUserProvided === null || replacerUserProvided === void 0 ? void 0 : replacerUserProvided.call(this, key,
|
|
22
|
-
if (ret)
|
|
23
|
-
|
|
23
|
+
const ret = replacerUserProvided === null || replacerUserProvided === void 0 ? void 0 : replacerUserProvided.call(this, key, valueAfterJSON, serializer);
|
|
24
|
+
if (ret) {
|
|
25
|
+
value = ret.replacement;
|
|
26
|
+
if (ret.resolved !== false)
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
if (forbidReactElements && (0, isReactElement_1.isReactElement)(value)) {
|
|
26
31
|
throw genErr({
|
|
@@ -40,11 +45,10 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
40
45
|
problematicValueName: path.length === 0 ? functionName : undefined,
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
|
-
const valueOriginal = this[key];
|
|
44
48
|
for (const { is, serialize } of types_1.types.slice().reverse()) {
|
|
45
|
-
if (is(
|
|
49
|
+
if (is(value)) {
|
|
46
50
|
//@ts-ignore
|
|
47
|
-
return serialize(
|
|
51
|
+
return serialize(value, serializer);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
if (sortObjectKeys && (0, isObject_1.isObject)(value)) {
|
package/dist/esm/stringify.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare function stringify(value: unknown, { forbidReactElements, space, valueNa
|
|
|
8
8
|
sortObjectKeys?: boolean;
|
|
9
9
|
replacer?: (this: Iterable, key: string, value: unknown, serializer: (value: unknown) => string) => {
|
|
10
10
|
replacement: unknown;
|
|
11
|
+
resolved?: boolean;
|
|
11
12
|
} | undefined;
|
|
12
13
|
}): string;
|
|
13
14
|
type ErrAddendum = {
|
package/dist/esm/stringify.js
CHANGED
|
@@ -14,11 +14,16 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
14
14
|
// - React elements
|
|
15
15
|
const serializer = (val) => JSON.stringify(val, replacerWithPath(replacer), space);
|
|
16
16
|
return serializer(value);
|
|
17
|
-
function replacer(key,
|
|
17
|
+
function replacer(key, valueAfterJSON, path) {
|
|
18
|
+
const valueOriginal = this[key];
|
|
19
|
+
let value = valueOriginal;
|
|
18
20
|
{
|
|
19
|
-
const ret = replacerUserProvided?.call(this, key,
|
|
20
|
-
if (ret)
|
|
21
|
-
|
|
21
|
+
const ret = replacerUserProvided?.call(this, key, valueAfterJSON, serializer);
|
|
22
|
+
if (ret) {
|
|
23
|
+
value = ret.replacement;
|
|
24
|
+
if (ret.resolved !== false)
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
if (forbidReactElements && isReactElement(value)) {
|
|
24
29
|
throw genErr({
|
|
@@ -38,11 +43,10 @@ function stringify(value, { forbidReactElements, space, valueName, sortObjectKey
|
|
|
38
43
|
problematicValueName: path.length === 0 ? functionName : undefined,
|
|
39
44
|
});
|
|
40
45
|
}
|
|
41
|
-
const valueOriginal = this[key];
|
|
42
46
|
for (const { is, serialize } of types.slice().reverse()) {
|
|
43
|
-
if (is(
|
|
47
|
+
if (is(value)) {
|
|
44
48
|
//@ts-ignore
|
|
45
|
-
return serialize(
|
|
49
|
+
return serialize(value, serializer);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
if (sortObjectKeys && isObject(value)) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/json-serializer",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.18",
|
|
4
4
|
"description": "Same as JSON but with added support for `Date`, `undefined`, `Map`, `Set`, and more.",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.mjs",
|
|
8
8
|
"./parse": {
|
|
9
|
-
"
|
|
9
|
+
"import": "./dist/esm/parse.js",
|
|
10
|
+
"require": "./dist/cjs/parse.js",
|
|
10
11
|
"types": "./dist/esm/parse.d.ts",
|
|
11
12
|
"default": "./dist/esm/parse.js"
|
|
12
13
|
},
|
|
13
14
|
"./stringify": {
|
|
14
|
-
"
|
|
15
|
+
"import": "./dist/esm/stringify.js",
|
|
16
|
+
"require": "./dist/cjs/stringify.js",
|
|
15
17
|
"types": "./dist/esm/stringify.d.ts",
|
|
16
18
|
"default": "./dist/esm/stringify.js"
|
|
17
19
|
}
|