UNPKG

@dfinity/utils

Version:

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

35 lines (34 loc) 1.71 kB
/** * 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 {[] | [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) => [] | [T]; /** * Extracts the value from a Candid-style variant representation of an optional value. * * @template T The type of the value. * @param {[] | [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: [] | [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 {[] | [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: [] | [T]) => T; /** * Extracts the value from a nullish Candid-style variant representation. * * @template T The type of the value. * @param {([] | [T]) | undefined} 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: ([] | [T]) | undefined) => T | undefined;