From 2dac5195566add3f6ed086fefeeeacae44efad65 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 16 Dec 2024 10:11:06 +0100 Subject: [PATCH 1/8] feat: emptyString utils Signed-off-by: David Dal Busco --- packages/utils/src/utils/nullish.utils.spec.ts | 9 +++++++++ packages/utils/src/utils/nullish.utils.ts | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/utils/src/utils/nullish.utils.spec.ts b/packages/utils/src/utils/nullish.utils.spec.ts index 845ebd6b1..6187135f4 100644 --- a/packages/utils/src/utils/nullish.utils.spec.ts +++ b/packages/utils/src/utils/nullish.utils.spec.ts @@ -42,4 +42,13 @@ describe("nullish-utils", () => { expect(notEmptyString("test")).toBeTruthy(); }); }); + + describe("emptyString", () => { + it("should determine empty", () => { + expect(notEmptyString(null)).toBeTruthy(); + expect(notEmptyString(undefined)).toBeTruthy(); + expect(notEmptyString("")).toBeTruthy(); + expect(notEmptyString("test")).toBeFalsy(); + }); + }); }); diff --git a/packages/utils/src/utils/nullish.utils.ts b/packages/utils/src/utils/nullish.utils.ts index 6b78f4ec1..43084b41e 100644 --- a/packages/utils/src/utils/nullish.utils.ts +++ b/packages/utils/src/utils/nullish.utils.ts @@ -11,3 +11,12 @@ export const nonNullish = ( /** Not null and not undefined and not empty */ export const notEmptyString = (value: string | undefined | null): boolean => nonNullish(value) && value !== ""; + +/** + * Checks if a given value is null, undefined, or an empty string. + * + * @param {string | undefined | null} value - The value to check. + * @returns {boolean} `true` if the value is null, undefined, or an empty string; otherwise, `false`. + */ +export const emptyString = (value: string | undefined | null): boolean => + !notEmptyString(value); From 72de993ee9412200666ac5e35face42fadf0b5d5 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:12:40 +0000 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/utils/README.md b/packages/utils/README.md index 2575e3cd7..7888844ad 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -35,6 +35,7 @@ npm i @dfinity/agent @dfinity/candid @dfinity/principal - [isNullish](#gear-isnullish) - [nonNullish](#gear-nonnullish) - [notEmptyString](#gear-notemptystring) +- [emptyString](#gear-emptystring) - [defaultAgent](#gear-defaultagent) - [createAgent](#gear-createagent) - [createServices](#gear-createservices) @@ -109,6 +110,20 @@ Not null and not undefined and not empty [:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L12) +#### :gear: emptyString + +Checks if a given value is null, undefined, or an empty string. + +| Function | Type | +| ------------- | ------------------------------------------------- | +| `emptyString` | `(value: string or null or undefined) => boolean` | + +Parameters: + +- `value`: - The value to check. + +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L21) + #### :gear: defaultAgent Get a default agent that connects to mainnet with the anonymous identity. From 89d912006eeb1f356e3339ef432e46ab578af0f4 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 16 Dec 2024 10:14:06 +0100 Subject: [PATCH 3/8] docs: add emptyString to changes Signed-off-by: David Dal Busco --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60971750d..754447c93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Expose a few additional types related to snapshots in `ic-management`. - Add support for `get_subnet_types_to_subnets` to `@dfinity/cmc`. - Support `VotingPowerEconomics`, `potential_voting_power` and `deciding_voting_power` in `@dfinity/nns`. +- Add utility `emptyString` (the opposite of existing `notEmptyString`). # 2024.11.27-1230Z From 742dfe95f58189a2c0fa64f3ea4779e8ff9da59d Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 16 Dec 2024 10:28:18 +0100 Subject: [PATCH 4/8] test: works better if you test with the right function Signed-off-by: David Dal Busco --- packages/utils/src/utils/nullish.utils.spec.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/utils/src/utils/nullish.utils.spec.ts b/packages/utils/src/utils/nullish.utils.spec.ts index 6187135f4..bdf688f05 100644 --- a/packages/utils/src/utils/nullish.utils.spec.ts +++ b/packages/utils/src/utils/nullish.utils.spec.ts @@ -1,4 +1,9 @@ -import { isNullish, nonNullish, notEmptyString } from "./nullish.utils"; +import { + emptyString, + isNullish, + nonNullish, + notEmptyString, +} from "./nullish.utils"; describe("nullish-utils", () => { describe("isNullish", () => { @@ -45,10 +50,10 @@ describe("nullish-utils", () => { describe("emptyString", () => { it("should determine empty", () => { - expect(notEmptyString(null)).toBeTruthy(); - expect(notEmptyString(undefined)).toBeTruthy(); - expect(notEmptyString("")).toBeTruthy(); - expect(notEmptyString("test")).toBeFalsy(); + expect(emptyString(null)).toBeTruthy(); + expect(emptyString(undefined)).toBeTruthy(); + expect(emptyString("")).toBeTruthy(); + expect(emptyString("test")).toBeFalsy(); }); }); }); From a57cdd85f36c8281c810fb9d1216a7adbbc8b70d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:29:46 +0000 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/README.md b/packages/utils/README.md index 07c24d04e..a40e71194 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -134,7 +134,7 @@ Parameters: - `value`: - The value to check. -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L21) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L38) #### :gear: defaultAgent From 301ca688ccd9024ed19a2306ecaaa6afe221c9c1 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 16 Dec 2024 10:43:15 +0100 Subject: [PATCH 6/8] feat: rename to isEmptyString Signed-off-by: David Dal Busco --- CHANGELOG.md | 2 +- packages/utils/src/utils/nullish.utils.spec.ts | 10 +++++----- packages/utils/src/utils/nullish.utils.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754447c93..e06383342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Expose a few additional types related to snapshots in `ic-management`. - Add support for `get_subnet_types_to_subnets` to `@dfinity/cmc`. - Support `VotingPowerEconomics`, `potential_voting_power` and `deciding_voting_power` in `@dfinity/nns`. -- Add utility `emptyString` (the opposite of existing `notEmptyString`). +- Add utility `isEmptyString` (the opposite of existing `notEmptyString`). # 2024.11.27-1230Z diff --git a/packages/utils/src/utils/nullish.utils.spec.ts b/packages/utils/src/utils/nullish.utils.spec.ts index bdf688f05..22c028cb6 100644 --- a/packages/utils/src/utils/nullish.utils.spec.ts +++ b/packages/utils/src/utils/nullish.utils.spec.ts @@ -1,5 +1,5 @@ import { - emptyString, + isEmptyString, isNullish, nonNullish, notEmptyString, @@ -50,10 +50,10 @@ describe("nullish-utils", () => { describe("emptyString", () => { it("should determine empty", () => { - expect(emptyString(null)).toBeTruthy(); - expect(emptyString(undefined)).toBeTruthy(); - expect(emptyString("")).toBeTruthy(); - expect(emptyString("test")).toBeFalsy(); + expect(isEmptyString(null)).toBeTruthy(); + expect(isEmptyString(undefined)).toBeTruthy(); + expect(isEmptyString("")).toBeTruthy(); + expect(isEmptyString("test")).toBeFalsy(); }); }); }); diff --git a/packages/utils/src/utils/nullish.utils.ts b/packages/utils/src/utils/nullish.utils.ts index 373220b3e..0a2d4df00 100644 --- a/packages/utils/src/utils/nullish.utils.ts +++ b/packages/utils/src/utils/nullish.utils.ts @@ -35,5 +35,5 @@ export const notEmptyString = (value: string | undefined | null): boolean => * @param {string | undefined | null} value - The value to check. * @returns {boolean} `true` if the value is null, undefined, or an empty string; otherwise, `false`. */ -export const emptyString = (value: string | undefined | null): boolean => +export const isEmptyString = (value: string | undefined | null): boolean => !notEmptyString(value); From fec3588b5a76670cd67eb132aee616b72b58f94a Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 09:44:36 +0000 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/utils/README.md b/packages/utils/README.md index a40e71194..968fd6af8 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -35,7 +35,7 @@ npm i @dfinity/agent @dfinity/candid @dfinity/principal - [isNullish](#gear-isnullish) - [nonNullish](#gear-nonnullish) - [notEmptyString](#gear-notemptystring) -- [emptyString](#gear-emptystring) +- [isEmptyString](#gear-isemptystring) - [defaultAgent](#gear-defaultagent) - [createAgent](#gear-createagent) - [createServices](#gear-createservices) @@ -122,13 +122,13 @@ Parameters: [:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/nullish.utils.ts#L29) -#### :gear: emptyString +#### :gear: isEmptyString Checks if a given value is null, undefined, or an empty string. -| Function | Type | -| ------------- | ------------------------------------------------- | -| `emptyString` | `(value: string or null or undefined) => boolean` | +| Function | Type | +| --------------- | ------------------------------------------------- | +| `isEmptyString` | `(value: string or null or undefined) => boolean` | Parameters: From 92b078a913582e7686aad1b8ccaeb5a624b8d0a2 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 16 Dec 2024 11:05:11 +0100 Subject: [PATCH 8/8] feat: rename to isEmptyString Signed-off-by: David Dal Busco --- packages/utils/src/utils/nullish.utils.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/utils/nullish.utils.spec.ts b/packages/utils/src/utils/nullish.utils.spec.ts index 22c028cb6..307376162 100644 --- a/packages/utils/src/utils/nullish.utils.spec.ts +++ b/packages/utils/src/utils/nullish.utils.spec.ts @@ -48,7 +48,7 @@ describe("nullish-utils", () => { }); }); - describe("emptyString", () => { + describe("isEmptyString", () => { it("should determine empty", () => { expect(isEmptyString(null)).toBeTruthy(); expect(isEmptyString(undefined)).toBeTruthy();