json-with-bigint 2.1.3 → 2.2.3
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/json-with-bigint.d.ts +2 -2
- package/json-with-bigint.js +5 -3
- package/json-with-bigint.min.js +1 -1
- package/package.json +1 -1
package/json-with-bigint.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type Json =
|
|
2
2
|
| null
|
|
3
3
|
| undefined
|
|
4
|
-
| string
|
|
4
|
+
| string
|
|
5
5
|
| number
|
|
6
6
|
| bigint
|
|
7
7
|
| boolean
|
|
@@ -15,6 +15,6 @@ interface JsonObject {
|
|
|
15
15
|
|
|
16
16
|
interface JsonArray extends Array<Json> {}
|
|
17
17
|
|
|
18
|
-
export function JSONStringify(data: Json): string;
|
|
18
|
+
export function JSONStringify(data: Json, space?: string | number): string;
|
|
19
19
|
|
|
20
20
|
export function JSONParse<T extends Json = Json>(serializedData: string): T;
|
package/json-with-bigint.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Function to serialize data to JSON string
|
|
3
3
|
Converts BigInt values to custom format (strings with digits and "n" at the end) and then converts them to proper big integers in JSON string
|
|
4
4
|
*/
|
|
5
|
-
export const JSONStringify = (data) => {
|
|
5
|
+
export const JSONStringify = (data, space) => {
|
|
6
6
|
const bigInts = /([\[:])?"(-?\d+)n"([,\}\]])/g;
|
|
7
|
-
const preliminaryJSON = JSON.stringify(
|
|
8
|
-
|
|
7
|
+
const preliminaryJSON = JSON.stringify(
|
|
8
|
+
data,
|
|
9
|
+
(_, value) => (typeof value === "bigint" ? value.toString() + "n" : value),
|
|
10
|
+
space
|
|
9
11
|
);
|
|
10
12
|
const finalJSON = preliminaryJSON.replace(bigInts, "$1$2$3");
|
|
11
13
|
|
package/json-with-bigint.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSONStringify=t=>JSON.stringify(t,((t,n)=>"bigint"==typeof n?n.toString()+"n":n)).replace(/([\[:])?"(-?\d+)n"([,\}\]])/g,"$1$2$3");export const JSONParse=t=>{const n=t.replace(/(?<=[^\\]":[\[]?|[^\\]":\[.*[^\.\d*])(-?\d{17,}|-?(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))(?=,|\}[^"]?|\][^"])/g,'"$1n"');return JSON.parse(n,((t,n)=>"string"==typeof n&&Boolean(n.match(/^-?\d+n$/))?BigInt(n.substring(0,n.length-1)):n))};
|
|
1
|
+
export const JSONStringify=(t,n)=>JSON.stringify(t,((t,n)=>"bigint"==typeof n?n.toString()+"n":n),n).replace(/([\[:])?"(-?\d+)n"([,\}\]])/g,"$1$2$3");export const JSONParse=t=>{const n=t.replace(/(?<=[^\\]":[\[]?|[^\\]":\[.*[^\.\d*])(-?\d{17,}|-?(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))(?=,|\}[^"]?|\][^"])/g,'"$1n"');return JSON.parse(n,((t,n)=>"string"==typeof n&&Boolean(n.match(/^-?\d+n$/))?BigInt(n.substring(0,n.length-1)):n))};
|
package/package.json
CHANGED