Skip to content

refactor!: Remove json-bigint #81

@danielbankhead

Description

@danielbankhead

Remove json-bigint and @types/json-bigint.

We can use native bigints via the JSON.parse reviver parameter and essentially check via:

const jsonParse = (stringified: string) => JSON.parse(stringified, (key, value, context) => {
  if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
    // Use the context for the appropriate precision
    return BigInt(context.source);
  }

  return value;
});

Example:

const bigJSON = '{"largeNumber": 12345678901234567890, "a": {"b": 1, "c": 893081290390128309213821903 }}';
const res = jsonParse(bigJSON);

// res:
// {
//  largeNumber: 12345678901234567890n,
//  a: { b: 1, c: 893081290390128309213821903n }
// }

Improves on:

Documentation:

Metadata

Metadata

Assignees

No one assigned

    Labels

    next major: breaking changethis is a change that we should wait to bundle into the next major versionpriority: p3Desirable enhancement or fix. May not be included in next release.semver: majorHint for users that this is an API breaking change.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions