# int64-native

> A simple uint64_t wrapper for JavaScript

Latest version **0.5.0** (published 2018-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install int64-native
pnpm add int64-native
yarn add int64-native
bun add int64-native
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2018-12-03 |
| First published | 2013-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Evan Savage |
| Maintainers | candu |
| Keywords | types, int64, bigint |

## Links

- npm: https://www.npmjs.com/package/int64-native
- Homepage: https://github.com/candu/node-int64-native
- npm.io page: https://npm.io/package/int64-native

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ^2.4.0
- [bindings](https://npm.io/package/bindings.md) 1.2.x

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2018-12-03
- 0.4.0 — 2015-09-02
- 0.3.2 — 2014-05-03
- 0.3.1 — 2014-04-16
- 0.2.1 — 2014-01-18
- 0.2.0 — 2013-07-10
- 0.1.0 — 2013-05-07

## 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');

---
_Source: https://npm.io/package/int64-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
