
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@types/bn.js
Advanced tools
TypeScript definitions for bn.js
@types/bn.js provides TypeScript type definitions for the bn.js library, which is a big number library for arbitrary-precision arithmetic. It is commonly used in cryptographic applications and blockchain development.
Basic Arithmetic Operations
This feature allows you to perform basic arithmetic operations such as addition, subtraction, multiplication, and division on big numbers.
const BN = require('bn.js');
const a = new BN(123);
const b = new BN(456);
const sum = a.add(b);
console.log(sum.toString()); // '579'
Modular Arithmetic
This feature allows you to perform modular arithmetic operations, which are essential in cryptographic algorithms.
const BN = require('bn.js');
const a = new BN(10);
const b = new BN(3);
const mod = a.mod(b);
console.log(mod.toString()); // '1'
Bitwise Operations
This feature allows you to perform bitwise operations such as AND, OR, XOR, and NOT on big numbers.
const BN = require('bn.js');
const a = new BN('1010', 2); // binary
const b = new BN('1100', 2); // binary
const and = a.and(b);
console.log(and.toString(2)); // '1000'
Number Conversion
This feature allows you to convert numbers between different bases, such as binary, hexadecimal, and decimal.
const BN = require('bn.js');
const a = new BN('ff', 16); // hexadecimal
console.log(a.toString(10)); // '255'
big.js is a small, fast, and lightweight library for arbitrary-precision decimal arithmetic. It is less feature-rich compared to bn.js but is suitable for applications that require high precision with smaller numbers.
decimal.js is a library for arbitrary-precision decimal arithmetic. It offers a wide range of mathematical functions and is more feature-rich compared to big.js, making it a good alternative to bn.js for applications requiring decimal arithmetic.
bignumber.js is a library for arbitrary-precision decimal and non-decimal arithmetic. It is similar to bn.js but focuses more on decimal arithmetic, making it suitable for financial calculations.
npm install --save @types/bn.js
This package contains type definitions for bn.js (https://github.com/indutny/bn.js).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bn.js.
These definitions were written by Leonid Logvinov, Henry Nguyen, Gaylor Bosson, and JounQin.
FAQs
TypeScript definitions for bn.js
The npm package @types/bn.js receives a total of 1,745,092 weekly downloads. As such, @types/bn.js popularity was classified as popular.
We found that @types/bn.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.