utils-js
A collection of utilities and constants for NNS/SNS projects.
![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
Table of contents
Installation
You can use utils-js
by installing it in your project.
npm i @dfinity/utils
The bundle needs peer dependencies, be sure that following resources are available in your project as well.
npm i @dfinity/agent @dfinity/candid @dfinity/principal
Features
utils-js
implements following features:
:toolbox: Functions
:gear: defaultAgent
Function | Type |
---|
defaultAgent | () => Agent |
:gear: createServices
Function | Type |
---|
createServices | <T>({ options: { canisterId, serviceOverride, certifiedServiceOverride, agent: agentOption, }, idlFactory, certifiedIdlFactory, }: { options: RequiredCanisterOptions<T>; idlFactory: InterfaceFactory; certifiedIdlFactory: InterfaceFactory; }) => { ...; } |
:gear: uint8ArrayToBigInt
Function | Type |
---|
uint8ArrayToBigInt | (array: Uint8Array) => bigint |
:gear: arrayBufferToUint8Array
Function | Type |
---|
arrayBufferToUint8Array | (buffer: ArrayBuffer) => Uint8Array |
:gear: uint8ArrayToArrayOfNumber
Function | Type |
---|
uint8ArrayToArrayOfNumber | (array: Uint8Array) => number[] |
:gear: arrayOfNumberToUint8Array
Function | Type |
---|
arrayOfNumberToUint8Array | (numbers: number[]) => Uint8Array |
:gear: asciiStringToByteArray
Function | Type |
---|
asciiStringToByteArray | (text: string) => number[] |
:gear: assertNonNullish
Function | Type |
---|
assertNonNullish | <T>(value: T, message?: string) => asserts value is NonNullable<T> |
:gear: toNullable
Function | Type |
---|
toNullable | <T>(value?: T) => [] or [T] |
:gear: fromNullable
Function | Type |
---|
fromNullable | <T>(value: [] or [T]) => T |
:gear: fromDefinedNullable
Function | Type |
---|
fromDefinedNullable | <T>(value: [] or [T]) => T |
:factory: NullishError
Constructors
public
Parameters: