@stacksjs/arrays 0.49.0 → 0.49.2

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/dist/index.d.ts CHANGED
@@ -41,6 +41,12 @@ export declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>
41
41
  * @category Array
42
42
  */
43
43
  export declare function uniq<T>(array: readonly T[]): T[];
44
+ /**
45
+ * Unique an Array by a custom equality function
46
+ *
47
+ * @category Array
48
+ */
49
+ export declare function uniqueBy<T>(array: readonly T[], equalFn: (a: any, b: any) => boolean): T[];
44
50
  /**
45
51
  * Get last item
46
52
  *
package/dist/index.mjs CHANGED
@@ -42,6 +42,14 @@ export function partition(array, ...filters) {
42
42
  export function uniq(array) {
43
43
  return Array.from(new Set(array));
44
44
  }
45
+ export function uniqueBy(array, equalFn) {
46
+ return array.reduce((acc, cur) => {
47
+ const index = acc.findIndex((item) => equalFn(cur, item));
48
+ if (index === -1)
49
+ acc.push(cur);
50
+ return acc;
51
+ }, []);
52
+ }
45
53
  export function last(array) {
46
54
  return at(array, -1);
47
55
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/arrays",
3
3
  "type": "module",
4
- "version": "0.49.0",
4
+ "version": "0.49.2",
5
5
  "packageManager": "pnpm@7.25.0",
6
6
  "description": "The Stacks array utilities.",
7
7
  "author": "Chris Breuer",
@@ -39,12 +39,12 @@
39
39
  "pnpm": ">=7.25.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@stacksjs/utils": "0.49.0"
42
+ "@stacksjs/utils": "0.49.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "mkdist": "^1.1.0",
46
46
  "typescript": "^4.9.4",
47
- "@stacksjs/testing": "0.49.0"
47
+ "@stacksjs/testing": "0.49.2"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "mkdist -d",