Skip to content
On this page

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

NameType
conditionunknown
messagestring | () => string

Returns

asserts condition

Defined in

packages/util/src/lib.ts:9


concatBytes

concatBytes(iterable): Uint8Array

Creates a concatenated Uint8Array from the inputs.

Parameters

NameType
iterableIterable<Uint8Array> | Uint8Array[]

Returns

Uint8Array

Defined in

packages/util/src/lib.ts:18


fromHex

fromHex(hex): Uint8Array

Parses pretty space-separated hex into bytes

Example

ts
fromHex('01 02 03') // new Uint8Array([1, 2, 3])

Parameters

NameTypeDescription
hexstringSpace-separated bytes in hex repr

Returns

Uint8Array

Defined in

packages/util/src/lib.ts:75


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

NameType
mapMap<K, V>
keyK

Returns

V

Defined in

packages/util/src/lib.ts:50


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

NameType
vUint8Array

Returns

string

Defined in

packages/util/src/lib.ts:63