npm.io
0.3.2 • Published 1 month ago

@pacote/u64

Licence
MIT
Version
0.3.2
Deps
0
Size
110 kB
Vulns
0
Weekly
0
Stars
20

@pacote/u64

version minified minified + gzip

Unsigned 64-bit integers.

This package exists because while modern JavaScript environments support very large integers via the BigInt type, it is not available in older browsers and tooling doesn't always transpile BigInt operations into a backwards-compatible format.

U64 also turned out to be more performant than BigInt in tests. @pacote's implementation of the XXH64 algorithm based on U64 is 4.5 times faster than the one based on BigInt, although optimizations to JavaScript runtimes might change this in the future.

If you target ECMAScript 2020 or later, and you do not care about the differences in performance, you will probably not need this.

The U64 type provided by this package is represented as a tuple of four 16-bit integers. For example, the number 1 is [1, 0, 0, 0]. It is not an object class with built-in methods. Instead of methods, the package provides functions to support commonly-used operations.

Installation

yarn add @pacote/u64

Example

import { add, from, toString } from '@pacote/u64'

const result = add(from('1609587929392839161'), from('9650029242287828579'))

toString(result) // -> '11259617171680667740'

License

MIT Luís Rodrigues.