Skip to content

Commit b86b557

Browse files
committed
support BigInt
1 parent b639d58 commit b86b557

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

devalue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function devalue(value) {
4747

4848
switch (type) {
4949
case 'Number':
50+
case 'BigInt':
5051
case 'String':
5152
case 'Boolean':
5253
case 'Date':
@@ -253,6 +254,7 @@ function stringifyPrimitive(thing) {
253254
if (thing === 0 && 1 / thing < 0) return '-0';
254255
const str = String(thing);
255256
if (typeof thing === 'number') return str.replace(/^(-)?0\./, '$1.');
257+
if (typeof thing === 'bigint') return thing + 'n';
256258
return str;
257259
}
258260

devalue.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('basics', (t) => {
6868
t('Object', { foo: 'bar', 'x-y': 'z' }, '{foo:"bar","x-y":"z"}');
6969
t('Set', new Set([1, 2, 3]), 'new Set([1,2,3])');
7070
t('Map', new Map([['a', 'b']]), 'new Map([["a","b"]])');
71+
t('BigInt', BigInt('1'), '1n');
7172
});
7273

7374
describe('strings', (t) => {

0 commit comments

Comments
 (0)