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 native JS implementation of bigint (ECMA-262) from/to:

  • buffer (node.js) or uint8array (native js),
  • hex string,
  • utf8 text string.

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

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 currently ECMA-262 and thus 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

bigintToHex(a)str

Convert a bigint to a hexadecimal string

hexToBigint(hex)bigint

Converts a hexadecimal string to a bigint

bufToText(buf)string

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

textToBuf(str)Buffer | Uint8Array

Converts a string of textwith utf-8 encoding to a buffer (node) or uint8array (native js)

bufToHex(a)string

Returns the hexadecimal representation of a buffer (node) or uint8array (native js)

hexToBuf(hex_str)Buffer | Uint8Array

Converts a hexadecimal string to a buffer (node) or uint8array (native js)

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 buffer|uint8array binary representaion)

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) ⇒ bigint

Converts a hexadecimal string to a bigint

Kind: global function
Returns: bigint - a

Param Type
hex string

bufToText(buf) ⇒ string

Converts a buffer (node) or a uint8array (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 | Uint8Array A buffer containing utf-8 encoded text.

textToBuf(str) ⇒ Buffer | Uint8Array

Converts a string of textwith utf-8 encoding to a buffer (node) or uint8array (native js)

Kind: global function
Returns: Buffer | Uint8Array - a buffer containing the utf-8 encoded text.

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

bufToHex(a) ⇒ string

Returns the hexadecimal representation of a buffer (node) or uint8array (native js)

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

Param Type Description
a Buffer | Uint8Array buffer containing utf-8 encoded text.

hexToBuf(hex_str) ⇒ Buffer | Uint8Array

Converts a hexadecimal string to a buffer (node) or uint8array (native js)

Kind: global function
Returns: Buffer | Uint8Array - a buffer (node) or uint8array (native js)

Param Type Description
hex_str string A hexadecimal 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 buffer|uint8array 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