JSBI (JavaScript BigInt) is a pure-JavaScript implementation of the ECMAScript BigInt proposal, which officially became a part of the JavaScript language in ES2020. The current stable version is 4.3.2. This library serves as a robust polyfill, enabling developers to use arbitrary-precision integers in JavaScript environments that lack native BigInt support, such as older browsers and Node.js versions. A key differentiator of JSBI is its precise adherence to the native BigInt specification's behavior, which facilitates a straightforward, mechanical migration path to native BigInts once they are universally supported, often accomplished through the `babel-plugin-transform-jsbi-to-bigint` plugin. JSBI prioritizes performance, aiming to be highly competitive with native BigInt implementations. Its release cadence is primarily driven by maintenance requirements and alignment with ECMAScript specification updates, rather than frequent feature additions, given its role as a specification-compliant polyfill.
npm install jsbiVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to import JSBI, create BigInt instances from numbers and strings, and perform arithmetic operations like addition and multiplication using JSBI's static methods, mimicking native BigInt behavior.
Replace native operators with corresponding `JSBI` static methods for all BigInt arithmetic. For example, `a + b` becomes `JSBI.add(a, b)`.
Always explicitly convert `JSBI` instances to a string representation before logging, using `String(myJsbiInstance)` or `myJsbiInstance.toString()`.
For new projects targeting modern environments, consider using native BigInts directly instead of JSBI. For existing projects, evaluate migration to native BigInts using `babel-plugin-transform-jsbi-to-bigint`.
Integrate `babel-plugin-transform-jsbi-to-bigint` into your Babel configuration to automatically convert JSBI syntax to native BigInts.
Ensure all operands in an arithmetic or comparison operation are `JSBI` instances and use `JSBI`'s static methods. If interconversion is necessary, use `JSBI.toNumber(jsbiValue)` or `JSBI.BigInt(numberValue)`.
Call `String(myJsbiValue)` or `myJsbiValue.toString()` explicitly when logging `JSBI` instances to view their numeric value.
No dependency data recorded yet.