@hyperfrontend/list-utils 0.0.3 → 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.
- package/CHANGELOG.md +15 -5
- package/README.md +6 -3
- package/_dependencies/@hyperfrontend/data-utils/index.cjs.js +214 -0
- package/_dependencies/@hyperfrontend/data-utils/index.esm.js +202 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.cjs.js +8 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.esm.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js +5 -0
- package/bundle/index.iife.js +119 -50
- package/bundle/index.iife.min.js +1 -2
- package/bundle/index.umd.js +119 -50
- package/bundle/index.umd.min.js +1 -2
- package/index.cjs.js +85 -122
- package/index.d.ts +169 -8
- package/index.d.ts.map +1 -1
- package/index.esm.js +71 -108
- package/package.json +12 -7
- package/bundle/index.iife.js.map +0 -1
- package/bundle/index.iife.min.js.map +0 -1
- package/bundle/index.umd.js.map +0 -1
- package/bundle/index.umd.min.js.map +0 -1
- package/create-fifo-list.d.ts +0 -18
- package/create-fifo-list.d.ts.map +0 -1
- package/create-lifo-list.d.ts +0 -18
- package/create-lifo-list.d.ts.map +0 -1
- package/create-range.d.ts +0 -9
- package/create-range.d.ts.map +0 -1
- package/create-value-picker.d.ts +0 -12
- package/create-value-picker.d.ts.map +0 -1
- package/get-last-key-in-map.d.ts +0 -2
- package/get-last-key-in-map.d.ts.map +0 -1
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- package/non-empty-strings.d.ts +0 -8
- package/non-empty-strings.d.ts.map +0 -1
- package/unique-strings.d.ts +0 -8
- package/unique-strings.d.ts.map +0 -1
package/index.cjs.js
CHANGED
|
@@ -1,126 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/object
|
|
10
|
-
*/
|
|
11
|
-
// Capture references at module initialization time
|
|
12
|
-
const _Object = globalThis.Object;
|
|
13
|
-
/**
|
|
14
|
-
* (Safe copy) Prevents modification of existing property attributes and values,
|
|
15
|
-
* and prevents the addition of new properties.
|
|
16
|
-
*/
|
|
17
|
-
const freeze = _Object.freeze;
|
|
18
|
-
|
|
19
|
-
const registeredClasses = [];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Safe copies of Array built-in static methods.
|
|
23
|
-
*
|
|
24
|
-
* These references are captured at module initialization time to protect against
|
|
25
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
26
|
-
*
|
|
27
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/array
|
|
28
|
-
*/
|
|
29
|
-
// Capture references at module initialization time
|
|
30
|
-
const _Array = globalThis.Array;
|
|
31
|
-
/**
|
|
32
|
-
* (Safe copy) Determines whether the passed value is an Array.
|
|
33
|
-
*/
|
|
34
|
-
const isArray = _Array.isArray;
|
|
35
|
-
/**
|
|
36
|
-
* (Safe copy) Creates an array from an array-like or iterable object.
|
|
37
|
-
*/
|
|
38
|
-
const from = _Array.from;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Returns the data type of the target.
|
|
42
|
-
* Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
|
|
43
|
-
* Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
|
|
44
|
-
*
|
|
45
|
-
* @param target - The target to get the data type of.
|
|
46
|
-
* @returns The data type of the target.
|
|
47
|
-
*/
|
|
48
|
-
const getType = (target) => {
|
|
49
|
-
if (target === null)
|
|
50
|
-
return 'null';
|
|
51
|
-
const nativeDataType = typeof target;
|
|
52
|
-
if (nativeDataType === 'object') {
|
|
53
|
-
if (isArray(target))
|
|
54
|
-
return 'array';
|
|
55
|
-
for (const registeredClass of registeredClasses) {
|
|
56
|
-
if (target instanceof registeredClass)
|
|
57
|
-
return registeredClass.name;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return nativeDataType;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Safe copies of Error built-ins via factory functions.
|
|
65
|
-
*
|
|
66
|
-
* Since constructors cannot be safely captured via Object.assign, this module
|
|
67
|
-
* provides factory functions that use Reflect.construct internally.
|
|
68
|
-
*
|
|
69
|
-
* These references are captured at module initialization time to protect against
|
|
70
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
71
|
-
*
|
|
72
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/error
|
|
73
|
-
*/
|
|
74
|
-
// Capture references at module initialization time
|
|
75
|
-
const _Error = globalThis.Error;
|
|
76
|
-
const _Reflect$1 = globalThis.Reflect;
|
|
77
|
-
/**
|
|
78
|
-
* (Safe copy) Creates a new Error using the captured Error constructor.
|
|
79
|
-
* Use this instead of `new Error()`.
|
|
80
|
-
*
|
|
81
|
-
* @param message - Optional error message.
|
|
82
|
-
* @param options - Optional error options.
|
|
83
|
-
* @returns A new Error instance.
|
|
84
|
-
*/
|
|
85
|
-
const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Safe copies of Set built-in via factory function.
|
|
89
|
-
*
|
|
90
|
-
* Since constructors cannot be safely captured via Object.assign, this module
|
|
91
|
-
* provides a factory function that uses Reflect.construct internally.
|
|
92
|
-
*
|
|
93
|
-
* These references are captured at module initialization time to protect against
|
|
94
|
-
* prototype pollution attacks. Import only what you need for tree-shaking.
|
|
95
|
-
*
|
|
96
|
-
* @module @hyperfrontend/immutable-api-utils/built-in-copy/set
|
|
97
|
-
*/
|
|
98
|
-
// Capture references at module initialization time
|
|
99
|
-
const _Set = globalThis.Set;
|
|
100
|
-
const _Reflect = globalThis.Reflect;
|
|
101
|
-
/**
|
|
102
|
-
* (Safe copy) Creates a new Set using the captured Set constructor.
|
|
103
|
-
* Use this instead of `new Set()`.
|
|
104
|
-
*
|
|
105
|
-
* @param iterable - Optional iterable of values.
|
|
106
|
-
* @returns A new Set instance.
|
|
107
|
-
*/
|
|
108
|
-
const createSet = (iterable) => _Reflect.construct(_Set, iterable ? [iterable] : []);
|
|
3
|
+
const index_cjs_js$2 = require('./_dependencies/@hyperfrontend/data-utils/index.cjs.js');
|
|
4
|
+
const index_cjs_js$4 = require('./_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js');
|
|
5
|
+
const index_cjs_js$3 = require('./_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js');
|
|
6
|
+
const index_cjs_js$1 = require('./_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js');
|
|
7
|
+
const index_cjs_js = require('./_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js');
|
|
109
8
|
|
|
110
9
|
/**
|
|
111
10
|
* Creates a FIFO (First-In-First-Out) list.
|
|
112
11
|
*
|
|
113
12
|
* @template T The type of elements in the list, must be an object.
|
|
114
13
|
* @returns {FifoList<T>} A FIFO list with methods to manipulate and query the list.
|
|
14
|
+
* @example Creating and using FIFO queue
|
|
15
|
+
* ```typescript
|
|
16
|
+
* interface Task { id: number; name: string }
|
|
17
|
+
* const queue = createFifoList<Task>()
|
|
18
|
+
*
|
|
19
|
+
* queue.push({ id: 1, name: 'first' })
|
|
20
|
+
* queue.push({ id: 2, name: 'second' })
|
|
21
|
+
*
|
|
22
|
+
* queue.pull() // => { id: 1, name: 'first' }
|
|
23
|
+
* queue.pull() // => { id: 2, name: 'second' }
|
|
24
|
+
* ```
|
|
115
25
|
*/
|
|
116
26
|
function createFifoList() {
|
|
117
|
-
const list = createSet();
|
|
27
|
+
const list = index_cjs_js.createSet();
|
|
118
28
|
const push = (item) => {
|
|
119
|
-
if (getType(item) !== 'object') {
|
|
120
|
-
throw createError('A fifo list only non-primitive values');
|
|
29
|
+
if (index_cjs_js$2.getType(item) !== 'object') {
|
|
30
|
+
throw index_cjs_js$3.createError('A fifo list only non-primitive values');
|
|
121
31
|
}
|
|
122
32
|
if (list.has(item)) {
|
|
123
|
-
throw createError('Cannot a item that already exists');
|
|
33
|
+
throw index_cjs_js$3.createError('Cannot a item that already exists');
|
|
124
34
|
}
|
|
125
35
|
list.add(item);
|
|
126
36
|
};
|
|
@@ -130,7 +40,7 @@ function createFifoList() {
|
|
|
130
40
|
return value;
|
|
131
41
|
};
|
|
132
42
|
const map = (callback) => {
|
|
133
|
-
return from(list.values()).map(callback);
|
|
43
|
+
return index_cjs_js$4.from(list.values()).map(callback);
|
|
134
44
|
};
|
|
135
45
|
const forEach = (callback) => {
|
|
136
46
|
list.forEach(callback);
|
|
@@ -149,7 +59,7 @@ function createFifoList() {
|
|
|
149
59
|
size,
|
|
150
60
|
clear,
|
|
151
61
|
};
|
|
152
|
-
return freeze(result);
|
|
62
|
+
return index_cjs_js$1.freeze(result);
|
|
153
63
|
}
|
|
154
64
|
|
|
155
65
|
/**
|
|
@@ -157,24 +67,35 @@ function createFifoList() {
|
|
|
157
67
|
*
|
|
158
68
|
* @template T The type of elements in the list, must be an object.
|
|
159
69
|
* @returns {LifoList<T>} A LIFO list with methods to manipulate and query the list.
|
|
70
|
+
* @example Creating and using LIFO stack
|
|
71
|
+
* ```typescript
|
|
72
|
+
* interface HistoryEntry { url: string; timestamp: number }
|
|
73
|
+
* const history = createLifoList<HistoryEntry>()
|
|
74
|
+
*
|
|
75
|
+
* history.push({ url: '/home', timestamp: 1 })
|
|
76
|
+
* history.push({ url: '/about', timestamp: 2 })
|
|
77
|
+
*
|
|
78
|
+
* history.pull() // => { url: '/about', timestamp: 2 }
|
|
79
|
+
* history.pull() // => { url: '/home', timestamp: 1 }
|
|
80
|
+
* ```
|
|
160
81
|
*/
|
|
161
82
|
function createLifoList() {
|
|
162
|
-
const list = createSet();
|
|
83
|
+
const list = index_cjs_js.createSet();
|
|
163
84
|
const push = (item) => {
|
|
164
|
-
if (getType(item) !== 'object') {
|
|
165
|
-
throw createError('A lifo list only supports non-primitive values');
|
|
85
|
+
if (index_cjs_js$2.getType(item) !== 'object') {
|
|
86
|
+
throw index_cjs_js$3.createError('A lifo list only supports non-primitive values');
|
|
166
87
|
}
|
|
167
88
|
list.add(item);
|
|
168
89
|
};
|
|
169
90
|
const pull = () => {
|
|
170
|
-
const lastItem = from(list).pop();
|
|
91
|
+
const lastItem = index_cjs_js$4.from(list).pop();
|
|
171
92
|
if (lastItem) {
|
|
172
93
|
list.delete(lastItem);
|
|
173
94
|
}
|
|
174
95
|
return lastItem;
|
|
175
96
|
};
|
|
176
97
|
const map = (callback) => {
|
|
177
|
-
return from(list).map(callback);
|
|
98
|
+
return index_cjs_js$4.from(list).map(callback);
|
|
178
99
|
};
|
|
179
100
|
const forEach = (callback) => {
|
|
180
101
|
list.forEach(callback);
|
|
@@ -195,7 +116,7 @@ function createLifoList() {
|
|
|
195
116
|
size,
|
|
196
117
|
clear,
|
|
197
118
|
};
|
|
198
|
-
return freeze(result);
|
|
119
|
+
return index_cjs_js$1.freeze(result);
|
|
199
120
|
}
|
|
200
121
|
|
|
201
122
|
/**
|
|
@@ -204,6 +125,14 @@ function createLifoList() {
|
|
|
204
125
|
* @param start - The starting number of the range
|
|
205
126
|
* @param end - The ending number of the range (inclusive)
|
|
206
127
|
* @returns An array containing all numbers from start to end
|
|
128
|
+
* @example Generating number ranges
|
|
129
|
+
* ```typescript
|
|
130
|
+
* createRange(1, 5)
|
|
131
|
+
* // => [1, 2, 3, 4, 5]
|
|
132
|
+
*
|
|
133
|
+
* createRange(3, 3)
|
|
134
|
+
* // => [3]
|
|
135
|
+
* ```
|
|
207
136
|
*/
|
|
208
137
|
function createRange(start, end) {
|
|
209
138
|
const range = [];
|
|
@@ -218,10 +147,20 @@ function createRange(start, end) {
|
|
|
218
147
|
*
|
|
219
148
|
* @param values - The array of string values to cycle through
|
|
220
149
|
* @returns A ValuePicker instance with current and next methods
|
|
150
|
+
* @example Cycling through values
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const colorPicker = createValuePicker(['red', 'green', 'blue'])
|
|
153
|
+
*
|
|
154
|
+
* colorPicker.current() // => 'red'
|
|
155
|
+
* colorPicker.next() // => 'red' (first call initializes)
|
|
156
|
+
* colorPicker.next() // => 'green'
|
|
157
|
+
* colorPicker.next() // => 'blue'
|
|
158
|
+
* colorPicker.next() // => 'red' (cycles back)
|
|
159
|
+
* ```
|
|
221
160
|
*/
|
|
222
161
|
function createValuePicker(values) {
|
|
223
162
|
if (!values || !values.length) {
|
|
224
|
-
throw createError('Expected values not to be an empty list.');
|
|
163
|
+
throw index_cjs_js$3.createError('Expected values not to be an empty list.');
|
|
225
164
|
}
|
|
226
165
|
let index = -1;
|
|
227
166
|
/**
|
|
@@ -251,7 +190,22 @@ function createValuePicker(values) {
|
|
|
251
190
|
};
|
|
252
191
|
}
|
|
253
192
|
|
|
254
|
-
|
|
193
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
194
|
+
/**
|
|
195
|
+
* Retrieves the final key from a Map by converting keys to an array.
|
|
196
|
+
*
|
|
197
|
+
* @param map - The Map to extract the last key from
|
|
198
|
+
* @returns The key that was inserted last, or undefined if map is empty
|
|
199
|
+
* @example Getting last key from Map
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const userRoles = new Map<string, string>()
|
|
202
|
+
* userRoles.set('alice', 'admin')
|
|
203
|
+
* userRoles.set('bob', 'editor')
|
|
204
|
+
* userRoles.set('charlie', 'viewer')
|
|
205
|
+
*
|
|
206
|
+
* getLastKeyInMap(userRoles) // => 'charlie'
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
255
209
|
const getLastKeyInMap = (map) => {
|
|
256
210
|
const items = [...map.keys()];
|
|
257
211
|
return items[items.length - 1];
|
|
@@ -262,6 +216,11 @@ const getLastKeyInMap = (map) => {
|
|
|
262
216
|
*
|
|
263
217
|
* @param values - The array of strings to filter
|
|
264
218
|
* @returns A new array containing only non-empty strings with content
|
|
219
|
+
* @example Filtering empty strings
|
|
220
|
+
* ```typescript
|
|
221
|
+
* nonEmptyStrings(['hello', '', ' ', 'world', null as unknown as string])
|
|
222
|
+
* // => ['hello', 'world']
|
|
223
|
+
* ```
|
|
265
224
|
*/
|
|
266
225
|
function nonEmptyStrings(values) {
|
|
267
226
|
return values.filter((value) => ![undefined, null, ''].includes(value) && value.trim() !== '');
|
|
@@ -272,9 +231,14 @@ function nonEmptyStrings(values) {
|
|
|
272
231
|
*
|
|
273
232
|
* @param values - The array of strings to deduplicate
|
|
274
233
|
* @returns A new array containing only unique strings
|
|
234
|
+
* @example Deduplicating strings
|
|
235
|
+
* ```typescript
|
|
236
|
+
* uniqueStrings(['apple', 'banana', 'apple', 'cherry', 'banana'])
|
|
237
|
+
* // => ['apple', 'banana', 'cherry']
|
|
238
|
+
* ```
|
|
275
239
|
*/
|
|
276
240
|
function uniqueStrings(values) {
|
|
277
|
-
return from(createSet(values));
|
|
241
|
+
return index_cjs_js$4.from(index_cjs_js.createSet(values));
|
|
278
242
|
}
|
|
279
243
|
|
|
280
244
|
exports.createFifoList = createFifoList;
|
|
@@ -284,4 +248,3 @@ exports.createValuePicker = createValuePicker;
|
|
|
284
248
|
exports.getLastKeyInMap = getLastKeyInMap;
|
|
285
249
|
exports.nonEmptyStrings = nonEmptyStrings;
|
|
286
250
|
exports.uniqueStrings = uniqueStrings;
|
|
287
|
-
//# sourceMappingURL=index.cjs.js.map
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A FIFO (First-In-First-Out) list interface.
|
|
3
|
+
*/
|
|
4
|
+
interface FifoList<T extends object> {
|
|
5
|
+
/** Adds an item to the end of the list */
|
|
6
|
+
push(item: T): void;
|
|
7
|
+
/** Removes and returns the first item in the list */
|
|
8
|
+
pull(): T;
|
|
9
|
+
/** Maps each item using the provided callback */
|
|
10
|
+
map<U>(callback: (item: T) => U): U[];
|
|
11
|
+
/** Iterates over each item in the list */
|
|
12
|
+
forEach(callback: (item: T) => void): void;
|
|
13
|
+
/** Removes a specific item from the list */
|
|
14
|
+
remove(item: T): boolean;
|
|
15
|
+
/** Checks if an item exists in the list */
|
|
16
|
+
has(item: T): boolean;
|
|
17
|
+
/** Returns the number of items in the list */
|
|
18
|
+
size(): number;
|
|
19
|
+
/** Removes all items from the list */
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a FIFO (First-In-First-Out) list.
|
|
24
|
+
*
|
|
25
|
+
* @template T The type of elements in the list, must be an object.
|
|
26
|
+
* @returns {FifoList<T>} A FIFO list with methods to manipulate and query the list.
|
|
27
|
+
* @example Creating and using FIFO queue
|
|
28
|
+
* ```typescript
|
|
29
|
+
* interface Task { id: number; name: string }
|
|
30
|
+
* const queue = createFifoList<Task>()
|
|
31
|
+
*
|
|
32
|
+
* queue.push({ id: 1, name: 'first' })
|
|
33
|
+
* queue.push({ id: 2, name: 'second' })
|
|
34
|
+
*
|
|
35
|
+
* queue.pull() // => { id: 1, name: 'first' }
|
|
36
|
+
* queue.pull() // => { id: 2, name: 'second' }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function createFifoList<T extends object>(): FifoList<T>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A LIFO (Last-In-First-Out) list interface.
|
|
43
|
+
*/
|
|
44
|
+
interface LifoList<T extends object> {
|
|
45
|
+
/** Adds an item to the list */
|
|
46
|
+
push(item: T): void;
|
|
47
|
+
/** Removes and returns the last item in the list */
|
|
48
|
+
pull(): T | undefined;
|
|
49
|
+
/** Maps each item using the provided callback */
|
|
50
|
+
map<U>(callback: (item: T) => U): U[];
|
|
51
|
+
/** Iterates over each item in the list */
|
|
52
|
+
forEach(callback: (item: T) => void): void;
|
|
53
|
+
/** Removes a specific item from the list */
|
|
54
|
+
remove(item: T): boolean;
|
|
55
|
+
/** Checks if an item exists in the list */
|
|
56
|
+
has(item: T): boolean;
|
|
57
|
+
/** Returns the number of items in the list */
|
|
58
|
+
size(): number;
|
|
59
|
+
/** Removes all items from the list */
|
|
60
|
+
clear(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a LIFO (Last-In-First-Out) list.
|
|
64
|
+
*
|
|
65
|
+
* @template T The type of elements in the list, must be an object.
|
|
66
|
+
* @returns {LifoList<T>} A LIFO list with methods to manipulate and query the list.
|
|
67
|
+
* @example Creating and using LIFO stack
|
|
68
|
+
* ```typescript
|
|
69
|
+
* interface HistoryEntry { url: string; timestamp: number }
|
|
70
|
+
* const history = createLifoList<HistoryEntry>()
|
|
71
|
+
*
|
|
72
|
+
* history.push({ url: '/home', timestamp: 1 })
|
|
73
|
+
* history.push({ url: '/about', timestamp: 2 })
|
|
74
|
+
*
|
|
75
|
+
* history.pull() // => { url: '/about', timestamp: 2 }
|
|
76
|
+
* history.pull() // => { url: '/home', timestamp: 1 }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createLifoList<T extends object>(): LifoList<T>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Interface for cycling through a list of values.
|
|
83
|
+
*/
|
|
84
|
+
interface ValuePicker {
|
|
85
|
+
/** Returns the current value without advancing. */
|
|
86
|
+
current: () => string;
|
|
87
|
+
/** Advances and returns the next value, cycling at end. */
|
|
88
|
+
next: () => string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a value picker that cycles through a list of string values.
|
|
92
|
+
*
|
|
93
|
+
* @param values - The array of string values to cycle through
|
|
94
|
+
* @returns A ValuePicker instance with current and next methods
|
|
95
|
+
* @example Cycling through values
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const colorPicker = createValuePicker(['red', 'green', 'blue'])
|
|
98
|
+
*
|
|
99
|
+
* colorPicker.current() // => 'red'
|
|
100
|
+
* colorPicker.next() // => 'red' (first call initializes)
|
|
101
|
+
* colorPicker.next() // => 'green'
|
|
102
|
+
* colorPicker.next() // => 'blue'
|
|
103
|
+
* colorPicker.next() // => 'red' (cycles back)
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function createValuePicker(values: string[]): ValuePicker;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates an array of numbers within a specified range (inclusive).
|
|
110
|
+
*
|
|
111
|
+
* @param start - The starting number of the range
|
|
112
|
+
* @param end - The ending number of the range (inclusive)
|
|
113
|
+
* @returns An array containing all numbers from start to end
|
|
114
|
+
* @example Generating number ranges
|
|
115
|
+
* ```typescript
|
|
116
|
+
* createRange(1, 5)
|
|
117
|
+
* // => [1, 2, 3, 4, 5]
|
|
118
|
+
*
|
|
119
|
+
* createRange(3, 3)
|
|
120
|
+
* // => [3]
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function createRange(start: number, end: number): number[];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves the final key from a Map by converting keys to an array.
|
|
127
|
+
*
|
|
128
|
+
* @param map - The Map to extract the last key from
|
|
129
|
+
* @returns The key that was inserted last, or undefined if map is empty
|
|
130
|
+
* @example Getting last key from Map
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const userRoles = new Map<string, string>()
|
|
133
|
+
* userRoles.set('alice', 'admin')
|
|
134
|
+
* userRoles.set('bob', 'editor')
|
|
135
|
+
* userRoles.set('charlie', 'viewer')
|
|
136
|
+
*
|
|
137
|
+
* getLastKeyInMap(userRoles) // => 'charlie'
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare const getLastKeyInMap: <K = any>(map: Map<K, any>) => K;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Filters out empty, null, undefined, and whitespace-only strings from an array.
|
|
144
|
+
*
|
|
145
|
+
* @param values - The array of strings to filter
|
|
146
|
+
* @returns A new array containing only non-empty strings with content
|
|
147
|
+
* @example Filtering empty strings
|
|
148
|
+
* ```typescript
|
|
149
|
+
* nonEmptyStrings(['hello', '', ' ', 'world', null as unknown as string])
|
|
150
|
+
* // => ['hello', 'world']
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function nonEmptyStrings(values: string[]): string[];
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Removes duplicate strings from an array, preserving insertion order.
|
|
157
|
+
*
|
|
158
|
+
* @param values - The array of strings to deduplicate
|
|
159
|
+
* @returns A new array containing only unique strings
|
|
160
|
+
* @example Deduplicating strings
|
|
161
|
+
* ```typescript
|
|
162
|
+
* uniqueStrings(['apple', 'banana', 'apple', 'cherry', 'banana'])
|
|
163
|
+
* // => ['apple', 'banana', 'cherry']
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function uniqueStrings(values: string[]): string[];
|
|
167
|
+
|
|
168
|
+
export { createFifoList, createLifoList, createRange, createValuePicker, getLastKeyInMap, nonEmptyStrings, uniqueStrings };
|
|
169
|
+
export type { FifoList, LifoList, ValuePicker };
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/utils/list/src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/utils/list/src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA"}
|