Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

safe-bigint

ljharb97MIT1.1.1TypeScript support: included

Safely create a BigInt from a numerical string, even one larger than MAX_SAFE_INTEGER.

bigint, safe, MAX_SAFE_INTEGER

readme

safe-bigint Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Safely create a BigInt from a numerical string, even one larger than MAX_SAFE_INTEGER.

Note that the implementation in node versions that lack the exports field, or bundlers/tooling that does not understand it, will use Function, which in browsers, may not work due to CSP controls.

However, the modern version (which modern node and bundlers/tooling should all detect) just exports the BigInt constructor. Feel free to alias this package with module.exports = BigInt or export default BigInt in your build process configuration.

Example

const safeBigInt = require('safe-bigint');
const assert = require('assert');
const { satisfies } = require('semver');

assert.equal(9007199254740991n, safeBigInt(9007199254740991));
assert.equal(9007199254740992n, safeBigInt(9007199254740992));

if (satisfies(process.version, '10.4 - 10.8')) {
    assert.throws(
        () => BigInt(9007199254740992),
        RangeError
    );
}

Tests

Simply clone the repo, npm install, and run npm test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.1.1 - 2024-12-18

Commits

  • [actions] split out node 10-20, and 20+ 6957cbe
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @ljharb/tsconfig, @types/get-intrinsic, @types/tape, auto-changelog, npmignore, object-inspect, tape 063d46f
  • [Refactor] use call-bound directly 0b38419
  • [Deps] update call-bind, get-intrinsic c98b8fa
  • [Tests] replace aud with npm audit e6923a6
  • [Dev Deps] update @arethetypeswrong/cli, @types/tape 35a5b05
  • [Dev Deps] add missing peer dep 647cdee

v1.1.0 - 2024-03-28

Commits

  • [New] add is-safe entrypoint ac6f82d
  • [Refactor] extract out "needs hack" logic d670522
  • [Dev Deps] update @ljharb/tsconfig dc40964

v1.0.1 - 2024-03-28

Commits

  • [types] use shared config 380f73f
  • [Fix] do not try to convert a bigint a47e900
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @ljharb/tsconfig, @types/object-inspect 75dfc21
  • [Dev Deps] update aud, npmignore, tape 0c3edf2
  • [Tests] use @arethetypeswrong/cli 1467c88

v1.0.0 - 2024-03-01

Commits

  • Initial implementation, tests, readme, types b8ef3e0
  • Initial commit 240198a
  • npm init 9298be2
  • Only apps should have lockfiles 8bfd7eb
  • [actions] add notable versions to test ed3f8e6