BigInteger.js is a robust JavaScript library for performing arithmetic operations on integers of unlimited size, circumventing JavaScript's standard number precision limitations. The current stable version is 1.6.52. While releases are not on a fixed schedule, the project is actively maintained, with recent updates addressing various fixes and TypeScript definitions. A key differentiator and recent major change is its evolution into a polyfill for the native JavaScript `BigInt` feature (introduced to TC39 in 2018). If the execution environment supports native `BigInt`, this library will transparently wrap the native implementation, otherwise, it provides its own software-based arbitrary-length integer solution. This makes it a highly compatible choice for environments with varying `BigInt` support.
npm install big-integerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `bigInt` values from numbers and strings, perform arithmetic operations like factorial calculation, and use pre-defined constants, highlighting its use in handling large integer arithmetic beyond standard JavaScript number limits.
Prefer using `bigInt.isInstance(value)` for checking if a value is a big-integer managed type. Avoid `instanceof` or direct type checking if cross-compatibility with native `BigInt` is required.
Always pass large integer values as strings to the `bigInt()` factory function to ensure exact representation and avoid precision loss. For example, `bigInt('9007199999999999')` instead of `bigInt(9007199999999999)`.Evaluate your project's target environment support. If native `BigInt` is available, consider using `n` suffix for literals (e.g., `123n`) and native operations. If broader compatibility is needed or older environments must be supported, `big-integer` remains a viable polyfill.
Ensure that string inputs only contain valid digits for the specified base and that the base parameter itself is a valid integer. For example, `bigInt('hello')` will throw this error, as will `bigInt('10', 0)`.When `big-integer` uses native `BigInt` as a polyfill, all operands in an arithmetic operation must be `BigInt`s. Convert standard numbers to `BigInt` using `BigInt(number)` or `bigInt(number)` before operations, e.g., `bigInt('100').plus(bigInt(5))` instead of `bigInt('100').plus(5)`.No dependency data recorded yet.