@lowdefy/helpers 4.0.0-rc.7 → 4.0.0-rc.9
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/serializer.js +24 -30
- package/package.json +2 -2
package/dist/serializer.js
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
import stableStringify from './stableStringify.js';
|
|
17
17
|
const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
18
18
|
let dateReplacer = (date)=>({
|
|
19
|
-
|
|
19
|
+
'~d': date.valueOf()
|
|
20
20
|
});
|
|
21
21
|
if (isoStringDates) {
|
|
22
22
|
dateReplacer = (date)=>({
|
|
23
|
-
|
|
23
|
+
'~d': date.toISOString()
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
let newValue = value;
|
|
@@ -29,7 +29,7 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
29
29
|
}
|
|
30
30
|
if (type.isError(newValue)) {
|
|
31
31
|
return {
|
|
32
|
-
|
|
32
|
+
'~e': {
|
|
33
33
|
name: newValue.name,
|
|
34
34
|
message: newValue.message,
|
|
35
35
|
value: newValue.toString()
|
|
@@ -46,17 +46,17 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
46
46
|
newValue[k] = dateReplacer(newValue[k]);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
if (newValue
|
|
50
|
-
Object.defineProperty(newValue, '
|
|
51
|
-
value: newValue
|
|
49
|
+
if (newValue['~r']) {
|
|
50
|
+
Object.defineProperty(newValue, '~r', {
|
|
51
|
+
value: newValue['~r'],
|
|
52
52
|
enumerable: true,
|
|
53
53
|
writable: true,
|
|
54
54
|
configurable: true
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
if (newValue
|
|
58
|
-
Object.defineProperty(newValue, '
|
|
59
|
-
value: newValue
|
|
57
|
+
if (newValue['~k']) {
|
|
58
|
+
Object.defineProperty(newValue, '~k', {
|
|
59
|
+
value: newValue['~k'],
|
|
60
60
|
enumerable: true,
|
|
61
61
|
writable: true,
|
|
62
62
|
configurable: true
|
|
@@ -77,17 +77,17 @@ const makeReplacer = (customReplacer, isoStringDates)=>(key, value)=>{
|
|
|
77
77
|
const makeReviver = (customReviver)=>(key, value)=>{
|
|
78
78
|
let newValue = value;
|
|
79
79
|
if (type.isObject(newValue)) {
|
|
80
|
-
if (newValue
|
|
81
|
-
Object.defineProperty(newValue, '
|
|
82
|
-
value: newValue
|
|
80
|
+
if (newValue['~r']) {
|
|
81
|
+
Object.defineProperty(newValue, '~r', {
|
|
82
|
+
value: newValue['~r'],
|
|
83
83
|
enumerable: false,
|
|
84
84
|
writable: true,
|
|
85
85
|
configurable: true
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
if (newValue
|
|
89
|
-
Object.defineProperty(newValue, '
|
|
90
|
-
value: newValue
|
|
88
|
+
if (newValue['~k']) {
|
|
89
|
+
Object.defineProperty(newValue, '~k', {
|
|
90
|
+
value: newValue['~k'],
|
|
91
91
|
enumerable: false,
|
|
92
92
|
writable: true,
|
|
93
93
|
configurable: true
|
|
@@ -98,19 +98,13 @@ const makeReviver = (customReviver)=>(key, value)=>{
|
|
|
98
98
|
newValue = customReviver(key, value);
|
|
99
99
|
}
|
|
100
100
|
if (type.isObject(newValue)) {
|
|
101
|
-
if (!type.isUndefined(newValue
|
|
102
|
-
const error = new Error(newValue.
|
|
103
|
-
error.name = newValue.
|
|
101
|
+
if (!type.isUndefined(newValue['~e'])) {
|
|
102
|
+
const error = new Error(newValue['~e'].message);
|
|
103
|
+
error.name = newValue['~e'].name;
|
|
104
104
|
return error;
|
|
105
105
|
}
|
|
106
|
-
if (!type.isUndefined(newValue
|
|
107
|
-
|
|
108
|
-
return new Date(newValue._date);
|
|
109
|
-
}
|
|
110
|
-
if (newValue._date === 'now') {
|
|
111
|
-
return newValue;
|
|
112
|
-
}
|
|
113
|
-
const result = new Date(newValue._date);
|
|
106
|
+
if (!type.isUndefined(newValue['~d'])) {
|
|
107
|
+
const result = new Date(newValue['~d']);
|
|
114
108
|
if (!type.isDate(result)) {
|
|
115
109
|
return newValue;
|
|
116
110
|
}
|
|
@@ -124,11 +118,11 @@ const serialize = (json, options = {})=>{
|
|
|
124
118
|
if (type.isDate(json)) {
|
|
125
119
|
if (options.isoStringDates) {
|
|
126
120
|
return {
|
|
127
|
-
|
|
121
|
+
'~d': json.toISOString()
|
|
128
122
|
};
|
|
129
123
|
}
|
|
130
124
|
return {
|
|
131
|
-
|
|
125
|
+
'~d': json.valueOf()
|
|
132
126
|
};
|
|
133
127
|
}
|
|
134
128
|
return JSON.parse(JSON.stringify(json, makeReplacer(options.replacer, options.isoStringDates)));
|
|
@@ -137,9 +131,9 @@ const serializeToString = (json, options = {})=>{
|
|
|
137
131
|
if (type.isUndefined(json)) return json;
|
|
138
132
|
if (type.isDate(json)) {
|
|
139
133
|
if (options.isoStringDates) {
|
|
140
|
-
return `{ "
|
|
134
|
+
return `{ "~d": "${json.toISOString()}" }`;
|
|
141
135
|
}
|
|
142
|
-
return `{ "
|
|
136
|
+
return `{ "~d": ${json.valueOf()} }`;
|
|
143
137
|
}
|
|
144
138
|
if (options.stable) {
|
|
145
139
|
return stableStringify(json, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/helpers",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.9",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "d20e6ac424643feca527a732dc2b0710713c8243"
|
|
55
55
|
}
|