Skip to main content

Class: Converter

Convert arrays to and from different formats.

Table of contents

Methods

Constructors

Methods

bytesToUtf8

Static bytesToUtf8(array, startIndex?, length?): string

Encode a raw array to UTF8 string.

Parameters

NameTypeDescription
arrayArrayLike<number>The bytes to encode.
startIndex?numberThe index to start in the bytes.
length?numberThe length of bytes to read.

Returns

string

The array formated as UTF8.


utf8ToBytes

Static utf8ToBytes(utf8): Uint8Array

Convert a UTF8 string to raw array.

Parameters

NameTypeDescription
utf8stringThe text to decode.

Returns

Uint8Array

The array.


bytesToHex

Static bytesToHex(array, includePrefix?, startIndex?, length?, reverse?): string

Encode a raw array to hex string.

Parameters

NameTypeDefault valueDescription
arrayArrayLike<number>undefinedThe bytes to encode.
includePrefixbooleanfalseInclude the 0x prefix on the returned hex.
startIndex?numberundefinedThe index to start in the bytes.
length?numberundefinedThe length of bytes to read.
reverse?booleanundefinedReverse the combine direction.

Returns

string

The array formated as hex.


hexToBytes

Static hexToBytes(hex, reverse?): Uint8Array

Decode a hex string to raw array.

Parameters

NameTypeDescription
hexstringThe hex to decode.
reverse?booleanStore the characters in reverse.

Returns

Uint8Array

The array.


utf8ToHex

Static utf8ToHex(utf8, includePrefix?): string

Convert the UTF8 to hex.

Parameters

NameTypeDefault valueDescription
utf8stringundefinedThe text to convert.
includePrefixbooleanfalseInclude the 0x prefix on the returned hex.

Returns

string

The hex version of the bytes.


hexToUtf8

Static hexToUtf8(hex): string

Convert the hex text to text.

Parameters

NameTypeDescription
hexstringThe hex to convert.

Returns

string

The UTF8 version of the bytes.


isHex

Static isHex(value, allowPrefix?): boolean

Is the data hex format.

Parameters

NameTypeDefault valueDescription
valuestringundefinedThe value to test.
allowPrefixbooleanfalseAllow the hex to have the 0x prefix.

Returns

boolean

True if the string is hex.


bytesToBinary

Static bytesToBinary(bytes): string

Convert bytes to binary string.

Parameters

NameTypeDescription
bytesUint8ArrayThe bytes to convert.

Returns

string

A binary string of the bytes.


binaryToBytes

Static binaryToBytes(binary): Uint8Array

Convert a binary string to bytes.

Parameters

NameTypeDescription
binarystringThe binary string.

Returns

Uint8Array

The bytes.


bytesToBase64

Static bytesToBase64(bytes): string

Convert bytes to base64 string.

Parameters

NameTypeDescription
bytesUint8ArrayThe bytes to convert.

Returns

string

A base64 string of the bytes.


base64ToBytes

Static base64ToBytes(base64): Uint8Array

Convert a base64 string to bytes.

Parameters

NameTypeDescription
base64stringThe base64 string.

Returns

Uint8Array

The bytes.

Constructors

constructor

new Converter()