@limitlesspc/std 0.21.1 → 0.23.0

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/array.d.ts CHANGED
@@ -161,9 +161,8 @@ declare function includesAny<T, U>(a: readonly T[], b: readonly U[]): boolean;
161
161
  */
162
162
  declare function includesAll<T, U>(a: readonly T[], b: readonly U[]): boolean;
163
163
  /**
164
- * Returns a new array with items with a unique key
164
+ * Returns the unique items from an array
165
165
  * @param array
166
- * @param key
167
166
  * @example
168
167
  * ```ts
169
168
  * const array = [
@@ -182,6 +181,24 @@ declare function includesAll<T, U>(a: readonly T[], b: readonly U[]): boolean;
182
181
  * // ]
183
182
  */
184
183
  declare function dedupe<T>(array: Iterable<T>): T[];
184
+ /**
185
+ * Returns the unique items from an array defined by a function
186
+ * @param array
187
+ * @example
188
+ * ```ts
189
+ * const array = [
190
+ * "cats",
191
+ * "cat",
192
+ * "dog",
193
+ * "dogs",
194
+ * ];
195
+ * // Two items are considered the duplicated if they share the same first 3 letters
196
+ * console.log(dedupeBy(array, item => item.slice(0, 3))); // [
197
+ * // "cats",
198
+ * // "dog",
199
+ * // ]
200
+ */
201
+ declare function dedupeBy<T>(array: Iterable<T>, key: (item: T) => any): T[];
185
202
  /**
186
203
  * Returns a new array with items with a unique key
187
204
  * @param array
@@ -226,6 +243,6 @@ declare function filterByKey<T>(array: readonly T[], key: keyof T): T[];
226
243
  * // ]
227
244
  * ```
228
245
  */
229
- declare function sortByKeys<T, K extends keyof T>(array: Iterable<T>, key: MaybeArray<K>, compare?: Compare<T[K]>): T[];
246
+ declare function sortByKeys<T, K extends keyof T>(array: T[], key: MaybeArray<K>, compare?: Compare<T[K]>): T[];
230
247
 
231
- export { added, changes, dedupe, dedupeByKey, difference, equal, filterByKey, hasChange, includesAll, includesAny, intersection, remove, removed, sortByKeys, swap, union, unorderedRemove };
248
+ export { added, changes, dedupe, dedupeBy, dedupeByKey, difference, equal, filterByKey, hasChange, includesAll, includesAny, intersection, remove, removed, sortByKeys, swap, union, unorderedRemove };
package/dist/array.js CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  added,
3
3
  changes,
4
4
  dedupe,
5
+ dedupeBy,
5
6
  dedupeByKey,
6
7
  difference,
7
8
  equal,
@@ -16,16 +17,16 @@ import {
16
17
  swap,
17
18
  union,
18
19
  unorderedRemove
19
- } from "./chunk-65SNM7MP.js";
20
- import "./chunk-WBSY6KRH.js";
21
- import "./chunk-MG5VQSTV.js";
22
- import "./chunk-6F4PWJZI.js";
20
+ } from "./chunk-4POIKW4G.js";
21
+ import "./chunk-CCBSTDYA.js";
22
+ import "./chunk-NXILTE26.js";
23
23
  import "./chunk-TMLWLR46.js";
24
24
  import "./chunk-LJSF3QBT.js";
25
25
  export {
26
26
  added,
27
27
  changes,
28
28
  dedupe,
29
+ dedupeBy,
29
30
  dedupeByKey,
30
31
  difference,
31
32
  equal,
@@ -1,4 +1,4 @@
1
- import { uint, Awaitable, AnyFunction, Result } from '../types.js';
1
+ import { Awaitable, uint, AnyFunction, Result } from '../types.js';
2
2
 
3
3
  type Task<T> = () => Awaitable<T>;
4
4
  interface TaskQueueItem<T> {
@@ -1,13 +1,3 @@
1
- import {
2
- Queue
3
- } from "../chunk-DYKZK6B5.js";
4
- import "../chunk-65SNM7MP.js";
5
- import "../chunk-WBSY6KRH.js";
6
- import "../chunk-MG5VQSTV.js";
7
- import "../chunk-6F4PWJZI.js";
8
- import "../chunk-TMLWLR46.js";
9
- import "../chunk-LJSF3QBT.js";
10
-
11
1
  // src/async/queue.ts
12
2
  var TaskQueue = class {
13
3
  constructor(tasks = []) {
@@ -95,12 +85,10 @@ function debounce(func, ms) {
95
85
  async function concurrently(funcs, max) {
96
86
  const tasks = [...funcs];
97
87
  const results = Array.from({ length: tasks.length });
98
- const queue = new Queue(tasks);
99
- const length = queue.size;
100
88
  let i = 0;
101
89
  return new Promise((resolve) => {
102
90
  const next = async () => {
103
- const func = queue.dequeue();
91
+ const func = tasks.shift();
104
92
  if (func) {
105
93
  results[i++] = await func();
106
94
  void next();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  zip
3
- } from "./chunk-WBSY6KRH.js";
3
+ } from "./chunk-CCBSTDYA.js";
4
4
  import {
5
5
  ascend
6
6
  } from "./chunk-TMLWLR46.js";
@@ -90,21 +90,13 @@ function includesAll(a, b) {
90
90
  return b.every((item) => a.includes(item));
91
91
  }
92
92
  function dedupe(array) {
93
- const result = [];
94
- const seen = /* @__PURE__ */ new Set();
95
- for (const item of array) {
96
- if (!seen.has(item)) {
97
- result.push(item);
98
- seen.add(item);
99
- }
100
- }
101
- return result;
93
+ return dedupeBy(array, (x) => x);
102
94
  }
103
- function dedupeByKey(array, key) {
95
+ function dedupeBy(array, key) {
104
96
  const result = [];
105
97
  const seen = /* @__PURE__ */ new Set();
106
98
  for (const item of array) {
107
- const value = item[key];
99
+ const value = key(item);
108
100
  if (!seen.has(value)) {
109
101
  result.push(item);
110
102
  seen.add(value);
@@ -112,11 +104,14 @@ function dedupeByKey(array, key) {
112
104
  }
113
105
  return result;
114
106
  }
107
+ function dedupeByKey(array, key) {
108
+ return dedupeBy(array, (x) => x[key]);
109
+ }
115
110
  function filterByKey(array, key) {
116
111
  return array.filter((item) => item[key]);
117
112
  }
118
113
  function sortByKeys(array, key, compare = ascend) {
119
- return [...array].sort((a, b) => {
114
+ return array.toSorted((a, b) => {
120
115
  const keys = Array.isArray(key) ? key : [key];
121
116
  for (const key2 of keys) {
122
117
  const value1 = a[key2];
@@ -145,6 +140,7 @@ export {
145
140
  includesAny,
146
141
  includesAll,
147
142
  dedupe,
143
+ dedupeBy,
148
144
  dedupeByKey,
149
145
  filterByKey,
150
146
  sortByKeys
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  reverseCurry
3
- } from "./chunk-MG5VQSTV.js";
3
+ } from "./chunk-NXILTE26.js";
4
4
  import {
5
5
  pickByKeys
6
6
  } from "./chunk-LJSF3QBT.js";