Registry / serialization / node-int64

node-int64

JSON →
library0.4.0jsnpmunverified

The `node-int64` library provides a class, `Int64`, to precisely represent 64-bit integers in JavaScript, addressing the inherent limitation of JavaScript's IEEE 754 double-precision floats which lose integer precision beyond +/- 2^53. It is currently at version 0.4.0, which was published 11 years ago, and the project is not actively maintained, with its author noting that native `BigInt`s will likely obsolete it. The library aims to provide a Number-like object primarily for carrying 64-bit integer values, such as those encountered in binary data formats like Apache Thrift, rather than for performing 64-bit integer arithmetic. While instances can be coerced to JavaScript numbers for basic operations, values exceeding the safe integer range will resolve to `Infinity`. Its primary utility lies in preserving the exact 64-bit binary representation, which can be extracted as an octet string or Node.js `Buffer`. This makes it suitable for interoperability with systems requiring precise 64-bit data types, distinguishing it from libraries focused on arbitrary-precision arithmetic.

npm install node-int64
INSTALL
IMPORT
SIG · NODE-INT64
N
node-int64
serializationjavascriptv0.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Int64
const Int64 = require('node-int64');
import Int64 from 'node-int64'; // This package is CommonJS-only. import { Int64 } from 'node-int64'; // This package is CommonJS-only.
The `node-int64` package is a CommonJS module and does not support ESM imports. It exports the `Int64` class directly as `module.exports`.
new Int64(value)
const myInt = new Int64('123456789abcdef0');
The constructor accepts numbers, hex strings, two 32-bit words, or Buffer/Uint8Array instances.
Int64 (TypeScript type)
import Int64 = require('node-int64'); // or /// <reference types="node-int64" />
import { Int64 } from 'node-int64'; // The community-maintained types use 'export = Int64'.
For TypeScript, the community-maintained `@types/node-int64` package should be installed. It uses `export = Int64`, requiring a `require` style import for types.

Demonstrates creating `Int64` instances from various inputs (number, hex string, Buffer) and basic output operations like `toOctetString` and `toBuffer`.

const Int64 = require('node-int64'); // Create an Int64 from a JavaScript number (up to 2^53 precision) const smallInt = new Int64(0x123456789); console.log(`Small Int: ${smallInt.toString(16)} (value: ${smallInt.valueOf()})`); // Create an Int64 from a hexadecimal string for full 64-bit precision const bigHex = '123456789abcdef0'; const largeInt = new Int64(bigHex); console.log(`Large Int (hex): ${largeInt.toOctetString()} (value: ${largeInt.valueOf()})`); // Create an Int64 from a Node.js Buffer const buffer = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x02, 0x03, 0x04]); const intFromBuffer = new Int64(buffer); console.log(`From Buffer: ${intFromBuffer.toOctetString()} (value: ${intFromBuffer.valueOf()})`); // Extract the 64-bit value into a Buffer const outputBuffer = intFromBuffer.toBuffer(); console.log(`To Buffer: ${outputBuffer.toString('hex')}`); // Check if the internal value is within JS safe integer range console.log(`Is smallInt finite (JS precision): ${isFinite(smallInt)}`); console.log(`Is largeInt finite (JS precision): ${isFinite(largeInt)}`);
Debug
Known issues
breakingThe `new Buffer()` constructor used in older examples and package internals is deprecated and can pose security risks. It has been replaced by `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`.
fix
While `node-int64` itself uses `new Buffer()` internally, direct usage in consuming code should be updated. For creating Int64 from a buffer, use `new Int64(Buffer.from([...]))` or `new Int64(new Uint8Array([...]))`.
affects: >=0.4.0 (for Node.js v6+)
gotchaThis library is designed for *representing* 64-bit integers, not for performing 64-bit *arithmetic*. Operations like addition or subtraction on `Int64` instances will implicitly convert them to standard JavaScript numbers, leading to precision loss if the value exceeds 2^53.
fix
If 64-bit arithmetic is required, consider using native `BigInt` (available in Node.js v10.5.0+ and modern browsers) or a different arbitrary-precision arithmetic library like `js-big-decimal`.
affects: >=0.4.0
deprecatedThe `node-int64` package is not actively maintained, and its author suggests it will be obsoleted by the native `BigInt` feature in JavaScript. Users are encouraged to migrate to `BigInt` for 64-bit integer handling when feasible.
fix
Evaluate migrating to native JavaScript `BigInt`. For example, `new Int64('...')` can often be replaced with `BigInt('0x...')` or `BigInt('...')`.
affects: >=0.4.0
gotchaWhen an `Int64` instance represents a value outside the safe integer range of JavaScript numbers (i.e., beyond +/- 2^53), attempting to coerce it to a number (e.g., through `valueOf()`, `+` operator, or implicit conversion) will result in `Infinity` or `NaN`, despite the internal 64-bit representation being accurate.
fix
Always use methods like `toOctetString()` or `toBuffer()` to retrieve the full 64-bit precision, or `toString(radix)` for string representation, rather than relying on numerical coercion, especially for large values.
affects: >=0.4.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES module context or a browser environment without a bundler that polyfills `require`.
fix
This package is CommonJS-only. Ensure your Node.js project is configured for CommonJS (e.g., without `"type": "module"` in `package.json` or by using a bundler). For browser environments, a bundler is necessary.
TypeError: Int64 is not a constructor
The `Int64` symbol was not correctly imported or assigned, or the package failed to load.
fix
Verify that `const Int64 = require('node-int64');` is correctly placed and executed before `new Int64(...)` calls. Check `node_modules` for `node-int64`.
ReferenceError: Buffer is not defined
Attempting to use `Buffer` in a browser environment without a polyfill, or in an older Node.js context where `Buffer` might not be globally available if not explicitly required/imported (less common in modern Node.js).
fix
For browser usage, a polyfill for Node.js `Buffer` is required. In Node.js, `Buffer` is typically global, but if not, ensure `const Buffer = require('buffer').Buffer;` or similar is used.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources