long
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Long.js is a JavaScript library developed for representing a 64-bit two's-complement integer value. Based on the Closure Library, it aims to reliably work with and perform bitwise operations on the full 64 bits. This functionality is necessary because JavaScript can only handle integers within the safe range of 2<sup>53</sup>-1. Beyond this limit, JavaScript is unable to accurately represent integer values, which can create inaccuracies in mathematical calculations. Long.js solves this issue, offering extended support for unsigned 64-bit integers.
Using long.js in your project involves a simple installation via npm, and its implementation is straightforward. To represent a 64-bit integer, you can instantiate a new Long
object. Here's a quick example:
// Install via npm
$> npm install long
// In your JavaScript file
import Long from "long";
var value = new Long(0xFFFFFFFF, 0x7FFFFFFF);
console.log(value.toString());
In this example, we've created a new Long
object with a 64-bit integer value and logged its string representation into the console. Note that blending ECMAScript modules (ESM) and CommonJS is not recommended, as it can yield different classes with the same functionality, even though they are fundamentally different module systems.
The complete documentation of Long.js, including its constructor, fields, constants, utility functions, and methods, can be found in the readme file of its GitHub repository, here. It provides a comprehensive guide to getting started with the library - from installation and basic usage, to advanced functions, such as bitwise operations and string representation of 64-bit integers.