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 CHANGED
@@ -40,7 +40,7 @@ JSONParse(JSONStringify(data)).bigNumber === 9007199254740992n // true
40
40
 
41
41
  ✔️ Can be used as both ESM and CommonJS module
42
42
 
43
- ✔️ Size: 756 bytes (minified and gzipped)
43
+ ✔️ Size: 776 bytes (minified and gzipped)
44
44
 
45
45
  ✔️ No dependencies
46
46
 
@@ -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 parsing passed");
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 parsing passed");
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 parsing passed");
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 parsing passed");
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 parsing passed");
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 parsing passed");
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 parsing passed");
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");
@@ -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) => {
@@ -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) => {
@@ -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 a='"'===n[0];if(a&&Boolean(n.match(e)))return n.substring(0,n.length-1)+'n"';const s=o||g,l=r&&(r.length<i||r.length===i&&r<=t);return a||s||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)}))};
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)}))};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-with-bigint",
3
- "version": "3.3.2",
3
+ "version": "3.3.4",
4
4
  "description": "JS library that allows you to easily serialize and deserialize data with BigInt values",
5
5
  "type": "module",
6
6
  "exports": {