Skip to content

Commit

Permalink
#2496: Remove "" for number in BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrushi20 committed Apr 17, 2024
1 parent 5b2ddaa commit d955eb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions packages/fast-stable-stringify/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ describe('fastStableStringify', function () {
expect(stringify(value)).toBe(jsonStableStringify(value));
});
it('hashes bigints', function () {
expect(stringify(200n)).toMatch('"200"n');
expect(stringify({ foo: 100n })).toMatch('{"foo":"100"n}');
expect(stringify({ age: BigInt(100n), name: 'Hrushi' })).toMatch('{"age":"100"n,"name":"Hrushi"}');
expect(stringify({ age: [BigInt(100n), BigInt(200n), BigInt(300n)] })).toMatch(
'{"age":["100"n,"200"n,"300"n]}',
);
expect(stringify(200n)).toMatch('200n');
expect(stringify({ foo: 100n, goo: '100n' })).toMatch('{"foo":100n,"goo":"100n"}');
expect(stringify({ age: BigInt(100n), name: 'Hrushi' })).toMatch('{"age":100n,"name":"Hrushi"}');
expect(stringify({ age: [BigInt(100n), BigInt(200n), BigInt(300n)] })).toMatch('{"age":[100n,200n,300n]}');
});
});
2 changes: 1 addition & 1 deletion packages/fast-stable-stringify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function stringify(val: unknown, isArrayProp: boolean) {
case 'undefined':
return isArrayProp ? null : undefined;
case 'bigint':
return JSON.stringify(val.toString()) + 'n';
return `${val.toString()}n`;
case 'string':
return JSON.stringify(val);
default:
Expand Down

0 comments on commit d955eb0

Please sign in to comment.