@elyukai/utils 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [0.2.5](https://github.com/elyukai/ts-utils/compare/v0.2.4...v0.2.5) (2026-02-22)
6
+
7
+
8
+ ### Features
9
+
10
+ * add allSame array function ([8cac98b](https://github.com/elyukai/ts-utils/commit/8cac98bd18e3a4ac7f7acb95b57e55ea031630b4))
11
+
5
12
  ## [0.2.4](https://github.com/elyukai/ts-utils/compare/v0.2.3...v0.2.4) (2026-02-20)
6
13
 
7
14
  ## [0.2.3](https://github.com/elyukai/ts-utils/compare/v0.2.2...v0.2.3) (2026-02-20)
@@ -16,3 +16,11 @@ export declare const anySame: <T>(arr: T[], equalityCheck?: (a: T, b: T) => bool
16
16
  * of found duplicates where the values are the indices of these values.
17
17
  */
18
18
  export declare const anySameIndices: <T>(arr: T[], equalityCheck?: (a: T, b: T) => boolean) => number[][];
19
+ /**
20
+ * Checks if all elements in the array are the same. An empty array is considered to satisfy this condition.
21
+ *
22
+ * @param arr The array to check.
23
+ * @param equalityCheck An optional function to determine if two elements are considered the same. Defaults to strict shallow equality.
24
+ * @returns `true` if all elements in the array are the same, otherwise `false`.
25
+ */
26
+ export declare const allSame: <T>(arr: T[], equalityCheck?: (a: T, b: T) => boolean) => boolean;
@@ -2,6 +2,7 @@
2
2
  * Utility functions for filtering arrays.
3
3
  * @module
4
4
  */
5
+ import { isNotEmpty } from "./nonEmpty.js";
5
6
  /**
6
7
  * Filters out duplicate values from an array. Objects are not supported, since
7
8
  * they don’t provide value equality semantics.
@@ -26,3 +27,11 @@ export const anySameIndices = (arr, equalityCheck = (a, b) => a === b) => arr.re
26
27
  : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- The index must exist according to the findIndex above
27
28
  acc.with(accIndex, [...acc[accIndex], index]);
28
29
  }, []);
30
+ /**
31
+ * Checks if all elements in the array are the same. An empty array is considered to satisfy this condition.
32
+ *
33
+ * @param arr The array to check.
34
+ * @param equalityCheck An optional function to determine if two elements are considered the same. Defaults to strict shallow equality.
35
+ * @returns `true` if all elements in the array are the same, otherwise `false`.
36
+ */
37
+ export const allSame = (arr, equalityCheck = (a, b) => a === b) => isNotEmpty(arr) ? arr.every((item) => equalityCheck(item, arr[0])) : true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyukai/utils",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "A set of JavaScript helper functions.",
5
5
  "files": [
6
6
  "dist",