npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

int64-native

v0.5.0

Published

A simple uint64_t wrapper for JavaScript

Downloads

25

Readme

int64-native

int64-native is a simple uint64_t wrapper for JavaScript, enabling the use of 64-bit unsigned integers from node.

Why?

int64-native was originally developed to support reasonable handling of 64-bit ID columns in databases. There are other 64-bit integer modules out there, but AFAICT all of them are pure JavaScript; native uint64_t seemed like a better way to handle this!

The one caveat is that you won't be able to use this browser-side. However, you can use the string representation to pass 64-bit values from server to client.

Installing

via npm

npm install int64-native

from source

git clone git://github.com/candu/node-int64-native.git
cd node-int64-native
npm install

int64-native is built using node-gyp.

Usage

All of the following examples are borrowed from test/int64.js, which you can run via

npm test

Including

require() gives you direct access to the constructor:

var Int64 = require('int64-native');

Constructor

You can create an Int64 as follows:

var x = new Int64(),
    y = new Int64(42),
    z = new Int64(0xfedcba98, 0x76543210),
    w = new Int64('0xfedcba9876543210')
expect(x.toString()).to.equal('0x0000000000000000');
expect(y.toString()).to.equal('0x000000000000002a');
expect(z.toString()).to.equal('0xfedcba9876543210');
expect(w.toString()).to.equal('0xfedcba9876543210');

The last two methods allow you to represent uint64_t values larger than (1 << 53) - 1.

Type Conversions

Int64 exposes toNumber(), valueOf() for converting to numeric values:

var a = new Int64(2),
    b = new Int64(3);
expect(a + b).to.equal(5);
var x = new Int64(),
    y = new Int64(42),
    z = new Int64(0xfedcba98, 0x76543210),
    w = new Int64('0xfedcba9876543210')
expect(+x).to.equal(0);
expect(+y).to.equal(42);
expect(+z).to.equal(Infinity);
expect(+w).to.equal(Infinity);

Values larger than (1 << 53) - 1 will be converted to Infinity, since they cannot be accurately represented using JavaScript's Number type.

As you can see from the examples so far, toString() produces the hex string corresponding to an Int64.

Conversion to Decimal String

Int64 also exposes toSignedDecimalString() and toUnsignedDecimalString() for converting to decimal strings:

var minusOne = new Int64('0xFFFFFFFFFFFFFFFF');
expect(minusOne.toSignedDecimalString()).to.equal('-1');
expect(minusOne.toUnsignedDecimalString()).to.equal('18446744073709551615');

Comparison

For cases where you wish to sort or compare Int64 values, equals() and compare() are provided:

var a = new Int64(2),
    b = new Int64(3);
expect(a.equals(a)).to.be.true;
expect(a.equals(b)).to.be.false;
expect(a.compare(a)).to.equal(0);
expect(a.compare(b)).to.equal(-1);
expect(b.compare(a)).to.equal(1);

Bit Manipulation

There are several operations for bit-level manipulation of Int64 values:

var x = new Int64('0xfedcba9876543210');
expect(x.high32().toString(16)).to.equal('fedcba98');
expect(x.low32().toString(16)).to.equal('76543210');
var y = x.and(new Int64(0xffff)),
    z = x.or(new Int64(0xffff)),
    w = x.xor(new Int64('fffffffffffffffff'));
expect(y.toString()).to.equal('0x0000000000003210');
expect(z.toString()).to.equal('0xfedcba987654ffff');
expect(w.toString()).to.equal('0x0123456789abcdef');
var a = new Int64(7),
    b = a.shiftLeft(1),
    c = a.shiftRight(1);
expect(b.toString()).to.equal('0x000000000000000e');
expect(c.toString()).to.equal('0x0000000000000003');