Skip to content

Convert from bigint to buffer (or uint8array), hex string, utf8 string, bas64 and backwards. For both node.js and javascript native.

License

Notifications You must be signed in to change notification settings

juanelas/bigint-conversion

Repository files navigation

Licence: MIT Contributor Covenant JavaScript Style Guide Node.js CI Coverage Status

bigint-conversion

Convert to/from non-negative integers represented with ES-2020 native JS implementation of BigInt from/to:

  • Buffer (node.js) or ArrayBuffer|TypedArray (native js),
  • hex string,
  • utf8-encoded text string,
  • standard and url-safe base64 with and without padding.

It provides a common interface for the conversions that works for both node.js and native javascript.

Note that there is not a directly visible TypedArray() constructor, but a set of typed array ones: Int8Array(), Uint8Array(), Uint8ClampedArray(), Int16Array(), Uint16Array(), Int32Array(), Uint32Array(), Float32Array(), Float64Array(), BigInt64Array(), BigUint64Array().

Usage

bigint-conversion can be imported to your project with npm:

npm install bigint-conversion

Then either require (Node.js CJS):

const bigintConversion = require('bigint-conversion')

or import (JavaScript ES module):

import * as bigintConversion from 'bigint-conversion'

The appropriate version for browser or node is automatically exported.

BigInt is ES-2020. In order to use it with TypeScript you should set target (and probably also lib) to at least es2020 in tsconfig.json.

You can also download the IIFE bundle, the ESM bundle or the UMD bundle and manually add it to your project, or, if you have already installed bigint-conversion in your project, just get the bundles from node_modules/bigint-conversion/dist/bundles/.

API reference documentation

Check the API

About

Convert from bigint to buffer (or uint8array), hex string, utf8 string, bas64 and backwards. For both node.js and javascript native.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published