Skip to content

Instantly share code, notes, and snippets.

@vitaly-t
Created October 7, 2019 20:23
Show Gist options
  • Save vitaly-t/66993f5feea568f38d2152cc791d5b7c to your computer and use it in GitHub Desktop.
Save vitaly-t/66993f5feea568f38d2152cc791d5b7c to your computer and use it in GitHub Desktop.
// Works the same as JSON.stringify, but also handles BigInt type,
// using 123n format, to make sure the result is reversible:
function stringify(value) {
if (value !== undefined) {
return JSON.stringify(value, (_, v) => typeof v === 'bigint' ? `${v}n` : v);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment