Scale JS / @scale-codec/util
Module: @scale-codec/util
@scale-codec/* shared utility functions
Table of contents
Functions
Functions
assert
▸ assert(condition, message): asserts condition
Good-old assert
Parameters
| Name | Type |
|---|---|
condition | unknown |
message | string | () => string |
Returns
asserts condition
Defined in
concatBytes
▸ concatBytes(iterable): Uint8Array
Creates a concatenated Uint8Array from the inputs.
Parameters
| Name | Type |
|---|---|
iterable | Iterable<Uint8Array> | Uint8Array[] |
Returns
Uint8Array
Defined in
fromHex
▸ fromHex(hex): Uint8Array
Parses pretty space-separated hex into bytes
Example
ts
fromHex('01 02 03') // new Uint8Array([1, 2, 3])
Parameters
| Name | Type | Description |
|---|---|---|
hex | string | Space-separated bytes in hex repr |
Returns
Uint8Array
Defined in
mapGetUnwrap
▸ mapGetUnwrap<K, V>(map, key): V
Returns value from map by key and throws if there is no such key
Type parameters
| Name |
|---|
K |
V |
Parameters
| Name | Type |
|---|---|
map | Map<K, V> |
key | K |
Returns
V
Defined in
toHex
▸ toHex(v): string
Makes pretty-hex from bytes array, like 01 a5 f0
Example
ts
toHex(new Uint8Array([1, 11, 3])) // '01 a1 03'
Parameters
| Name | Type |
|---|---|
v | Uint8Array |
Returns
string