Skip to main content
Version: 5.24.3

Namespace: encode

References​

IS_BROWSER​

Re-exports IS_BROWSER

Functions​

arrayBufferToString​

â–¸ arrayBufferToString(array): string

Convert array buffer to string

[internal usage]

Parameters​

NameType
arrayArrayBuffer

Returns​

string

Defined in​

src/utils/encode.ts:18


utf8ToArray​

â–¸ utf8ToArray(str): Uint8Array

Convert utf8-string to Uint8Array

[internal usage]

Parameters​

NameType
strstring

Returns​

Uint8Array

Defined in​

src/utils/encode.ts:27


stringToArrayBuffer​

â–¸ stringToArrayBuffer(str): Uint8Array

Convert utf8-string to Uint8Array

Deprecated

equivalent to 'utf8ToArray', alias will be removed

Parameters​

NameType
strstring

Returns​

Uint8Array

Defined in​

src/utils/encode.ts:36


atobUniversal​

â–¸ atobUniversal(a): Uint8Array

Convert string to array buffer (browser and node compatible)

Parameters​

NameType
astring

Returns​

Uint8Array

Defined in​

src/utils/encode.ts:43


btoaUniversal​

â–¸ btoaUniversal(b): string

Convert array buffer to string (browser and node compatible)

Parameters​

NameType
bArrayBuffer

Returns​

string

Defined in​

src/utils/encode.ts:50


buf2hex​

â–¸ buf2hex(buffer): string

Convert array buffer to hex-string

Parameters​

NameType
bufferUint8Array

Returns​

string

format: hex-string

Defined in​

src/utils/encode.ts:58


removeHexPrefix​

â–¸ removeHexPrefix(hex): string

Remove hex prefix '0x' from hex-string

Parameters​

NameTypeDescription
hexstringhex-string

Returns​

string

format: base16-string

Defined in​

src/utils/encode.ts:67


addHexPrefix​

â–¸ addHexPrefix(hex): string

Add hex prefix '0x' to base16-string

Parameters​

NameTypeDescription
hexstringbase16-string

Returns​

string

format: hex-string

Defined in​

src/utils/encode.ts:76


padLeft​

â–¸ padLeft(str, length, padding?): string

Prepend string (default with '0')

Parameters​

NameTypeDefault value
strstringundefined
lengthnumberundefined
paddingstringSTRING_ZERO

Returns​

string

Defined in​

src/utils/encode.ts:98


calcByteLength​

â–¸ calcByteLength(str, byteSize?): number

Calculate byte length of string

[no internal usage]

Parameters​

NameTypeDefault value
strstringundefined
byteSizenumber8

Returns​

number

Defined in​

src/utils/encode.ts:107


sanitizeBytes​

â–¸ sanitizeBytes(str, byteSize?, padding?): string

Prepend '0' to string bytes

[no internal usage]

Parameters​

NameTypeDefault value
strstringundefined
byteSizenumber8
paddingstringSTRING_ZERO

Returns​

string

Defined in​

src/utils/encode.ts:118


sanitizeHex​

â–¸ sanitizeHex(hex): string

Prepend '0' to hex-string bytes

[no internal usage]

Parameters​

NameTypeDescription
hexstringhex-string

Returns​

string

format: hex-string

Defined in​

src/utils/encode.ts:129


pascalToSnake​

â–¸ pascalToSnake(text): string

String transformation util

Pascal case to screaming snake case

Parameters​

NameType
textstring

Returns​

string

Defined in​

src/utils/encode.ts:143