json-with-bigint 3.3.3 → 3.4.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
@@ -24,9 +24,9 @@ JSONParse(JSONStringify(data)).bigNumber === 9007199254740992n // true
24
24
 
25
25
  ✔️ No need to change your JSON or the way you want to work with your data
26
26
 
27
- ✔️ You don't have to memorize this library's API, you already know it. Just skip the dot, and that's it (JSONParse(), JSONStringify())
27
+ ✔️ You don't have to memorize this library's API, you already know it. Just skip the dot, and that's it (`JSONParse()`, `JSONStringify()`)
28
28
 
29
- ✔️ Parses and stringifies all other values other than big numbers the same way as native JSON methods in JS do. You can just replace every `JSON.parse` and `JSON.stringify` call in your project with functions from this library and it'll work.
29
+ ✔️ Parses and stringifies all other values other than big numbers the same way as native JSON methods in JS do. Signatures match too. You can just replace every `JSON.parse()` and `JSON.strinfigy()` in your project with `JSONParse()` and `JSONStringify()`, and it will work
30
30
 
31
31
  ✔️ Correctly parses float numbers and negative numbers
32
32
 
@@ -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");
@@ -26,7 +26,7 @@ const JSONStringify = (value, replacer, space) => {
26
26
  if (!value) return originalStringify(value, replacer, space);
27
27
 
28
28
  const bigInts = /([\[:])?"(-?\d+)n"($|([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
29
- const noise = /([\[:])?("-?\d+n+)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,28 +1,3 @@
1
- type JsonObject = {
2
- [x: string]: Json;
3
- };
1
+ export const JSONStringify: typeof JSON.stringify;
4
2
 
5
- type JsonArray = Json[];
6
-
7
- export type Json =
8
- | null
9
- | undefined
10
- | string
11
- | number
12
- | bigint
13
- | boolean
14
- | JsonObject
15
- | {}
16
- | JsonArray;
17
-
18
- export function JSONStringify(
19
- data: Exclude<Json, undefined>,
20
- space?: string | number
21
- ): string;
22
-
23
- export function JSONStringify(
24
- data: undefined,
25
- space?: string | number
26
- ): undefined;
27
-
28
- export function JSONParse<T extends Json = Json>(serializedData: string): T;
3
+ export const JSONParse: typeof JSON.parse;
@@ -1,28 +1,3 @@
1
- type JsonObject = {
2
- [x: string]: Json;
3
- };
1
+ export const JSONStringify: typeof JSON.stringify;
4
2
 
5
- type JsonArray = Json[];
6
-
7
- export type Json =
8
- | null
9
- | undefined
10
- | string
11
- | number
12
- | bigint
13
- | boolean
14
- | JsonObject
15
- | {}
16
- | JsonArray;
17
-
18
- export function JSONStringify(
19
- data: Exclude<Json, undefined>,
20
- space?: string | number
21
- ): string;
22
-
23
- export function JSONStringify(
24
- data: undefined,
25
- space?: string | number
26
- ): undefined;
27
-
28
- export function JSONParse<T extends Json = Json>(serializedData: string): T;
3
+ export const JSONParse: typeof JSON.parse;
@@ -26,7 +26,7 @@ export const JSONStringify = (value, replacer, space) => {
26
26
  if (!value) return originalStringify(value, replacer, space);
27
27
 
28
28
  const bigInts = /([\[:])?"(-?\d+)n"($|([\\n]|\s)*(\s|[\\n])*[,\}\]])/g;
29
- const noise = /([\[:])?("-?\d+n+)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"($|([\\n]|\s)*(\s|[\\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.3",
3
+ "version": "3.4.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": {