From 7b52b25114115e1dc2463028d6cef3f6c0875569 Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Fri, 19 Jun 2026 11:35:35 +0200 Subject: [PATCH 1/3] feat: add functional utilities chore: remove `@` in github related links --- README.md | 4 ++-- package.json | 6 +++--- src/functional/identity.ts | 7 +++++++ src/functional/index.ts | 2 ++ src/functional/noop.ts | 4 ++++ src/index.ts | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/functional/identity.ts create mode 100644 src/functional/index.ts create mode 100644 src/functional/noop.ts diff --git a/README.md b/README.md index eeff822..f0d4f4f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![NPM version](https://img.shields.io/npm/v/@zakodium/utils.svg)](https://www.npmjs.com/package/@zakodium/utils) [![npm download](https://img.shields.io/npm/dm/@zakodium/utils.svg)](https://www.npmjs.com/package/@zakodium/utils) -[![test coverage](https://img.shields.io/codecov/c/github/@zakodium/utils.svg)](https://codecov.io/gh/@zakodium/utils) -[![license](https://img.shields.io/npm/l/@zakodium/utils.svg)](https://github.com/@zakodium/utils/blob/main/LICENSE) +[![test coverage](https://img.shields.io/codecov/c/github/zakodium/utils.svg)](https://app.codecov.io/gh/zakodium/utils) +[![license](https://img.shields.io/github/license/zakodium/utils.svg)](https://github.com/zakodium/utils/blob/main/LICENSE) Small utilities by zakodium for zakodium. diff --git a/package.json b/package.json index efda47c..fb60910 100644 --- a/package.json +++ b/package.json @@ -41,10 +41,10 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/@zakodium/utils.git" + "url": "git+https://github.com/zakodium/utils.git" }, "bugs": { - "url": "https://github.com/@zakodium/utils/issues" + "url": "https://github.com/zakodium/utils/issues" }, - "homepage": "https://github.com/@zakodium/utils#readme" + "homepage": "https://github.com/zakodium/utils#readme-ov-file" } diff --git a/src/functional/identity.ts b/src/functional/identity.ts new file mode 100644 index 0000000..52e4c51 --- /dev/null +++ b/src/functional/identity.ts @@ -0,0 +1,7 @@ +/** + * Identity function. + * @param value + */ +export function identity(value: T): T { + return value; +} diff --git a/src/functional/index.ts b/src/functional/index.ts new file mode 100644 index 0000000..d1ab215 --- /dev/null +++ b/src/functional/index.ts @@ -0,0 +1,2 @@ +export * from './noop.ts'; +export * from './identity.ts'; diff --git a/src/functional/noop.ts b/src/functional/noop.ts new file mode 100644 index 0000000..94cab0b --- /dev/null +++ b/src/functional/noop.ts @@ -0,0 +1,4 @@ +/** + * No operation function. + */ +export function noop() {} diff --git a/src/index.ts b/src/index.ts index 0445be0..efe3633 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,2 @@ export * from './types/index.ts'; +export * from './functional/index.ts'; From bc723a6b12ceb551d4289a11c448397878bec0ac Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Fri, 19 Jun 2026 11:38:15 +0200 Subject: [PATCH 2/3] docs: remove utils list from README it is redundant with the API Reference --- README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README.md b/README.md index f0d4f4f..0df8c93 100644 --- a/README.md +++ b/README.md @@ -29,20 +29,6 @@ assertDefinedNotNull(value); // throws if value is null or undefined - [API Reference](https://zakodium.github.io/utils/) -### Assertions - -With types mutations. - -- `function assert(value: unknown, message?: string | (() => string)): asserts value;` -- `function assertUnreachable(value: never): never;` -- `function assertDefined(value: T): asserts value is Exclude;` -- `function assertDefinedNotNull(value: T): asserts value is Exclude;` - -### Casting - -- `function is(value: unknown, condition: boolean): value is Output;` -- `function cast(value: unknown): asserts value is Output;` - ## Features that could be added later - Iterable helpers like `map`, `filter` and so on. From 0c8444cfbfdd0371066fee3c7c457433ff72221c Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Fri, 19 Jun 2026 11:45:24 +0200 Subject: [PATCH 3/3] test: add unit tests for identity and noop --- src/functional/identity.test.ts | 29 +++++++++++++++++++++++++++++ src/functional/noop.test.ts | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/functional/identity.test.ts create mode 100644 src/functional/noop.test.ts diff --git a/src/functional/identity.test.ts b/src/functional/identity.test.ts new file mode 100644 index 0000000..d1ba45b --- /dev/null +++ b/src/functional/identity.test.ts @@ -0,0 +1,29 @@ +import { expect, test } from 'vitest'; + +import { identity } from './identity.ts'; + +test('should return undefined', () => { + expect(identity(undefined)).toBeUndefined(); +}); + +test('should return null', () => { + expect(identity(null)).toBeNull(); +}); + +test('should return 0', () => { + expect(identity(0)).toBe(0); +}); + +test('should return false', () => { + expect(identity(false)).toBe(false); +}); + +test('should return string', () => { + expect(identity('foo')).toBe('foo'); +}); + +test('should return object as-is', () => { + const object = {}; + + expect(identity(object)).toBe(object); +}); diff --git a/src/functional/noop.test.ts b/src/functional/noop.test.ts new file mode 100644 index 0000000..2c0468c --- /dev/null +++ b/src/functional/noop.test.ts @@ -0,0 +1,10 @@ +import { expect, test } from 'vitest'; + +import { noop } from './noop.ts'; + +test('noop should always returns undefined', () => { + expect(noop()).toBeUndefined(); + + // @ts-expect-error check if add truthy arguments continue to return undefined + expect(noop({})).toBeUndefined(); +});