JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6784
  • Score
    100M100P100Q143944F
  • License MIT

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

Package Exports

  • bigint-conversion

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bigint-conversion) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bigint-conversion

Convert to/from ES-2020 native JS implementation of BigInt from/to:

  • Buffer (node.js) or ArrayBuffer|TypedArray (native js),
  • hex string,
  • utf8-encoded text string.

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

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().

Installation

bigint-conversion is distributed for web browsers and/or webviews supporting BigInt as an ES6 module or an IIFE file; and for Node.js as a CJS module.

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

npm install bigint-conversion

NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js.

For web browsers, you can also directly download the IIFE file or the ES6 module from GitHub.

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

bigint-conversion JS Doc

Functions

bigintToBuf(a)Buffer | ArrayBuffer

Convert a bigint to a buffer (node.js) or ArrayBuffer (native js)

bufToBigint(buf)bigint

Converts a Buffer (node.js) or ArrayBuffer|TypedArray (native js) to a bigint

bigintToHex(a)str

Convert a bigint to a hexadecimal string

hexToBigint(hex_str)bigint

Converts a hexadecimal string to a bigint

bigintToText(a)string

Converts a bigint representing a binary array of utf-8 encoded text to a string of utf-8 text

textToBigint(text)bigint

Converts a utf-8 string to a bigint (from its binary representaion)

bufToText(buf)string

Converts a buffer (node) or a ArrayBuffer (native js) containing utf-8 encoded text to a string of utf-8 text

textToBuf(str)Buffer | ArrayBuffer

Converts a string of utf-8 encoded text to a Buffer (node) or ArrayBuffer (native js)

bufToHex(buf)string

Returns the hexadecimal representation of a buffer.

hexToBuf(hex_str)Buffer | ArrayBuffer

Converts a hexadecimal string to a buffer

bigintToBuf(a) ⇒ Buffer | ArrayBuffer

Convert a bigint to a buffer (node.js) or ArrayBuffer (native js)

Kind: global function
Returns: Buffer | ArrayBuffer - A buffer (node.js) or ArrayBuffer (native js) with a binary representation of the input bigint

Param Type
a bigint

bufToBigint(buf) ⇒ bigint

Converts a Buffer (node.js) or ArrayBuffer|TypedArray (native js) to a bigint

Kind: global function
Returns: bigint - A BigInt

Param Type
buf Buffer | ArrayBuffer | TypedArray

bigintToHex(a) ⇒ str

Convert a bigint to a hexadecimal string

Kind: global function
Returns: str - A hexadecimal representation of the input bigint

Param Type
a bigint

hexToBigint(hex_str) ⇒ bigint

Converts a hexadecimal string to a bigint

Kind: global function
Returns: bigint - A BigInt

Param Type
hex_str string

bigintToText(a) ⇒ string

Converts a bigint representing a binary array of utf-8 encoded text to a string of utf-8 text

Kind: global function
Returns: string - A string text with utf-8 encoding

Param Type Description
a bigint A bigint representing a binary array of utf-8 encoded text.

textToBigint(text) ⇒ bigint

Converts a utf-8 string to a bigint (from its binary representaion)

Kind: global function
Returns: bigint - A bigint representing a binary array of the input utf-8 encoded text

Param Type Description
text string A string text with utf-8 encoding

bufToText(buf) ⇒ string

Converts a buffer (node) or a ArrayBuffer (native js) containing utf-8 encoded text to a string of utf-8 text

Kind: global function
Returns: string - A string text with utf-8 encoding

Param Type Description
buf Buffer | ArrayBuffer | TypedArray A buffer containing utf-8 encoded text

textToBuf(str) ⇒ Buffer | ArrayBuffer

Converts a string of utf-8 encoded text to a Buffer (node) or ArrayBuffer (native js)

Kind: global function
Returns: Buffer | ArrayBuffer - A buffer containing the utf-8 encoded text

Param Type Description
str string A string of text (with utf-8 encoding)

bufToHex(buf) ⇒ string

Returns the hexadecimal representation of a buffer.

Kind: global function
Returns: string - A string with a hexadecimal representation of the input buffer

Param Type
buf Buffer | ArrayBuffer | TypedArray

hexToBuf(hex_str) ⇒ Buffer | ArrayBuffer

Converts a hexadecimal string to a buffer

Kind: global function
Returns: Buffer | ArrayBuffer - A Buffer (node) or ArrayBuffer (native js)

Param Type Description
hex_str string A string representing a number with hexadecimal notation