json-with-bigint 3.3.2 → 3.3.4
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/README.md +1 -1
- package/__tests__/unit.cjs +15 -7
- package/json-with-bigint.cjs +2 -2
- package/json-with-bigint.js +6 -6
- package/json-with-bigint.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/__tests__/unit.cjs
CHANGED
|
@@ -101,37 +101,45 @@ const test7Obj = [
|
|
|
101
101
|
"90071992547409981111.5n",
|
|
102
102
|
];
|
|
103
103
|
|
|
104
|
+
const test8Obj = { uid: BigInt("1308537228663099396") };
|
|
105
|
+
const test8JSON = '{\n "uid": 1308537228663099396\n}';
|
|
106
|
+
|
|
104
107
|
assert.deepStrictEqual(JSONParse(test1JSON), test1Obj);
|
|
105
|
-
console.log("1 test
|
|
108
|
+
console.log("1 test passed");
|
|
106
109
|
assert.deepStrictEqual(JSONStringify(JSONParse(test1JSON)), test1JSON);
|
|
107
110
|
console.log("1 test round-trip passed");
|
|
108
111
|
|
|
109
112
|
assert.deepStrictEqual(JSONParse(test2JSON), test2Obj);
|
|
110
|
-
console.log("2 test
|
|
113
|
+
console.log("2 test passed");
|
|
111
114
|
assert.deepStrictEqual(JSONStringify(JSONParse(test2JSON)), test2TersedJSON);
|
|
112
115
|
console.log("2 test round-trip passed");
|
|
113
116
|
|
|
114
117
|
assert.deepStrictEqual(JSONParse(test3JSON), test3Obj);
|
|
115
|
-
console.log("3 test
|
|
118
|
+
console.log("3 test passed");
|
|
116
119
|
assert.deepStrictEqual(JSONStringify(JSONParse(test3JSON)), test3JSON);
|
|
117
120
|
console.log("3 test round-trip passed");
|
|
118
121
|
|
|
119
122
|
assert.deepStrictEqual(JSONParse(test4JSON), test4Obj);
|
|
120
|
-
console.log("4 test
|
|
123
|
+
console.log("4 test passed");
|
|
121
124
|
assert.deepStrictEqual(JSONStringify(JSONParse(test4JSON)), test4JSON);
|
|
122
125
|
console.log("4 test round-trip passed");
|
|
123
126
|
|
|
124
127
|
assert.deepStrictEqual(JSONParse(test5JSON), test5Obj);
|
|
125
|
-
console.log("5 test
|
|
128
|
+
console.log("5 test passed");
|
|
126
129
|
assert.deepStrictEqual(JSONStringify(JSONParse(test5JSON)), test5JSON);
|
|
127
130
|
console.log("5 test round-trip passed");
|
|
128
131
|
|
|
129
132
|
assert.deepStrictEqual(JSONParse(test6JSON), test6Obj);
|
|
130
|
-
console.log("6 test
|
|
133
|
+
console.log("6 test passed");
|
|
131
134
|
assert.deepStrictEqual(JSONStringify(JSONParse(test6JSON)), test6JSON);
|
|
132
135
|
console.log("6 test round-trip passed");
|
|
133
136
|
|
|
134
137
|
assert.deepStrictEqual(JSONParse(test7JSON), test7Obj);
|
|
135
|
-
console.log("7 test
|
|
138
|
+
console.log("7 test passed");
|
|
136
139
|
assert.deepStrictEqual(JSONStringify(JSONParse(test7JSON)), test7JSON);
|
|
137
140
|
console.log("7 test round-trip passed");
|
|
141
|
+
|
|
142
|
+
assert.deepStrictEqual(JSONStringify(test8Obj, null, 2), test8JSON);
|
|
143
|
+
console.log("8 test passed");
|
|
144
|
+
assert.deepStrictEqual(JSONParse(JSONStringify(test8Obj, null, 2)), test8Obj);
|
|
145
|
+
console.log("8 test round-trip passed");
|
package/json-with-bigint.cjs
CHANGED
|
@@ -25,8 +25,8 @@ const JSONStringify = (value, replacer, space) => {
|
|
|
25
25
|
|
|
26
26
|
if (!value) return originalStringify(value, replacer, space);
|
|
27
27
|
|
|
28
|
-
const bigInts = /([\[:])?"(-?\d+)n"($|[,\}\]])/g;
|
|
29
|
-
const noise = /([\[:])?("-?\d+n+)n("$|"[,\}\]])/g;
|
|
28
|
+
const bigInts = /([\[:])?"(-?\d+)n"($|([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
|
|
29
|
+
const noise = /([\[:])?("-?\d+n+)n("$|"([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
|
|
30
30
|
const convertedToCustomJSON = originalStringify(
|
|
31
31
|
value,
|
|
32
32
|
(key, value) => {
|
package/json-with-bigint.js
CHANGED
|
@@ -11,13 +11,13 @@ export const JSONStringify = (value, replacer, space) => {
|
|
|
11
11
|
return originalStringify(
|
|
12
12
|
value,
|
|
13
13
|
(key, value) => {
|
|
14
|
-
if (typeof value === "bigint") return JSON.rawJSON(value.toString())
|
|
14
|
+
if (typeof value === "bigint") return JSON.rawJSON(value.toString());
|
|
15
15
|
|
|
16
|
-
if (typeof replacer === "function") return replacer(key, value)
|
|
16
|
+
if (typeof replacer === "function") return replacer(key, value);
|
|
17
17
|
|
|
18
|
-
if (Array.isArray(replacer) && replacer.includes(key)) return value
|
|
18
|
+
if (Array.isArray(replacer) && replacer.includes(key)) return value;
|
|
19
19
|
|
|
20
|
-
return value
|
|
20
|
+
return value;
|
|
21
21
|
},
|
|
22
22
|
space
|
|
23
23
|
);
|
|
@@ -25,8 +25,8 @@ export const JSONStringify = (value, replacer, space) => {
|
|
|
25
25
|
|
|
26
26
|
if (!value) return originalStringify(value, replacer, space);
|
|
27
27
|
|
|
28
|
-
const bigInts = /([\[:])?"(-?\d+)n"($|[,\}\]])/g;
|
|
29
|
-
const noise = /([\[:])?("-?\d+n+)n("$|"[,\}\]])/g;
|
|
28
|
+
const bigInts = /([\[:])?"(-?\d+)n"($|([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
|
|
29
|
+
const noise = /([\[:])?("-?\d+n+)n("$|"([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
|
|
30
30
|
const convertedToCustomJSON = originalStringify(
|
|
31
31
|
value,
|
|
32
32
|
(key, value) => {
|
package/json-with-bigint.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const noiseValue=/^-?\d+n+$/,originalStringify=JSON.stringify,originalParse=JSON.parse;export const JSONStringify=(n,r,t)=>{if("rawJSON"in JSON)return originalStringify(n,((n,t)=>"bigint"==typeof t?JSON.rawJSON(t.toString()):"function"==typeof r?r(n,t):(Array.isArray(r)&&r.includes(n),t)),t);if(!n)return originalStringify(n,r,t);const i=originalStringify(n,((n,t)=>"string"==typeof t&&Boolean(t.match(noiseValue))||"bigint"==typeof t?t.toString()+"n":"function"==typeof r?r(n,t):(Array.isArray(r)&&r.includes(n),t)),t);return i.replace(/([\[:])?"(-?\d+)n"($|[,\}\]])/g,"$1$2$3").replace(/([\[:])?("-?\d+n+)n("$|"[,\}\]])/g,"$1$2$3")};export const JSONParse=(n,r)=>{if(!n)return originalParse(n,r);const t=Number.MAX_SAFE_INTEGER.toString(),i=t.length,e=/^"-?\d+n+"$/,o=/^-?\d+n$/,g=n.replace(/"(?:\\.|[^"])*"|-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/g,((n,r,o,g)=>{const
|
|
1
|
+
const noiseValue=/^-?\d+n+$/,originalStringify=JSON.stringify,originalParse=JSON.parse;export const JSONStringify=(n,r,t)=>{if("rawJSON"in JSON)return originalStringify(n,((n,t)=>"bigint"==typeof t?JSON.rawJSON(t.toString()):"function"==typeof r?r(n,t):(Array.isArray(r)&&r.includes(n),t)),t);if(!n)return originalStringify(n,r,t);const i=originalStringify(n,((n,t)=>"string"==typeof t&&Boolean(t.match(noiseValue))||"bigint"==typeof t?t.toString()+"n":"function"==typeof r?r(n,t):(Array.isArray(r)&&r.includes(n),t)),t);return i.replace(/([\[:])?"(-?\d+)n"($|([\\n]|\s)*(\s|[\\n])*[,\}\]])/g,"$1$2$3").replace(/([\[:])?("-?\d+n+)n("$|"([\\n]|\s)*(\s|[\\n])*[,\}\]])/g,"$1$2$3")};export const JSONParse=(n,r)=>{if(!n)return originalParse(n,r);const t=Number.MAX_SAFE_INTEGER.toString(),i=t.length,e=/^"-?\d+n+"$/,o=/^-?\d+n$/,g=n.replace(/"(?:\\.|[^"])*"|-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/g,((n,r,o,g)=>{const s='"'===n[0];if(s&&Boolean(n.match(e)))return n.substring(0,n.length-1)+'n"';const a=o||g,l=r&&(r.length<i||r.length===i&&r<=t);return s||a||l?n:'"'+n+'n"'}));return originalParse(g,((n,t,i)=>{if("string"==typeof t&&Boolean(t.match(o)))return BigInt(t.substring(0,t.length-1));return"string"==typeof t&&Boolean(t.match(noiseValue))?t.substring(0,t.length-1):"function"!=typeof r?t:r(n,t,i)}))};
|