Skip to content

Commit ac439a6

Browse files
committed
Add BigInt support
1 parent bc0691a commit ac439a6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/index.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe("javascript-stringify", () => {
218218
});
219219

220220
describe(
221-
"should not take the names of their keys",
221+
"omit the names of their keys",
222222
cases(["{name:function () {}}", "{'tricky name':function () {}}"])
223223
);
224224
});
@@ -250,6 +250,10 @@ describe("javascript-stringify", () => {
250250
it("should stringify", test(Buffer.from("test"), "new Buffer('test')"));
251251
});
252252

253+
describeIf("BigInt", typeof (BigInt as any) === "function", () => {
254+
it("should stringify", test(BigInt("10"), "BigInt('10')"));
255+
});
256+
253257
describe("Error", () => {
254258
it("should stringify", test(new Error("test"), "new Error('test')"));
255259
});

src/stringify.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const PRIMITIVE_TYPES: Record<string, ToString> = {
1818
// ES2018 `Symbol.description`.
1919
return `Symbol(${next((value as any).description)})`;
2020
},
21+
bigint: (value: bigint, space: string, next: Next) => {
22+
return `BigInt(${next(String(value))})`;
23+
},
2124
undefined: String,
2225
object: objectToString,
2326
function: functionToString

0 commit comments

Comments
 (0)