@dfinity/utils
Advanced tools
Comparing version
@@ -8,2 +8,3 @@ export * from "./enums/token.enums"; | ||
export type { CanisterOptions } from "./types/canister.options"; | ||
export * from "./types/did.utils"; | ||
export * from "./types/query-and-update.params"; | ||
@@ -10,0 +11,0 @@ export type { QueryParams } from "./types/query.params"; |
@@ -0,1 +1,2 @@ | ||
import type { Nullable, NullishNullable } from "../types/did.utils"; | ||
/** | ||
@@ -6,5 +7,5 @@ * Converts a value into a Candid-style variant representation of an optional 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. | ||
* @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) => [] | [T]; | ||
export declare const toNullable: <T>(value?: T | null) => Nullable<T>; | ||
/** | ||
@@ -14,6 +15,6 @@ * 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. | ||
* @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: [] | [T]) => T | undefined; | ||
export declare const fromNullable: <T>(value: Nullable<T>) => T | undefined; | ||
/** | ||
@@ -24,7 +25,7 @@ * 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. | ||
* @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: [] | [T]) => T; | ||
export declare const fromDefinedNullable: <T>(value: Nullable<T>) => T; | ||
/** | ||
@@ -34,5 +35,5 @@ * 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`. | ||
* @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: ([] | [T]) | undefined) => T | undefined; | ||
export declare const fromNullishNullable: <T>(value: NullishNullable<T>) => T | undefined; |
{ | ||
"name": "@dfinity/utils", | ||
"version": "2.13.1", | ||
"version": "2.13.2-beta-2025-07-18", | ||
"description": "A collection of utilities and constants for NNS/SNS projects.", | ||
@@ -19,3 +19,3 @@ "license": "Apache-2.0", | ||
"prepack": "npm run build", | ||
"test": "jest" | ||
"test": "vitest" | ||
}, | ||
@@ -51,6 +51,6 @@ "repository": { | ||
"peerDependencies": { | ||
"@dfinity/agent": "^2.0.0", | ||
"@dfinity/candid": "^2.0.0", | ||
"@dfinity/principal": "^2.0.0" | ||
"@dfinity/agent": "*", | ||
"@dfinity/candid": "*", | ||
"@dfinity/principal": "*" | ||
} | ||
} | ||
} |
144
README.md
@@ -88,2 +88,6 @@ # utils-js | ||
Returns: | ||
bigint | FromStringToTokenError | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/parser/token.ts#L12) | ||
@@ -103,2 +107,6 @@ | ||
Returns: | ||
`true` if the argument is null or undefined; otherwise, `false`. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L8) | ||
@@ -118,2 +126,6 @@ | ||
Returns: | ||
`true` if the argument is not null or undefined; otherwise, `false`. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L19) | ||
@@ -133,2 +145,6 @@ | ||
Returns: | ||
`true` if the value is not null, not undefined, and not an empty string; otherwise, `false`. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L29) | ||
@@ -148,2 +164,6 @@ | ||
Returns: | ||
Type predicate indicating if the value is null, undefined, or an empty string. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L39) | ||
@@ -187,2 +207,6 @@ | ||
Returns: | ||
A promise that resolves when the request is done. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/services/query.ts#L36) | ||
@@ -198,2 +222,6 @@ | ||
Returns: | ||
The default agent to use | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/agent.utils.ts#L14) | ||
@@ -344,2 +372,6 @@ | ||
Returns: | ||
A Base32 string encoding the input. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/base32.utils.ts#L21) | ||
@@ -374,2 +406,6 @@ | ||
Returns: | ||
- The base64 encoded string representation of the binary data. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/base64.utils.ts#L7) | ||
@@ -389,2 +425,6 @@ | ||
Returns: | ||
- The Uint8Array representation of the decoded binary data. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/base64.utils.ts#L16) | ||
@@ -420,2 +460,6 @@ | ||
Returns: | ||
The transformed value if it matches a known type, otherwise the original value. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L22) | ||
@@ -444,2 +488,6 @@ | ||
Returns: | ||
The reconstructed value if it matches a known type, otherwise the original value. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L53) | ||
@@ -462,2 +510,6 @@ | ||
Returns: | ||
A promise that resolves to the hex string of the SHA-256 hash. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/crypto.utils.ts#L14) | ||
@@ -480,2 +532,6 @@ | ||
Returns: | ||
A promise that resolves to the hex string of the SHA-256 hash. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/crypto.utils.ts#L31) | ||
@@ -497,2 +553,6 @@ | ||
Returns: | ||
The human-readable duration string. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L43) | ||
@@ -508,2 +568,6 @@ | ||
Returns: | ||
The current timestamp in nanoseconds. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L123) | ||
@@ -523,2 +587,6 @@ | ||
Returns: | ||
The timestamp in nanoseconds. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L132) | ||
@@ -543,2 +611,6 @@ | ||
Returns: | ||
A debounced version of the original function. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/debounce.utils.ts#L13) | ||
@@ -550,5 +622,5 @@ | ||
| Function | Type | | ||
| ------------ | -------------------------------------------------- | | ||
| `toNullable` | `<T>(value?: T or null or undefined) => [] or [T]` | | ||
| Function | Type | | ||
| ------------ | ---------------------------------------------------- | | ||
| `toNullable` | `<T>(value?: T or null or undefined) => Nullable<T>` | | ||
@@ -559,4 +631,8 @@ Parameters: | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L11) | ||
Returns: | ||
A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L12) | ||
#### :gear: fromNullable | ||
@@ -566,5 +642,5 @@ | ||
| Function | Type | | ||
| -------------- | ----------------------------------------- | | ||
| `fromNullable` | `<T>(value: [] or [T]) => T or undefined` | | ||
| Function | Type | | ||
| -------------- | ------------------------------------------- | | ||
| `fromNullable` | `<T>(value: Nullable<T>) => T or undefined` | | ||
@@ -575,4 +651,8 @@ Parameters: | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L21) | ||
Returns: | ||
The extracted value, or `undefined` if the array is empty. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L22) | ||
#### :gear: fromDefinedNullable | ||
@@ -583,5 +663,5 @@ | ||
| Function | Type | | ||
| --------------------- | ---------------------------- | | ||
| `fromDefinedNullable` | `<T>(value: [] or [T]) => T` | | ||
| Function | Type | | ||
| --------------------- | ------------------------------ | | ||
| `fromDefinedNullable` | `<T>(value: Nullable<T>) => T` | | ||
@@ -592,4 +672,8 @@ Parameters: | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L32) | ||
Returns: | ||
The extracted value. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L34) | ||
#### :gear: fromNullishNullable | ||
@@ -599,5 +683,5 @@ | ||
| Function | Type | | ||
| --------------------- | ------------------------------------------------------ | | ||
| `fromNullishNullable` | `<T>(value: [] or [T] or undefined) => T or undefined` | | ||
| Function | Type | | ||
| --------------------- | -------------------------------------------------- | | ||
| `fromNullishNullable` | `<T>(value: NullishNullable<T>) => T or undefined` | | ||
@@ -608,4 +692,8 @@ Parameters: | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L47) | ||
Returns: | ||
The extracted value, or `undefined` if the input is nullish or the array is empty. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/did.utils.ts#L49) | ||
#### :gear: principalToSubAccount | ||
@@ -640,2 +728,6 @@ | ||
Returns: | ||
boolean | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/version.utils.ts#L34) | ||
@@ -739,2 +831,6 @@ | ||
Returns: | ||
The amount of e8s. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/parser/token.ts#L224) | ||
@@ -816,2 +912,6 @@ | ||
Returns: | ||
The amount of ulps. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/parser/token.ts#L324) | ||
@@ -825,2 +925,6 @@ | ||
Returns: | ||
The amount of ulps in e8s precision | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/parser/token.ts#L332) | ||
@@ -862,2 +966,6 @@ | ||
Returns: | ||
A new instance of `AgentManager`. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/agent.utils.ts#L72) | ||
@@ -885,2 +993,6 @@ | ||
Returns: | ||
The HttpAgent associated with the given identity. | ||
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/agent.utils.ts#L85) | ||
@@ -887,0 +999,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
223689
1.13%36
2.86%679
1.8%1002
12.58%4
33.33%