@keplr-wallet/router
Advanced tools
Comparing version 0.12.132 to 0.12.133-rc.0
@@ -18,2 +18,8 @@ "use strict"; | ||
} | ||
if (typeof BigInt !== "undefined" && | ||
value && | ||
typeof value === "string" && | ||
value.startsWith("__bigint__")) { | ||
return BigInt(value.replace("__bigint__", "")); | ||
} | ||
return value; | ||
@@ -38,2 +44,5 @@ }); | ||
} | ||
if (typeof value === "bigint") { | ||
return `__bigint__${value.toString()}`; | ||
} | ||
return value; | ||
@@ -50,3 +59,3 @@ }); | ||
return undefined; | ||
return JSONUint8Array.parse(JSON.stringify(obj)); | ||
return JSONUint8Array.parse(JSONUint8Array.stringify(obj)); | ||
} | ||
@@ -53,0 +62,0 @@ } |
@@ -9,2 +9,29 @@ "use strict"; | ||
describe("Test json with Uint8Array", () => { | ||
it("should support bigint", () => { | ||
const test = { | ||
a: 1, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
b: 2n, | ||
c: { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
d: 3n, | ||
}, | ||
}; | ||
const text = uint8_array_1.JSONUint8Array.stringify(test); | ||
assert_1.default.strictEqual(text, '{"a":1,"b":"__bigint__2","c":{"d":"__bigint__3"}}'); | ||
const obj = uint8_array_1.JSONUint8Array.parse(text); | ||
assert_1.default.deepStrictEqual(obj, { | ||
a: 1, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
b: 2n, | ||
c: { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
d: 3n, | ||
}, | ||
}); | ||
}); | ||
it("should stringify properly with uint8array", () => { | ||
@@ -11,0 +38,0 @@ const test = { |
{ | ||
"name": "@keplr-wallet/router", | ||
"version": "0.12.132", | ||
"version": "0.12.133-rc.0", | ||
"main": "build/index.js", | ||
@@ -18,3 +18,3 @@ "author": "chainapsis", | ||
}, | ||
"gitHead": "c2d43ec60a80e023faee97ded00f582b7605307c" | ||
"gitHead": "6496cf28fc619e718b4e2e9e347755730292745b" | ||
} |
@@ -6,2 +6,36 @@ import assert from "assert"; | ||
describe("Test json with Uint8Array", () => { | ||
it("should support bigint", () => { | ||
const test = { | ||
a: 1, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
b: 2n, | ||
c: { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
d: 3n, | ||
}, | ||
}; | ||
const text = JSONUint8Array.stringify(test); | ||
assert.strictEqual( | ||
text, | ||
'{"a":1,"b":"__bigint__2","c":{"d":"__bigint__3"}}' | ||
); | ||
const obj = JSONUint8Array.parse(text); | ||
assert.deepStrictEqual(obj, { | ||
a: 1, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
b: 2n, | ||
c: { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
d: 3n, | ||
}, | ||
}); | ||
}); | ||
it("should stringify properly with uint8array", () => { | ||
@@ -8,0 +42,0 @@ const test = { |
@@ -20,2 +20,11 @@ // The JSON encoder that supports the `Uint8Array`. | ||
if ( | ||
typeof BigInt !== "undefined" && | ||
value && | ||
typeof value === "string" && | ||
value.startsWith("__bigint__") | ||
) { | ||
return BigInt(value.replace("__bigint__", "")); | ||
} | ||
return value; | ||
@@ -47,2 +56,6 @@ }); | ||
if (typeof value === "bigint") { | ||
return `__bigint__${value.toString()}`; | ||
} | ||
return value; | ||
@@ -61,4 +74,4 @@ }); | ||
return JSONUint8Array.parse(JSON.stringify(obj)); | ||
return JSONUint8Array.parse(JSONUint8Array.stringify(obj)); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71741
1253