UNPKG

@dfinity/utils

Version:

A collection of utilities and constants for NNS/SNS projects.

36 lines (35 loc) 1.78 kB
import type { Nullable, NullishNullable } from "../types/did.utils"; /** * Converts a value into a Candid-style variant representation of an optional value. * * @template T The type of the value. * @param {T | null | undefined} value - The value to convert into a Candid-style variant. * @returns {Nullable<T>} A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value. */ export declare const toNullable: <T>(value?: T | null) => Nullable<T>; /** * Extracts the value from a Candid-style variant representation of an optional value. * * @template T The type of the value. * @param {Nullable<T>} value - A Candid-style variant representing an optional value. * @returns {T | undefined} The extracted value, or `undefined` if the array is empty. */ export declare const fromNullable: <T>(value: Nullable<T>) => T | undefined; /** * Extracts the value from a Candid-style variant representation of an optional value, * ensuring the value is defined. Throws an error if the array is empty or the value is nullish. * * @template T The type of the value. * @param {Nullable<T>} value - A Candid-style variant representing an optional value. * @returns {T} The extracted value. * @throws {Error} If the array is empty or the value is nullish. */ export declare const fromDefinedNullable: <T>(value: Nullable<T>) => T; /** * Extracts the value from a nullish Candid-style variant representation. * * @template T The type of the value. * @param {NullishNullable<T>} value - A Candid-style variant or `undefined`. * @returns {T | undefined} The extracted value, or `undefined` if the input is nullish or the array is empty. */ export declare const fromNullishNullable: <T>(value: NullishNullable<T>) => T | undefined;