@hyperfrontend/list-utils 0.0.4 → 0.0.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +14 -6
  2. package/README.md +3 -1
  3. package/_dependencies/@hyperfrontend/data-utils/index.cjs.js +214 -0
  4. package/_dependencies/@hyperfrontend/data-utils/index.esm.js +202 -0
  5. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js +7 -0
  6. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js +5 -0
  7. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.cjs.js +8 -0
  8. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.esm.js +7 -0
  9. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js +6 -0
  10. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js +5 -0
  11. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.cjs.js +6 -0
  12. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js +5 -0
  13. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +7 -0
  14. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +5 -0
  15. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +7 -0
  16. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +5 -0
  17. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js +6 -0
  18. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js +5 -0
  19. package/bundle/index.iife.js +119 -50
  20. package/bundle/index.iife.min.js +1 -2
  21. package/bundle/index.umd.js +119 -50
  22. package/bundle/index.umd.min.js +1 -2
  23. package/index.cjs.js +85 -122
  24. package/index.d.ts +169 -8
  25. package/index.d.ts.map +1 -1
  26. package/index.esm.js +71 -108
  27. package/package.json +12 -7
  28. package/bundle/index.iife.js.map +0 -1
  29. package/bundle/index.iife.min.js.map +0 -1
  30. package/bundle/index.umd.js.map +0 -1
  31. package/bundle/index.umd.min.js.map +0 -1
  32. package/create-fifo-list.d.ts +0 -18
  33. package/create-fifo-list.d.ts.map +0 -1
  34. package/create-lifo-list.d.ts +0 -18
  35. package/create-lifo-list.d.ts.map +0 -1
  36. package/create-range.d.ts +0 -9
  37. package/create-range.d.ts.map +0 -1
  38. package/create-value-picker.d.ts +0 -12
  39. package/create-value-picker.d.ts.map +0 -1
  40. package/get-last-key-in-map.d.ts +0 -2
  41. package/get-last-key-in-map.d.ts.map +0 -1
  42. package/index.cjs.js.map +0 -1
  43. package/index.esm.js.map +0 -1
  44. package/non-empty-strings.d.ts +0 -8
  45. package/non-empty-strings.d.ts.map +0 -1
  46. package/unique-strings.d.ts +0 -8
  47. package/unique-strings.d.ts.map +0 -1
@@ -1,24 +1,6 @@
1
1
  var HyperfrontendListUtils = (function (exports) {
2
2
  'use strict';
3
3
 
4
- /**
5
- * Safe copies of Object built-in methods.
6
- *
7
- * These references are captured at module initialization time to protect against
8
- * prototype pollution attacks. Import only what you need for tree-shaking.
9
- *
10
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
11
- */
12
- // Capture references at module initialization time
13
- const _Object = globalThis.Object;
14
- /**
15
- * (Safe copy) Prevents modification of existing property attributes and values,
16
- * and prevents the addition of new properties.
17
- */
18
- const freeze = _Object.freeze;
19
-
20
- const registeredClasses = [];
21
-
22
4
  /**
23
5
  * Safe copies of Array built-in static methods.
24
6
  *
@@ -27,7 +9,6 @@ var HyperfrontendListUtils = (function (exports) {
27
9
  *
28
10
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
29
11
  */
30
- // Capture references at module initialization time
31
12
  const _Array = globalThis.Array;
32
13
  /**
33
14
  * (Safe copy) Determines whether the passed value is an Array.
@@ -38,29 +19,6 @@ var HyperfrontendListUtils = (function (exports) {
38
19
  */
39
20
  const from = _Array.from;
40
21
 
41
- /**
42
- * Returns the data type of the target.
43
- * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
44
- * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
45
- *
46
- * @param target - The target to get the data type of.
47
- * @returns The data type of the target.
48
- */
49
- const getType = (target) => {
50
- if (target === null)
51
- return 'null';
52
- const nativeDataType = typeof target;
53
- if (nativeDataType === 'object') {
54
- if (isArray(target))
55
- return 'array';
56
- for (const registeredClass of registeredClasses) {
57
- if (target instanceof registeredClass)
58
- return registeredClass.name;
59
- }
60
- }
61
- return nativeDataType;
62
- };
63
-
64
22
  /**
65
23
  * Safe copies of Error built-ins via factory functions.
66
24
  *
@@ -72,7 +30,6 @@ var HyperfrontendListUtils = (function (exports) {
72
30
  *
73
31
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
74
32
  */
75
- // Capture references at module initialization time
76
33
  const _Error = globalThis.Error;
77
34
  const _Reflect$1 = globalThis.Reflect;
78
35
  /**
@@ -82,21 +39,69 @@ var HyperfrontendListUtils = (function (exports) {
82
39
  * @param message - Optional error message.
83
40
  * @param options - Optional error options.
84
41
  * @returns A new Error instance.
42
+ *
43
+ * @example Creating Error instances
44
+ * ```typescript
45
+ * const error = createError('Operation failed')
46
+ * // With cause for error chaining
47
+ * const wrapped = createError('Request failed', { cause: originalError })
48
+ * ```
85
49
  */
86
50
  const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
87
51
 
88
52
  /**
89
- * Safe copies of Set built-in via factory function.
90
- *
91
- * Since constructors cannot be safely captured via Object.assign, this module
92
- * provides a factory function that uses Reflect.construct internally.
53
+ * Safe copies of Object built-in methods.
93
54
  *
94
55
  * These references are captured at module initialization time to protect against
95
56
  * prototype pollution attacks. Import only what you need for tree-shaking.
96
57
  *
58
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
59
+ */
60
+ const _Object = globalThis.Object;
61
+ /**
62
+ * (Safe copy) Prevents modification of existing property attributes and values,
63
+ * and prevents the addition of new properties.
64
+ */
65
+ const freeze = _Object.freeze;
66
+
67
+ const registeredClasses = [];
68
+
69
+ /**
70
+ * Returns the data type of the target.
71
+ * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
72
+ * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
73
+ *
74
+ * @param target - The target to get the data type of.
75
+ * @returns The data type of the target.
76
+ *
77
+ * @example Determining data types
78
+ * ```typescript
79
+ * getType([1, 2]) // 'array'
80
+ * getType({ a: 1 }) // 'object'
81
+ * getType(null) // 'null'
82
+ * ```
83
+ */
84
+ const getType = (target) => {
85
+ if (target === null)
86
+ return 'null';
87
+ const nativeDataType = typeof target;
88
+ if (nativeDataType === 'object') {
89
+ if (isArray(target))
90
+ return 'array';
91
+ for (const registeredClass of registeredClasses) {
92
+ if (target instanceof registeredClass)
93
+ return registeredClass.name;
94
+ }
95
+ }
96
+ return nativeDataType;
97
+ };
98
+
99
+ /**
100
+ * Safe Set factory for protected set construction.
101
+ *
97
102
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
98
103
  */
99
- // Capture references at module initialization time
104
+ /* eslint-disable workspace/lib-require-jsdoc-example */
100
105
  const _Set = globalThis.Set;
101
106
  const _Reflect = globalThis.Reflect;
102
107
  /**
@@ -113,6 +118,17 @@ var HyperfrontendListUtils = (function (exports) {
113
118
  *
114
119
  * @template T The type of elements in the list, must be an object.
115
120
  * @returns {FifoList<T>} A FIFO list with methods to manipulate and query the list.
121
+ * @example Creating and using FIFO queue
122
+ * ```typescript
123
+ * interface Task { id: number; name: string }
124
+ * const queue = createFifoList<Task>()
125
+ *
126
+ * queue.push({ id: 1, name: 'first' })
127
+ * queue.push({ id: 2, name: 'second' })
128
+ *
129
+ * queue.pull() // => { id: 1, name: 'first' }
130
+ * queue.pull() // => { id: 2, name: 'second' }
131
+ * ```
116
132
  */
117
133
  function createFifoList() {
118
134
  const list = createSet();
@@ -158,6 +174,17 @@ var HyperfrontendListUtils = (function (exports) {
158
174
  *
159
175
  * @template T The type of elements in the list, must be an object.
160
176
  * @returns {LifoList<T>} A LIFO list with methods to manipulate and query the list.
177
+ * @example Creating and using LIFO stack
178
+ * ```typescript
179
+ * interface HistoryEntry { url: string; timestamp: number }
180
+ * const history = createLifoList<HistoryEntry>()
181
+ *
182
+ * history.push({ url: '/home', timestamp: 1 })
183
+ * history.push({ url: '/about', timestamp: 2 })
184
+ *
185
+ * history.pull() // => { url: '/about', timestamp: 2 }
186
+ * history.pull() // => { url: '/home', timestamp: 1 }
187
+ * ```
161
188
  */
162
189
  function createLifoList() {
163
190
  const list = createSet();
@@ -205,6 +232,14 @@ var HyperfrontendListUtils = (function (exports) {
205
232
  * @param start - The starting number of the range
206
233
  * @param end - The ending number of the range (inclusive)
207
234
  * @returns An array containing all numbers from start to end
235
+ * @example Generating number ranges
236
+ * ```typescript
237
+ * createRange(1, 5)
238
+ * // => [1, 2, 3, 4, 5]
239
+ *
240
+ * createRange(3, 3)
241
+ * // => [3]
242
+ * ```
208
243
  */
209
244
  function createRange(start, end) {
210
245
  const range = [];
@@ -219,6 +254,16 @@ var HyperfrontendListUtils = (function (exports) {
219
254
  *
220
255
  * @param values - The array of string values to cycle through
221
256
  * @returns A ValuePicker instance with current and next methods
257
+ * @example Cycling through values
258
+ * ```typescript
259
+ * const colorPicker = createValuePicker(['red', 'green', 'blue'])
260
+ *
261
+ * colorPicker.current() // => 'red'
262
+ * colorPicker.next() // => 'red' (first call initializes)
263
+ * colorPicker.next() // => 'green'
264
+ * colorPicker.next() // => 'blue'
265
+ * colorPicker.next() // => 'red' (cycles back)
266
+ * ```
222
267
  */
223
268
  function createValuePicker(values) {
224
269
  if (!values || !values.length) {
@@ -252,7 +297,22 @@ var HyperfrontendListUtils = (function (exports) {
252
297
  };
253
298
  }
254
299
 
255
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
+ /* eslint-disable @typescript-eslint/no-explicit-any */
301
+ /**
302
+ * Retrieves the final key from a Map by converting keys to an array.
303
+ *
304
+ * @param map - The Map to extract the last key from
305
+ * @returns The key that was inserted last, or undefined if map is empty
306
+ * @example Getting last key from Map
307
+ * ```typescript
308
+ * const userRoles = new Map<string, string>()
309
+ * userRoles.set('alice', 'admin')
310
+ * userRoles.set('bob', 'editor')
311
+ * userRoles.set('charlie', 'viewer')
312
+ *
313
+ * getLastKeyInMap(userRoles) // => 'charlie'
314
+ * ```
315
+ */
256
316
  const getLastKeyInMap = (map) => {
257
317
  const items = [...map.keys()];
258
318
  return items[items.length - 1];
@@ -263,6 +323,11 @@ var HyperfrontendListUtils = (function (exports) {
263
323
  *
264
324
  * @param values - The array of strings to filter
265
325
  * @returns A new array containing only non-empty strings with content
326
+ * @example Filtering empty strings
327
+ * ```typescript
328
+ * nonEmptyStrings(['hello', '', ' ', 'world', null as unknown as string])
329
+ * // => ['hello', 'world']
330
+ * ```
266
331
  */
267
332
  function nonEmptyStrings(values) {
268
333
  return values.filter((value) => ![undefined, null, ''].includes(value) && value.trim() !== '');
@@ -273,6 +338,11 @@ var HyperfrontendListUtils = (function (exports) {
273
338
  *
274
339
  * @param values - The array of strings to deduplicate
275
340
  * @returns A new array containing only unique strings
341
+ * @example Deduplicating strings
342
+ * ```typescript
343
+ * uniqueStrings(['apple', 'banana', 'apple', 'cherry', 'banana'])
344
+ * // => ['apple', 'banana', 'cherry']
345
+ * ```
276
346
  */
277
347
  function uniqueStrings(values) {
278
348
  return from(createSet(values));
@@ -289,4 +359,3 @@ var HyperfrontendListUtils = (function (exports) {
289
359
  return exports;
290
360
 
291
361
  })({});
292
- //# sourceMappingURL=index.iife.js.map
@@ -1,2 +1 @@
1
- var HyperfrontendListUtils=function(e){"use strict";const t=globalThis.Object.freeze,r=[],n=globalThis.Array,o=n.isArray,i=n.from,l=e=>{if(null===e)return"null";const t=typeof e;if("object"===t){if(o(e))return"array";for(const t of r)if(e instanceof t)return t.name}return t},s=globalThis.Error,a=globalThis.Reflect,u=(e,t)=>a.construct(s,[e,t]),c=globalThis.Set,f=globalThis.Reflect,h=e=>f.construct(c,e?[e]:[]);return e.createFifoList=function(){const e=h();return t({push:t=>{if("object"!==l(t))throw u("A fifo list only non-primitive values");if(e.has(t))throw u("Cannot a item that already exists");e.add(t)},pull:()=>{const t=e.values().next().value;return e.delete(t),t},map:t=>i(e.values()).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>e.clear()})},e.createLifoList=function(){const e=h();return t({push:t=>{if("object"!==l(t))throw u("A lifo list only supports non-primitive values");e.add(t)},pull:()=>{const t=i(e).pop();return t&&e.delete(t),t},map:t=>i(e).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>{e.clear()}})},e.createRange=function(e,t){const r=[];for(let n=e;n<=t;n+=1)r.push(n);return r},e.createValuePicker=function(e){if(!e||!e.length)throw u("Expected values not to be an empty list.");let t=-1;function r(){return t<0&&(t=0),e[t]}return{current:r,next:function(){return t<0?r():(t=++t<e.length?t:0,e[t])}}},e.getLastKeyInMap=e=>{const t=[...e.keys()];return t[t.length-1]},e.nonEmptyStrings=function(e){return e.filter(e=>![void 0,null,""].includes(e)&&""!==e.trim())},e.uniqueStrings=function(e){return i(h(e))},e}({});
2
- //# sourceMappingURL=index.iife.min.js.map
1
+ var HyperfrontendListUtils=function(e){"use strict";const t=globalThis.Array,r=t.isArray,n=t.from,o=globalThis.Error,i=globalThis.Reflect,l=(e,t)=>i.construct(o,[e,t]),s=globalThis.Object.freeze,a=[],u=e=>{if(null===e)return"null";const t=typeof e;if("object"===t){if(r(e))return"array";for(const t of a)if(e instanceof t)return t.name}return t},c=globalThis.Set,f=globalThis.Reflect,h=e=>f.construct(c,e?[e]:[]);return e.createFifoList=function(){const e=h();return s({push:t=>{if("object"!==u(t))throw l("A fifo list only non-primitive values");if(e.has(t))throw l("Cannot a item that already exists");e.add(t)},pull:()=>{const t=e.values().next().value;return e.delete(t),t},map:t=>n(e.values()).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>e.clear()})},e.createLifoList=function(){const e=h();return s({push:t=>{if("object"!==u(t))throw l("A lifo list only supports non-primitive values");e.add(t)},pull:()=>{const t=n(e).pop();return t&&e.delete(t),t},map:t=>n(e).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>{e.clear()}})},e.createRange=function(e,t){const r=[];for(let n=e;n<=t;n+=1)r.push(n);return r},e.createValuePicker=function(e){if(!e||!e.length)throw l("Expected values not to be an empty list.");let t=-1;function r(){return t<0&&(t=0),e[t]}return{current:r,next:function(){return t<0?r():(t=++t<e.length?t:0,e[t])}}},e.getLastKeyInMap=e=>{const t=[...e.keys()];return t[t.length-1]},e.nonEmptyStrings=function(e){return e.filter(e=>![void 0,null,""].includes(e)&&""!==e.trim())},e.uniqueStrings=function(e){return n(h(e))},e}({});
@@ -4,24 +4,6 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.HyperfrontendListUtils = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- /**
8
- * Safe copies of Object built-in methods.
9
- *
10
- * These references are captured at module initialization time to protect against
11
- * prototype pollution attacks. Import only what you need for tree-shaking.
12
- *
13
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
14
- */
15
- // Capture references at module initialization time
16
- const _Object = globalThis.Object;
17
- /**
18
- * (Safe copy) Prevents modification of existing property attributes and values,
19
- * and prevents the addition of new properties.
20
- */
21
- const freeze = _Object.freeze;
22
-
23
- const registeredClasses = [];
24
-
25
7
  /**
26
8
  * Safe copies of Array built-in static methods.
27
9
  *
@@ -30,7 +12,6 @@
30
12
  *
31
13
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
32
14
  */
33
- // Capture references at module initialization time
34
15
  const _Array = globalThis.Array;
35
16
  /**
36
17
  * (Safe copy) Determines whether the passed value is an Array.
@@ -41,29 +22,6 @@
41
22
  */
42
23
  const from = _Array.from;
43
24
 
44
- /**
45
- * Returns the data type of the target.
46
- * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
47
- * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
48
- *
49
- * @param target - The target to get the data type of.
50
- * @returns The data type of the target.
51
- */
52
- const getType = (target) => {
53
- if (target === null)
54
- return 'null';
55
- const nativeDataType = typeof target;
56
- if (nativeDataType === 'object') {
57
- if (isArray(target))
58
- return 'array';
59
- for (const registeredClass of registeredClasses) {
60
- if (target instanceof registeredClass)
61
- return registeredClass.name;
62
- }
63
- }
64
- return nativeDataType;
65
- };
66
-
67
25
  /**
68
26
  * Safe copies of Error built-ins via factory functions.
69
27
  *
@@ -75,7 +33,6 @@
75
33
  *
76
34
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
77
35
  */
78
- // Capture references at module initialization time
79
36
  const _Error = globalThis.Error;
80
37
  const _Reflect$1 = globalThis.Reflect;
81
38
  /**
@@ -85,21 +42,69 @@
85
42
  * @param message - Optional error message.
86
43
  * @param options - Optional error options.
87
44
  * @returns A new Error instance.
45
+ *
46
+ * @example Creating Error instances
47
+ * ```typescript
48
+ * const error = createError('Operation failed')
49
+ * // With cause for error chaining
50
+ * const wrapped = createError('Request failed', { cause: originalError })
51
+ * ```
88
52
  */
89
53
  const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
90
54
 
91
55
  /**
92
- * Safe copies of Set built-in via factory function.
93
- *
94
- * Since constructors cannot be safely captured via Object.assign, this module
95
- * provides a factory function that uses Reflect.construct internally.
56
+ * Safe copies of Object built-in methods.
96
57
  *
97
58
  * These references are captured at module initialization time to protect against
98
59
  * prototype pollution attacks. Import only what you need for tree-shaking.
99
60
  *
61
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
62
+ */
63
+ const _Object = globalThis.Object;
64
+ /**
65
+ * (Safe copy) Prevents modification of existing property attributes and values,
66
+ * and prevents the addition of new properties.
67
+ */
68
+ const freeze = _Object.freeze;
69
+
70
+ const registeredClasses = [];
71
+
72
+ /**
73
+ * Returns the data type of the target.
74
+ * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
75
+ * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
76
+ *
77
+ * @param target - The target to get the data type of.
78
+ * @returns The data type of the target.
79
+ *
80
+ * @example Determining data types
81
+ * ```typescript
82
+ * getType([1, 2]) // 'array'
83
+ * getType({ a: 1 }) // 'object'
84
+ * getType(null) // 'null'
85
+ * ```
86
+ */
87
+ const getType = (target) => {
88
+ if (target === null)
89
+ return 'null';
90
+ const nativeDataType = typeof target;
91
+ if (nativeDataType === 'object') {
92
+ if (isArray(target))
93
+ return 'array';
94
+ for (const registeredClass of registeredClasses) {
95
+ if (target instanceof registeredClass)
96
+ return registeredClass.name;
97
+ }
98
+ }
99
+ return nativeDataType;
100
+ };
101
+
102
+ /**
103
+ * Safe Set factory for protected set construction.
104
+ *
100
105
  * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
101
106
  */
102
- // Capture references at module initialization time
107
+ /* eslint-disable workspace/lib-require-jsdoc-example */
103
108
  const _Set = globalThis.Set;
104
109
  const _Reflect = globalThis.Reflect;
105
110
  /**
@@ -116,6 +121,17 @@
116
121
  *
117
122
  * @template T The type of elements in the list, must be an object.
118
123
  * @returns {FifoList<T>} A FIFO list with methods to manipulate and query the list.
124
+ * @example Creating and using FIFO queue
125
+ * ```typescript
126
+ * interface Task { id: number; name: string }
127
+ * const queue = createFifoList<Task>()
128
+ *
129
+ * queue.push({ id: 1, name: 'first' })
130
+ * queue.push({ id: 2, name: 'second' })
131
+ *
132
+ * queue.pull() // => { id: 1, name: 'first' }
133
+ * queue.pull() // => { id: 2, name: 'second' }
134
+ * ```
119
135
  */
120
136
  function createFifoList() {
121
137
  const list = createSet();
@@ -161,6 +177,17 @@
161
177
  *
162
178
  * @template T The type of elements in the list, must be an object.
163
179
  * @returns {LifoList<T>} A LIFO list with methods to manipulate and query the list.
180
+ * @example Creating and using LIFO stack
181
+ * ```typescript
182
+ * interface HistoryEntry { url: string; timestamp: number }
183
+ * const history = createLifoList<HistoryEntry>()
184
+ *
185
+ * history.push({ url: '/home', timestamp: 1 })
186
+ * history.push({ url: '/about', timestamp: 2 })
187
+ *
188
+ * history.pull() // => { url: '/about', timestamp: 2 }
189
+ * history.pull() // => { url: '/home', timestamp: 1 }
190
+ * ```
164
191
  */
165
192
  function createLifoList() {
166
193
  const list = createSet();
@@ -208,6 +235,14 @@
208
235
  * @param start - The starting number of the range
209
236
  * @param end - The ending number of the range (inclusive)
210
237
  * @returns An array containing all numbers from start to end
238
+ * @example Generating number ranges
239
+ * ```typescript
240
+ * createRange(1, 5)
241
+ * // => [1, 2, 3, 4, 5]
242
+ *
243
+ * createRange(3, 3)
244
+ * // => [3]
245
+ * ```
211
246
  */
212
247
  function createRange(start, end) {
213
248
  const range = [];
@@ -222,6 +257,16 @@
222
257
  *
223
258
  * @param values - The array of string values to cycle through
224
259
  * @returns A ValuePicker instance with current and next methods
260
+ * @example Cycling through values
261
+ * ```typescript
262
+ * const colorPicker = createValuePicker(['red', 'green', 'blue'])
263
+ *
264
+ * colorPicker.current() // => 'red'
265
+ * colorPicker.next() // => 'red' (first call initializes)
266
+ * colorPicker.next() // => 'green'
267
+ * colorPicker.next() // => 'blue'
268
+ * colorPicker.next() // => 'red' (cycles back)
269
+ * ```
225
270
  */
226
271
  function createValuePicker(values) {
227
272
  if (!values || !values.length) {
@@ -255,7 +300,22 @@
255
300
  };
256
301
  }
257
302
 
258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
303
+ /* eslint-disable @typescript-eslint/no-explicit-any */
304
+ /**
305
+ * Retrieves the final key from a Map by converting keys to an array.
306
+ *
307
+ * @param map - The Map to extract the last key from
308
+ * @returns The key that was inserted last, or undefined if map is empty
309
+ * @example Getting last key from Map
310
+ * ```typescript
311
+ * const userRoles = new Map<string, string>()
312
+ * userRoles.set('alice', 'admin')
313
+ * userRoles.set('bob', 'editor')
314
+ * userRoles.set('charlie', 'viewer')
315
+ *
316
+ * getLastKeyInMap(userRoles) // => 'charlie'
317
+ * ```
318
+ */
259
319
  const getLastKeyInMap = (map) => {
260
320
  const items = [...map.keys()];
261
321
  return items[items.length - 1];
@@ -266,6 +326,11 @@
266
326
  *
267
327
  * @param values - The array of strings to filter
268
328
  * @returns A new array containing only non-empty strings with content
329
+ * @example Filtering empty strings
330
+ * ```typescript
331
+ * nonEmptyStrings(['hello', '', ' ', 'world', null as unknown as string])
332
+ * // => ['hello', 'world']
333
+ * ```
269
334
  */
270
335
  function nonEmptyStrings(values) {
271
336
  return values.filter((value) => ![undefined, null, ''].includes(value) && value.trim() !== '');
@@ -276,6 +341,11 @@
276
341
  *
277
342
  * @param values - The array of strings to deduplicate
278
343
  * @returns A new array containing only unique strings
344
+ * @example Deduplicating strings
345
+ * ```typescript
346
+ * uniqueStrings(['apple', 'banana', 'apple', 'cherry', 'banana'])
347
+ * // => ['apple', 'banana', 'cherry']
348
+ * ```
279
349
  */
280
350
  function uniqueStrings(values) {
281
351
  return from(createSet(values));
@@ -290,4 +360,3 @@
290
360
  exports.uniqueStrings = uniqueStrings;
291
361
 
292
362
  }));
293
- //# sourceMappingURL=index.umd.js.map
@@ -1,2 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).HyperfrontendListUtils={})}(this,function(e){"use strict";const t=globalThis.Object.freeze,n=[],r=globalThis.Array,o=r.isArray,i=r.from,s=e=>{if(null===e)return"null";const t=typeof e;if("object"===t){if(o(e))return"array";for(const t of n)if(e instanceof t)return t.name}return t},l=globalThis.Error,a=globalThis.Reflect,u=(e,t)=>a.construct(l,[e,t]),c=globalThis.Set,f=globalThis.Reflect,h=e=>f.construct(c,e?[e]:[]);e.createFifoList=function(){const e=h();return t({push:t=>{if("object"!==s(t))throw u("A fifo list only non-primitive values");if(e.has(t))throw u("Cannot a item that already exists");e.add(t)},pull:()=>{const t=e.values().next().value;return e.delete(t),t},map:t=>i(e.values()).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>e.clear()})},e.createLifoList=function(){const e=h();return t({push:t=>{if("object"!==s(t))throw u("A lifo list only supports non-primitive values");e.add(t)},pull:()=>{const t=i(e).pop();return t&&e.delete(t),t},map:t=>i(e).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>{e.clear()}})},e.createRange=function(e,t){const n=[];for(let r=e;r<=t;r+=1)n.push(r);return n},e.createValuePicker=function(e){if(!e||!e.length)throw u("Expected values not to be an empty list.");let t=-1;function n(){return t<0&&(t=0),e[t]}return{current:n,next:function(){return t<0?n():(t=++t<e.length?t:0,e[t])}}},e.getLastKeyInMap=e=>{const t=[...e.keys()];return t[t.length-1]},e.nonEmptyStrings=function(e){return e.filter(e=>![void 0,null,""].includes(e)&&""!==e.trim())},e.uniqueStrings=function(e){return i(h(e))}});
2
- //# sourceMappingURL=index.umd.min.js.map
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).HyperfrontendListUtils={})}(this,function(e){"use strict";const t=globalThis.Array,n=t.isArray,r=t.from,o=globalThis.Error,i=globalThis.Reflect,s=(e,t)=>i.construct(o,[e,t]),l=globalThis.Object.freeze,a=[],u=e=>{if(null===e)return"null";const t=typeof e;if("object"===t){if(n(e))return"array";for(const t of a)if(e instanceof t)return t.name}return t},c=globalThis.Set,f=globalThis.Reflect,h=e=>f.construct(c,e?[e]:[]);e.createFifoList=function(){const e=h();return l({push:t=>{if("object"!==u(t))throw s("A fifo list only non-primitive values");if(e.has(t))throw s("Cannot a item that already exists");e.add(t)},pull:()=>{const t=e.values().next().value;return e.delete(t),t},map:t=>r(e.values()).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>e.clear()})},e.createLifoList=function(){const e=h();return l({push:t=>{if("object"!==u(t))throw s("A lifo list only supports non-primitive values");e.add(t)},pull:()=>{const t=r(e).pop();return t&&e.delete(t),t},map:t=>r(e).map(t),forEach:t=>{e.forEach(t)},remove:t=>e.delete(t),has:t=>e.has(t),size:()=>e.size,clear:()=>{e.clear()}})},e.createRange=function(e,t){const n=[];for(let r=e;r<=t;r+=1)n.push(r);return n},e.createValuePicker=function(e){if(!e||!e.length)throw s("Expected values not to be an empty list.");let t=-1;function n(){return t<0&&(t=0),e[t]}return{current:n,next:function(){return t<0?n():(t=++t<e.length?t:0,e[t])}}},e.getLastKeyInMap=e=>{const t=[...e.keys()];return t[t.length-1]},e.nonEmptyStrings=function(e){return e.filter(e=>![void 0,null,""].includes(e)&&""!==e.trim())},e.uniqueStrings=function(e){return r(h(e))}});