- MINOR: #39, implemented the tc39 proposal of https://github.com/tc39/proposal-json-parse-with-source (only the
context.source), so that it is possible to handleBigInts.
const {parse, stringify} = require('comment-json')
const parsed = parse(
`{"foo": 9007199254740993}`,
// The reviver function now has a 3rd param that contains the string source.
(key, value, {source}) =>
/^[0-9]+$/.test(source) ? BigInt(source) : value
)
console.log(parsed)
// {
// "foo": 9007199254740993n
// }
stringify(parsed, (key, val) =>
typeof value === 'bigint'
// Pay attention that
// JSON.rawJSON is supported in node >= 21
? JSON.rawJSON(String(val))
: value
)
// {"foo":9007199254740993}An upgrade is recommended for all users.