Gathering detailed insights and metrics for node-int64
Gathering detailed insights and metrics for node-int64
Gathering detailed insights and metrics for node-int64
Gathering detailed insights and metrics for node-int64
Support for representing 64-bit integers in JavaScript
npm install node-int64
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
203 Stars
34 Commits
50 Forks
13 Watching
1 Branches
7 Contributors
Updated on 19 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.5%
5,086,654
Compared to previous day
Last week
1.9%
27,182,191
Compared to previous week
Last month
18.1%
110,678,275
Compared to previous month
Last year
13.2%
1,120,333,427
Compared to previous year
1
int64
was a workaround JS' lack of support for Int64 data types. Somewhat to my surprise, people have found it useful. However, it looks like BigInts will soon be a formally accepted feature, obsoleting the need for this package.
If a trustworthy organization or individual would like to take over as maintainer, I'm happy to hand this off. Please contact me at robert@broofa.com if you're interested. Otherwise I'll be npm-deprecating this at some future date.
JavaScript Numbers are represented as IEEE 754 double-precision floats. Unfortunately, this means they lose integer precision for values beyond +/- 2^^53. For projects that need to accurately handle 64-bit ints, such as node-thrift, a performant, Number-like class is needed. Int64 is that class.
Int64 instances look and feel much like JS-native Numbers. By way of example ...
1// First, let's illustrate the problem ... 2> (0x123456789).toString(16) 3'123456789' // <- what we expect. 4> (0x123456789abcdef0).toString(16) 5'123456789abcdf00' // <- Ugh! JS doesn't do big ints. :( 6 7// So let's create a couple Int64s using the above values ... 8 9// Require, of course 10> Int64 = require('node-int64') 11 12// x's value is what we expect (the decimal value of 0x123456789) 13> x = new Int64(0x123456789) 14[Int64 value:4886718345 octets:00 00 00 01 23 45 67 89] 15 16// y's value is Infinity because it's outside the range of integer 17// precision. But that's okay - it's still useful because it's internal 18// representation (octets) is what we passed in 19> y = new Int64('123456789abcdef0') 20[Int64 value:Infinity octets:12 34 56 78 9a bc de f0] 21 22// Let's do some math. Int64's behave like Numbers. (Sorry, Int64 isn't 23// for doing 64-bit integer arithmetic (yet) - it's just for carrying 24// around int64 values 25> x + 1 264886718346 27> y + 1 28Infinity 29 30// Int64 string operations ... 31> 'value: ' + x 32'value: 4886718345' 33> 'value: ' + y 34'value: Infinity' 35> x.toString(2) 36'100100011010001010110011110001001' 37> y.toString(2) 38'Infinity' 39 40// Use JS's isFinite() method to see if the Int64 value is in the 41// integer-precise range of JS values 42> isFinite(x) 43true 44> isFinite(y) 45false 46 47// Get an octet string representation. (Yay, y is what we put in!) 48> x.toOctetString() 49'0000000123456789' 50> y.toOctetString() 51'123456789abcdef0' 52 53// Finally, some other ways to create Int64s ... 54 55// Pass hi/lo words 56> new Int64(0x12345678, 0x9abcdef0) 57[Int64 value:Infinity octets:12 34 56 78 9a bc de f0] 58 59// Pass a Buffer 60> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])) 61[Int64 value:Infinity octets:12 34 56 78 9a bc de f0] 62 63// Pass a Buffer and offset 64> new Int64(new Buffer([0,0,0,0,0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4) 65[Int64 value:Infinity octets:12 34 56 78 9a bc de f0] 66 67// Pull out into a buffer 68> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).toBuffer() 69<Buffer 12 34 56 78 9a bc de f0> 70 71// Or copy into an existing one (at an offset) 72> var buf = new Buffer(1024); 73> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).copy(buf, 512);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/26 approved changesets -- score normalized to 2
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More