@ocavue/utils 1.2.0 → 1.3.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/index.d.ts CHANGED
@@ -23,6 +23,48 @@ declare class DefaultMap<K$1, V> extends Map<K$1, V> {
23
23
  constructor(defaultFactory: () => V, iterable?: Iterable<readonly [K$1, V]>);
24
24
  get(key: K$1): V;
25
25
  }
26
+ /**
27
+ * A weak map that automatically creates values for missing keys using a factory function.
28
+ *
29
+ * Similar to DefaultMap but uses WeakMap as the base, allowing garbage collection of keys.
30
+ */
31
+ declare class DefaultWeakMap<K$1 extends WeakKey, V> extends WeakMap<K$1, V> {
32
+ private readonly defaultFactory;
33
+ constructor(defaultFactory: () => V, entries?: readonly (readonly [K$1, V])[] | null);
34
+ get(key: K$1): V;
35
+ }
36
+ /**
37
+ * A map that counts occurrences of keys.
38
+ *
39
+ * Similar to Python's [Counter](https://docs.python.org/3.13/library/collections.html#collections.Counter).
40
+ */
41
+ declare class Counter<K$1> extends DefaultMap<K$1, number> {
42
+ constructor(iterable?: Iterable<readonly [K$1, number]>);
43
+ /**
44
+ * Increments the count for a key by a given amount (default 1).
45
+ */
46
+ increment(key: K$1, amount?: number): void;
47
+ /**
48
+ * Decrements the count for a key by a given amount (default 1).
49
+ */
50
+ decrement(key: K$1, amount?: number): void;
51
+ }
52
+ /**
53
+ * A weak map that counts occurrences of object keys.
54
+ *
55
+ * Similar to Counter but uses WeakMap as the base, allowing garbage collection of keys.
56
+ */
57
+ declare class WeakCounter<K$1 extends WeakKey> extends DefaultWeakMap<K$1, number> {
58
+ constructor(entries?: readonly (readonly [K$1, number])[] | null);
59
+ /**
60
+ * Increments the count for a key by a given amount (default 1).
61
+ */
62
+ increment(key: K$1, amount?: number): void;
63
+ /**
64
+ * Decrements the count for a key by a given amount (default 1).
65
+ */
66
+ decrement(key: K$1, amount?: number): void;
67
+ }
26
68
  //#endregion
27
69
  //#region src/dom.d.ts
28
70
  /**
@@ -233,5 +275,5 @@ declare function once<T>(fn: () => T): () => T;
233
275
  */
234
276
  declare function sleep(ms: number): Promise<void>;
235
277
  //#endregion
236
- export { DefaultMap, type ObjectEntries, formatBytes, getDocument, getDocumentElement, getId, getWindow, isDeepEqual, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMap, isMathMLElement, isNodeLike, isObject, isSVGElement, isSet, isShadowRoot, isTextNode, isWindowLike, mapGroupBy, mapValues, objectEntries, objectGroupBy, once, sleep };
278
+ export { Counter, DefaultMap, DefaultWeakMap, type ObjectEntries, WeakCounter, formatBytes, getDocument, getDocumentElement, getId, getWindow, isDeepEqual, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMap, isMathMLElement, isNodeLike, isObject, isSVGElement, isSet, isShadowRoot, isTextNode, isWindowLike, mapGroupBy, mapValues, objectEntries, objectGroupBy, once, sleep };
237
279
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/checker.ts","../src/default-map.ts","../src/dom.ts","../src/format-bytes.ts","../src/get-id.ts","../src/is-deep-equal.ts","../src/map-group-by.ts","../src/map-values.ts","../src/object-entries.ts","../src/object-group-by.ts","../src/once.ts","../src/sleep.ts"],"sourcesContent":[],"mappings":";;AAGA;AASA;AAOgB,iBAhBA,QAAA,CAgBmC,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAdvC,MAcuC,CAAA,MAAA,GAAA,MAAA,GAAA,MAAA,EAAA,OAAA,CAAA;;;;ACdtC,iBDOG,KAAA,CCPO,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IDOyB,GCPzB,CAAA,OAAA,EAAA,OAAA,CAAA;;;;AAG8C,iBDWrD,KAAA,CCXqD,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IDWrB,GCXqB,CAAA,OAAA,CAAA;;;;ADLrE;AASA;AAOA;;cCda,2BAAyB,IAAI,KAAG;;EAAhC,WAAA,CAAA,cAA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AOA;AAOA;AAOA;AAOA;AAUA;AAOA;AAOA;AAOA;AAOA;AAWA;AAQA;;;;;;;AAqBA;;;;;;;AAkBA;;;;;;;;cM3Ea,0BAA0B,0BAChC,MACF,cAAc;;;;;;;;APjD+B,cQ6BrC,aR7BqC,EAAA,CAAA,YQ6BX,WR7BW,EAAA,CAAA,CAAA,CAAA,KAAA,EQ8BzC,QR9ByC,CQ8BhC,CR9BgC,CAAA,EAAA,WAAA,EAAA,CAAA,IAAA,EQ+B5B,CR/B4B,EAAA,KAAA,EAAA,MAAA,EAAA,GQ+BP,GR/BO,EAAA,GQgC7C,ORhC6C,CQgCrC,MRhCqC,CQgC9B,GRhC8B,EQgC3B,CRhC2B,EAAA,CAAA,CAAA;;;;ADLlD;AASA;AAOA;;;;ACdA;;;;;;AAGkD,iBSKlC,ITLkC,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,GAAA,GSKhB,CTLgB,CAAA,EAAA,GAAA,GSKN,CTLM;;;;ADLlD;AASA;AAOgB,iBWhBA,KAAA,CXgBmC,EAAA,EAAA,MAAA,CAAA,EWhBhB,OXgBgB,CAAA,IAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/checker.ts","../src/default-map.ts","../src/dom.ts","../src/format-bytes.ts","../src/get-id.ts","../src/is-deep-equal.ts","../src/map-group-by.ts","../src/map-values.ts","../src/object-entries.ts","../src/object-group-by.ts","../src/once.ts","../src/sleep.ts"],"sourcesContent":[],"mappings":";;AAGA;AASA;AAOgB,iBAhBA,QAAA,CAgBmC,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAdvC,MAcuC,CAAA,MAAA,GAAA,MAAA,GAAA,MAAA,EAAA,OAAA,CAAA;;;;ACdtC,iBDOG,KAAA,CCPO,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IDOyB,GCPzB,CAAA,OAAA,EAAA,OAAA,CAAA;;;;AAG8C,iBDWrD,KAAA,CCXqD,KAAA,EAAA,OAAA,CAAA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,GAAA,CAAA,CAAA,GAAA,QAAI,MOEV,CPFU,GAAA,COEL,CPFK,EOEF,CPFE,COEA,CPFA,CAAA,CAAA,EARc,CAAA,MOW9B,CPX8B,CAAA;;AAuBtC;;;;;;;;;;;AA0BA;;;;;;;;AAyBA;;;;;;;;;;;ACzEA;AAOA;AAOA;AAOA;AAOA;AAUA;AAOgB,cMIH,aNJqB,EAAA,CAAO,UMIF,MNJiB,CAAA,MAAgB,EAAA,GAAA,CAAA,CAAA,CAAA,GAAA,EMKjE,CNLiE,EAAA,GMMnE,aNNmE,CMMrD,CNNqD,CAAA,EAAA;;;;;;;;AD3CtB,cQ+BrC,aR/BqC,EAAA,CAAA,YQ+BX,WR/BW,EAAA,CAAA,CAAA,CAAA,KAAA,EQgCzC,QRhCyC,CQgChC,CRhCgC,CAAA,EAAA,WAAA,EAAA,CAAA,IAAA,EQiC5B,CRjC4B,EAAA,KAAA,EAAA,MAAA,EAAA,GQiCP,GRjCO,EAAA,GQkC7C,ORlC6C,CQkCrC,MRlCqC,CQkC9B,GRlC8B,EQkC3B,CRlC2B,EAAA,CAAA,CAAA;;;;ADLlD;AASA;AAOA;;;;ACdA;;;;;;AAGkD,iBSKlC,ITLkC,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,GAAA,GSKhB,CTLgB,CAAA,EAAA,GAAA,GSKN,CTLM;;;;ADLlD;AASA;AAOgB,iBWhBA,KAAA,CXgBmC,EAAA,EAAA,MAAA,CAAA,EWhBhB,OXgBgB,CAAA,IAAA,CAAA"}
package/dist/index.js CHANGED
@@ -1,122 +1,84 @@
1
- //#region src/checker.ts
2
- /**
3
- * Checks if the given value is an object.
4
- */
5
1
  function isObject(value) {
6
- return value != null && typeof value === "object";
2
+ return typeof value == "object" && !!value;
7
3
  }
8
- /**
9
- * Checks if the given value is a Map.
10
- */
11
4
  function isMap(value) {
12
5
  return value instanceof Map;
13
6
  }
14
- /**
15
- * Checks if the given value is a Set.
16
- */
17
7
  function isSet(value) {
18
8
  return value instanceof Set;
19
9
  }
20
-
21
- //#endregion
22
- //#region src/default-map.ts
23
- /**
24
- * A map that automatically creates values for missing keys using a factory function.
25
- *
26
- * Similar to Python's [defaultdict](https://docs.python.org/3.13/library/collections.html#collections.defaultdict).
27
- */
28
10
  var DefaultMap = class extends Map {
29
11
  constructor(defaultFactory, iterable) {
30
- super(iterable);
31
- this.defaultFactory = defaultFactory;
12
+ super(iterable), this.defaultFactory = defaultFactory;
32
13
  }
33
14
  get(key) {
34
15
  if (this.has(key)) return super.get(key);
35
- const value = this.defaultFactory();
36
- this.set(key, value);
37
- return value;
16
+ let value = this.defaultFactory();
17
+ return this.set(key, value), value;
18
+ }
19
+ }, DefaultWeakMap = class extends WeakMap {
20
+ constructor(defaultFactory, entries) {
21
+ super(entries), this.defaultFactory = defaultFactory;
22
+ }
23
+ get(key) {
24
+ if (this.has(key)) return super.get(key);
25
+ let value = this.defaultFactory();
26
+ return this.set(key, value), value;
27
+ }
28
+ }, Counter = class extends DefaultMap {
29
+ constructor(iterable) {
30
+ super(() => 0, iterable);
31
+ }
32
+ increment(key, amount = 1) {
33
+ this.set(key, this.get(key) + amount);
34
+ }
35
+ decrement(key, amount = 1) {
36
+ this.set(key, this.get(key) - amount);
37
+ }
38
+ }, WeakCounter = class extends DefaultWeakMap {
39
+ constructor(entries) {
40
+ super(() => 0, entries);
41
+ }
42
+ increment(key, amount = 1) {
43
+ this.set(key, this.get(key) + amount);
44
+ }
45
+ decrement(key, amount = 1) {
46
+ this.set(key, this.get(key) - amount);
38
47
  }
39
48
  };
40
-
41
- //#endregion
42
- //#region src/dom-node-type.ts
43
- const ELEMENT_NODE = 1;
44
- const TEXT_NODE = 3;
45
- const DOCUMENT_NODE = 9;
46
- const DOCUMENT_FRAGMENT_NODE = 11;
47
-
48
- //#endregion
49
- //#region src/dom.ts
50
- /**
51
- * Checks if the given DOM node is an Element.
52
- */
53
49
  function isElement(node) {
54
- return node.nodeType === ELEMENT_NODE;
50
+ return node.nodeType === 1;
55
51
  }
56
- /**
57
- * Checks if the given DOM node is a Text node.
58
- */
59
52
  function isTextNode(node) {
60
- return node.nodeType === TEXT_NODE;
53
+ return node.nodeType === 3;
61
54
  }
62
- /**
63
- * Checks if the given DOM node is an HTMLElement.
64
- */
65
55
  function isHTMLElement(node) {
66
56
  return isElement(node) && node.namespaceURI === "http://www.w3.org/1999/xhtml";
67
57
  }
68
- /**
69
- * Checks if the given DOM node is an SVGElement.
70
- */
71
58
  function isSVGElement(node) {
72
59
  return isElement(node) && node.namespaceURI === "http://www.w3.org/2000/svg";
73
60
  }
74
- /**
75
- * Checks if the given DOM node is an MathMLElement.
76
- */
77
61
  function isMathMLElement(node) {
78
62
  return isElement(node) && node.namespaceURI === "http://www.w3.org/1998/Math/MathML";
79
63
  }
80
- /**
81
- * Checks if the given DOM node is a Document.
82
- */
83
64
  function isDocument(node) {
84
- return node.nodeType === DOCUMENT_NODE;
65
+ return node.nodeType === 9;
85
66
  }
86
- /**
87
- * Checks if the given DOM node is a DocumentFragment.
88
- */
89
67
  function isDocumentFragment(node) {
90
- return node.nodeType === DOCUMENT_FRAGMENT_NODE;
68
+ return node.nodeType === 11;
91
69
  }
92
- /**
93
- * Checks if the given DOM node is a ShadowRoot.
94
- */
95
70
  function isShadowRoot(node) {
96
71
  return isDocumentFragment(node) && "host" in node && isElementLike(node.host);
97
72
  }
98
- /**
99
- * Checks if an unknown value is likely a DOM node.
100
- */
101
73
  function isNodeLike(value) {
102
74
  return isObject(value) && value.nodeType !== void 0;
103
75
  }
104
- /**
105
- * Checks if an unknown value is likely a DOM element.
106
- */
107
76
  function isElementLike(value) {
108
- return isObject(value) && value.nodeType === ELEMENT_NODE && typeof value.nodeName === "string";
77
+ return isObject(value) && value.nodeType === 1 && typeof value.nodeName == "string";
109
78
  }
110
- /**
111
- * Checks if the given value is likely a Window object.
112
- */
113
79
  function isWindowLike(value) {
114
80
  return isObject(value) && value.window === value;
115
81
  }
116
- /**
117
- * Gets the window object for the given target or the global window object if no
118
- * target is provided.
119
- */
120
82
  function getWindow(target) {
121
83
  if (target) {
122
84
  if (isShadowRoot(target)) return getWindow(target.host);
@@ -125,282 +87,94 @@ function getWindow(target) {
125
87
  }
126
88
  return window;
127
89
  }
128
- /**
129
- * Gets the document for the given target or the global document if no target is
130
- * provided.
131
- */
132
90
  function getDocument(target) {
133
- if (target) {
134
- if (isWindowLike(target)) return target.document;
135
- if (isDocument(target)) return target;
136
- return target.ownerDocument || document;
137
- }
138
- return document;
91
+ return target ? isWindowLike(target) ? target.document : isDocument(target) ? target : target.ownerDocument || document : document;
139
92
  }
140
- /**
141
- * Gets a reference to the root node of the document based on the given target.
142
- */
143
93
  function getDocumentElement(target) {
144
94
  return getDocument(target).documentElement;
145
95
  }
146
-
147
- //#endregion
148
- //#region src/format-bytes.ts
149
- /**
150
- * Formats a number of bytes into a human-readable string.
151
- * @param bytes - The number of bytes to format.
152
- * @returns A string representing the number of bytes in a human-readable format.
153
- */
154
96
  function formatBytes(bytes) {
155
- const units = [
97
+ let units = [
156
98
  "B",
157
99
  "KB",
158
100
  "MB",
159
101
  "GB"
160
- ];
161
- let unitIndex = 0;
162
- let num = bytes;
163
- while (Math.abs(num) >= 1024 && unitIndex < units.length - 1) {
164
- num /= 1024;
165
- unitIndex++;
166
- }
167
- const fraction = unitIndex === 0 && num % 1 === 0 ? 0 : 1;
102
+ ], unitIndex = 0, num = bytes;
103
+ for (; Math.abs(num) >= 1024 && unitIndex < units.length - 1;) num /= 1024, unitIndex++;
104
+ let fraction = unitIndex === 0 && num % 1 == 0 ? 0 : 1;
168
105
  return `${num.toFixed(fraction)}${units[unitIndex]}`;
169
106
  }
170
-
171
- //#endregion
172
- //#region src/get-id.ts
173
- let id = 0;
174
- /**
175
- * Generates a unique positive integer.
176
- */
107
+ let id = 0, maxSafeInteger = 2 ** 53 - 1;
177
108
  function getId() {
178
- id = id % Number.MAX_SAFE_INTEGER + 1;
179
- return id;
109
+ return id++, id >= maxSafeInteger && (id = 1), id;
180
110
  }
181
-
182
- //#endregion
183
- //#region src/is-deep-equal.ts
184
- /**
185
- * Whether two values are deeply equal.
186
- */
187
111
  function isDeepEqual(a, b) {
188
- if (a === b) return true;
189
- if (a == null || b == null) return false;
190
- const aType = typeof a;
191
- if (aType !== typeof b) return false;
192
- if (aType === "number" && Number.isNaN(a) && Number.isNaN(b)) return true;
112
+ if (a === b) return !0;
113
+ if (a == null || b == null) return !1;
114
+ let aType = typeof a;
115
+ if (aType !== typeof b) return !1;
116
+ if (aType === "number" && Number.isNaN(a) && Number.isNaN(b)) return !0;
193
117
  if (Array.isArray(a)) {
194
- if (!Array.isArray(b)) return false;
195
- if (a.length !== b.length) return false;
196
- const size = a.length;
197
- for (let i = 0; i < size; i++) if (!isDeepEqual(a[i], b[i])) return false;
198
- return true;
118
+ if (!Array.isArray(b) || a.length !== b.length) return !1;
119
+ let size = a.length;
120
+ for (let i = 0; i < size; i++) if (!isDeepEqual(a[i], b[i])) return !1;
121
+ return !0;
199
122
  }
200
123
  if (isSet(a)) {
201
- if (!isSet(b)) return false;
202
- if (a.size !== b.size) return false;
203
- for (const value of a) if (!b.has(value)) return false;
204
- return true;
124
+ if (!isSet(b) || a.size !== b.size) return !1;
125
+ for (let value of a) if (!b.has(value)) return !1;
126
+ return !0;
205
127
  }
206
128
  if (isMap(a)) {
207
- if (!isMap(b)) return false;
208
- if (a.size !== b.size) return false;
209
- for (const key of a.keys()) {
210
- if (!b.has(key)) return false;
211
- if (!isDeepEqual(a.get(key), b.get(key))) return false;
212
- }
213
- return true;
129
+ if (!isMap(b) || a.size !== b.size) return !1;
130
+ for (let key of a.keys()) if (!b.has(key) || !isDeepEqual(a.get(key), b.get(key))) return !1;
131
+ return !0;
214
132
  }
215
- if (typeof a === "object" && typeof b === "object") {
216
- const aKeys = Object.keys(a);
217
- const bKeys = Object.keys(b);
218
- if (aKeys.length !== bKeys.length) return false;
219
- for (const key of aKeys) if (!isDeepEqual(a[key], b[key])) return false;
220
- return true;
133
+ if (typeof a == "object" && typeof b == "object") {
134
+ let aKeys = Object.keys(a), bKeys = Object.keys(b);
135
+ if (aKeys.length !== bKeys.length) return !1;
136
+ for (let key of aKeys) if (!isDeepEqual(a[key], b[key])) return !1;
137
+ return !0;
221
138
  }
222
- return false;
139
+ return !1;
223
140
  }
224
-
225
- //#endregion
226
- //#region src/map-group-by.ts
227
- /**
228
- * @internal
229
- */
230
141
  function mapGroupByPolyfill(items, keySelector) {
231
- const map = /* @__PURE__ */ new Map();
232
- let index = 0;
233
- for (const item of items) {
234
- const key = keySelector(item, index);
235
- const group = map.get(key);
236
- if (group) group.push(item);
237
- else map.set(key, [item]);
238
- index++;
142
+ let map = /* @__PURE__ */ new Map(), index = 0;
143
+ for (let item of items) {
144
+ let key = keySelector(item, index), group = map.get(key);
145
+ group ? group.push(item) : map.set(key, [item]), index++;
239
146
  }
240
147
  return map;
241
148
  }
242
- /**
243
- * @internal
244
- */
245
149
  function mapGroupByNative(items, keySelector) {
246
150
  return Map.groupBy(items, keySelector);
247
151
  }
248
- /**
249
- * A polyfill for the `Map.groupBy` static method.
250
- *
251
- * @public
252
- */
253
- const mapGroupBy = !!Map.groupBy ? mapGroupByNative : mapGroupByPolyfill;
254
-
255
- //#endregion
256
- //#region src/map-values.ts
257
- /**
258
- * Creates a new object with the same keys as the input object, but with values
259
- * transformed by the provided callback function. Similar to `Array.prototype.map()`
260
- * but for object values.
261
-
262
- * @param object - The object whose values will be transformed.
263
- * @param callback - A function that transforms each value. Receives the value and
264
- * its corresponding key as arguments.
265
- * @returns A new object with the same keys but transformed values.
266
- *
267
- * @example
268
- * ```typescript
269
- * const prices = { apple: 1, banana: 2, orange: 3 }
270
- * const doubled = mapValues(prices, (price) => price * 2)
271
- * // Result: { apple: 2, banana: 4, orange: 6 }
272
- * ```
273
- *
274
- * @example
275
- * ```typescript
276
- * const users = { john: 25, jane: 30, bob: 35 }
277
- * const greetings = mapValues(users, (age, name) => `${name} is ${age} years old`)
278
- * // Result: { john: 'john is 25 years old', jane: 'jane is 30 years old', bob: 'bob is 35 years old' }
279
- * ```
280
- *
281
- * @example
282
- * ```typescript
283
- * const data = { a: '1', b: '2', c: '3' }
284
- * const numbers = mapValues(data, (str) => parseInt(str, 10))
285
- * // Result: { a: 1, b: 2, c: 3 }
286
- * ```
287
- *
288
- * @public
289
- */
152
+ const mapGroupBy = /* @__PURE__ */ (() => !!Map.groupBy)() ? mapGroupByNative : mapGroupByPolyfill;
290
153
  function mapValues(object, callback) {
291
154
  let result = {};
292
- for (const [key, value] of Object.entries(object)) result[key] = callback(value, key);
155
+ for (let [key, value] of Object.entries(object)) result[key] = callback(value, key);
293
156
  return result;
294
157
  }
295
-
296
- //#endregion
297
- //#region src/object-entries.ts
298
- /**
299
- * A type-safe wrapper around `Object.entries()` that preserves the exact types of object keys
300
- * and values. Unlike the standard `Object.entries()` which returns `[string, any][]`, this
301
- * function returns an array of tuples where each tuple is precisely typed according to the
302
- * input object's structure.
303
- *
304
- * This is particularly useful when working with objects that have known, fixed property types
305
- * and you want to maintain type safety when iterating over entries.
306
- *
307
- * @example
308
- * ```typescript
309
- * const myObject = { a: 1, b: 'hello', c: true } as const
310
- * const entries = objectEntries(myObject)
311
- * // Type: (["a", 1] | ["b", "hello"] | ["c", true])[]
312
- *
313
- * for (const [key, value] of entries) {
314
- * // key is typed as "a" | "b" | "c"
315
- * // value is typed as 1 | "hello" | true
316
- * console.log(`${key}: ${value}`)
317
- * }
318
- * ```
319
- *
320
- * @example
321
- * ```typescript
322
- * interface User {
323
- * name: string
324
- * age: number
325
- * active: boolean
326
- * }
327
- *
328
- * const user: User = { name: 'Alice', age: 30, active: true }
329
- * const entries = objectEntries(user)
330
- * // Type: (["name", string] | ["age", number] | ["active", boolean])[]
331
- * ```
332
- *
333
- * @public
334
- */
335
158
  const objectEntries = Object.entries;
336
-
337
- //#endregion
338
- //#region src/object-group-by.ts
339
- /**
340
- * @internal
341
- */
342
159
  function objectGroupByPolyfill(items, keySelector) {
343
- const result = {};
344
- let index = 0;
345
- for (const item of items) {
346
- const key = keySelector(item, index);
347
- const group = result[key];
348
- if (group) group.push(item);
349
- else result[key] = [item];
350
- index++;
160
+ let result = {}, index = 0;
161
+ for (let item of items) {
162
+ let key = keySelector(item, index), group = result[key];
163
+ group ? group.push(item) : result[key] = [item], index++;
351
164
  }
352
165
  return result;
353
166
  }
354
- /**
355
- * @internal
356
- */
357
167
  function objectGroupByNative(items, keySelector) {
358
168
  return Object.groupBy(items, keySelector);
359
169
  }
360
- /**
361
- * A polyfill for the `Object.groupBy` static method.
362
- *
363
- * @public
364
- */
365
- const objectGroupBy = !!Object.groupBy ? objectGroupByNative : objectGroupByPolyfill;
366
-
367
- //#endregion
368
- //#region src/once.ts
369
- /**
370
- * Creates a function that will only execute the provided function once.
371
- * Subsequent calls will return the cached result from the first execution.
372
- *
373
- * @param fn The function to execute once
374
- * @returns A function that will only execute the provided function once
375
- * @example
376
- * ```ts
377
- * const getValue = once(() => expensiveOperation())
378
- * getValue() // executes expensiveOperation
379
- * getValue() // returns cached result
380
- * ```
381
- */
170
+ const objectGroupBy = /* @__PURE__ */ (() => !!Object.groupBy)() ? objectGroupByNative : objectGroupByPolyfill;
382
171
  function once(fn) {
383
- let called = false;
384
- let result;
385
- return () => {
386
- if (!called) {
387
- result = fn();
388
- called = true;
389
- fn = void 0;
390
- }
391
- return result;
392
- };
172
+ let called = !1, result;
173
+ return () => (called || (result = fn(), called = !0, fn = void 0), result);
393
174
  }
394
-
395
- //#endregion
396
- //#region src/sleep.ts
397
- /**
398
- * Sleep for a given number of milliseconds.
399
- */
400
175
  function sleep(ms) {
401
176
  return new Promise((resolve) => setTimeout(resolve, ms));
402
177
  }
178
+ export { Counter, DefaultMap, DefaultWeakMap, WeakCounter, formatBytes, getDocument, getDocumentElement, getId, getWindow, isDeepEqual, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMap, isMathMLElement, isNodeLike, isObject, isSVGElement, isSet, isShadowRoot, isTextNode, isWindowLike, mapGroupBy, mapValues, objectEntries, objectGroupBy, once, sleep };
403
179
 
404
- //#endregion
405
- export { DefaultMap, formatBytes, getDocument, getDocumentElement, getId, getWindow, isDeepEqual, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMap, isMathMLElement, isNodeLike, isObject, isSVGElement, isSet, isShadowRoot, isTextNode, isWindowLike, mapGroupBy, mapValues, objectEntries, objectGroupBy, once, sleep };
406
180
  //# sourceMappingURL=index.js.map