@alessiofrittoli/react-hooks 4.1.1 → 4.2.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/README.md +509 -2
- package/dist/chunk-OXQJOVCZ.mjs +1 -0
- package/dist/chunk-SV2TCLLE.js +1 -0
- package/dist/misc/queue/index.d.mts +266 -0
- package/dist/misc/queue/index.d.ts +266 -0
- package/dist/misc/queue/index.js +1 -0
- package/dist/misc/queue/index.mjs +1 -0
- package/dist/misc/queue/utils.d.mts +104 -0
- package/dist/misc/queue/utils.d.ts +104 -0
- package/dist/misc/queue/utils.js +1 -0
- package/dist/misc/queue/utils.mjs +1 -0
- package/dist/types-Cx6f9FS1.d.mts +83 -0
- package/dist/types-Cx6f9FS1.d.ts +83 -0
- package/package.json +30 -10
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { g as QueuedItems, U as UUID, d as QueueItem, f as QueuedItem, e as QueueItems } from '../../types-Cx6f9FS1.js';
|
|
2
|
+
import '@alessiofrittoli/math-utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Adds a UUID to the given item.
|
|
6
|
+
*
|
|
7
|
+
* @template T The type of the given item, must extend object.
|
|
8
|
+
* @param item The item to add a UUID to.
|
|
9
|
+
* @returns A new item with the same properties as the input item plus a UUID.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const item = { foo: 'bar' }
|
|
14
|
+
* const newItem = addItemUUID( item )
|
|
15
|
+
* // Returns: { foo: 'bar', uuid: 'XXXXXXXX-XXXX-4XXX-YXXX-XXXXXXXXXXXX' }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare const addItemUUID: <T extends object = object>(item: QueueItem<T> | QueuedItem<T>) => QueuedItem<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Adds a UUID to one or more items.
|
|
21
|
+
*
|
|
22
|
+
* If a single item is provided, it is normalized to an array and returned as
|
|
23
|
+
* a one-element list with generated UUIDs.
|
|
24
|
+
*
|
|
25
|
+
* @template T The type of the given item, must extend object.
|
|
26
|
+
* @param items A single item or an array of items where UUIDs are added to.
|
|
27
|
+
* @returns An array of items with a UUID on each item.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const result = addItemsUUID( [ { foo: 'bar' } ] )
|
|
32
|
+
* // Returns: [ { foo: 'bar', uuid: '...' } ]
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare const addItemsUUID: <T extends object = object>(items: QueueItem<T> | QueuedItem<T> | QueueItems<T> | QueuedItems<T>) => QueuedItems<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Adds a UUID to the given item only when it does not already define one.
|
|
38
|
+
*
|
|
39
|
+
* @template T The type of the given item, must extend object.
|
|
40
|
+
* @param item The item to normalize with a UUID.
|
|
41
|
+
* @returns A new item with a guaranteed UUID.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const result = maybeAddItemUUID( { foo: 'bar' } )
|
|
46
|
+
* // Returns: { foo: 'bar', uuid: '...' }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare const maybeAddItemUUID: <T extends object = object>(item: QueueItem<T> | QueuedItem<T>) => QueuedItem<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Adds UUIDs to one or more items, preserving existing UUIDs when present.
|
|
52
|
+
*
|
|
53
|
+
* If a single item is provided, it is normalized to an array and returned as
|
|
54
|
+
* a one-element list.
|
|
55
|
+
*
|
|
56
|
+
* @template T The type of the given item, must extend object.
|
|
57
|
+
* @param items A single item or an array of items to normalize with UUIDs.
|
|
58
|
+
* @returns An array of items with UUIDs on each item.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = maybeAddItemsUUID( [ { foo: 'bar' }, { foo: 'baz', uuid: '1' } ] )
|
|
63
|
+
* // Returns: [ { foo: 'bar', uuid: '...' }, { foo: 'baz', uuid: '1' } ]
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare const maybeAddItemsUUID: <T extends object = object>(items: QueueItem<T> | QueuedItem<T> | (QueueItem<T> | QueuedItem<T>)[]) => QueuedItems<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Finds the index of the item matching the given UUID.
|
|
69
|
+
*
|
|
70
|
+
* @param items The queue items to search in.
|
|
71
|
+
* @param uuid The UUID to match.
|
|
72
|
+
* @returns The matching index, or `-1` when the UUID is missing or not found.
|
|
73
|
+
*/
|
|
74
|
+
declare const findIndexByUUID: (items: QueuedItems, uuid?: UUID) => number;
|
|
75
|
+
interface GetEffectiveQueueOptions<T extends object = object> {
|
|
76
|
+
/**
|
|
77
|
+
* The main queue.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
queue: QueuedItems<T>;
|
|
81
|
+
/**
|
|
82
|
+
* The custom queue.
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
customQueue: QueuedItems<T>;
|
|
86
|
+
/**
|
|
87
|
+
* The UUID after which the custom items are inserted.
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
uuid?: UUID;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the queue with `customQueue` inserted after the item identified by `uuid`.
|
|
94
|
+
*
|
|
95
|
+
* If `uuid` is not provided, the original queue is returned unchanged. If `uuid`
|
|
96
|
+
* is provided but not found, `customQueue` is appended to the end of `queue`.
|
|
97
|
+
*
|
|
98
|
+
* @template T The type of the queue items, must extend object.
|
|
99
|
+
* @param options An object defining required parameters. See {@link GetEffectiveQueueOptions}.
|
|
100
|
+
* @returns The effective queue.
|
|
101
|
+
*/
|
|
102
|
+
declare const getEffectiveQueue: <T extends object = object>(options: GetEffectiveQueueOptions<T>) => QueuedItems<T>;
|
|
103
|
+
|
|
104
|
+
export { type GetEffectiveQueueOptions, addItemUUID, addItemsUUID, findIndexByUUID, getEffectiveQueue, maybeAddItemUUID, maybeAddItemsUUID };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSV2TCLLEjs = require('../../chunk-SV2TCLLE.js');exports.addItemUUID = _chunkSV2TCLLEjs.a; exports.addItemsUUID = _chunkSV2TCLLEjs.b; exports.findIndexByUUID = _chunkSV2TCLLEjs.e; exports.getEffectiveQueue = _chunkSV2TCLLEjs.f; exports.maybeAddItemUUID = _chunkSV2TCLLEjs.c; exports.maybeAddItemsUUID = _chunkSV2TCLLEjs.d;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f}from"../../chunk-OXQJOVCZ.mjs";export{a as addItemUUID,b as addItemsUUID,e as findIndexByUUID,f as getEffectiveQueue,c as maybeAddItemUUID,d as maybeAddItemsUUID};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { UUID as UUID$1 } from '@alessiofrittoli/math-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UUID type alias used by queue items.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
type UUID = UUID$1;
|
|
8
|
+
/**
|
|
9
|
+
* Queue item with an optional UUID.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
type QueueItem<T extends object = object> = T & {
|
|
13
|
+
/**
|
|
14
|
+
* Optional item UUID.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
uuid?: UUID;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* List of queued items.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
type QueueItems<T extends object = object> = QueueItem<T>[];
|
|
24
|
+
/**
|
|
25
|
+
* Queue item with a required UUID.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
type QueuedItem<T extends object = object> = QueueItem<T> & {
|
|
29
|
+
/**
|
|
30
|
+
* Item UUID.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
uuid: UUID;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* List of queued items.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
type QueuedItems<T extends object = object> = QueuedItem<T>[];
|
|
40
|
+
/**
|
|
41
|
+
* Item shape accepted when enqueuing, with an optional UUID.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
type OptionalQueuedItem<T extends object = object> = Omit<T, 'uuid'> & Pick<QueueItem<Omit<T, 'uuid'>>, 'uuid'>;
|
|
45
|
+
/**
|
|
46
|
+
* List of items accepted when enqueuing.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
type OptionalQueuedItems<T extends object = object> = OptionalQueuedItem<T>[];
|
|
50
|
+
/**
|
|
51
|
+
* Defines the queue.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
interface Queue<T extends object = object> {
|
|
55
|
+
/**
|
|
56
|
+
* The queue items.
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
items: QueuedItems<T>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extracts the queued items type from a queue.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
type QueuedItemsType<T extends Queue = Queue> = T['items'];
|
|
66
|
+
/**
|
|
67
|
+
* Extracts the queued item type from a queue.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
type QueuedItemType<T extends Queue = Queue> = QueuedItemsType<T>[number];
|
|
71
|
+
/**
|
|
72
|
+
* Queue shape used when creating a new queue with optional item UUIDs.
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
type NewQueue<T extends Queue = Queue> = Omit<T, 'items'> & {
|
|
76
|
+
/**
|
|
77
|
+
* The queue items.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
items: OptionalQueuedItems<QueuedItemType<T>>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type { NewQueue as N, OptionalQueuedItem as O, Queue as Q, UUID as U, QueuedItemType as a, QueuedItemsType as b, OptionalQueuedItems as c, QueueItem as d, QueueItems as e, QueuedItem as f, QueuedItems as g };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { UUID as UUID$1 } from '@alessiofrittoli/math-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UUID type alias used by queue items.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
type UUID = UUID$1;
|
|
8
|
+
/**
|
|
9
|
+
* Queue item with an optional UUID.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
type QueueItem<T extends object = object> = T & {
|
|
13
|
+
/**
|
|
14
|
+
* Optional item UUID.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
uuid?: UUID;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* List of queued items.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
type QueueItems<T extends object = object> = QueueItem<T>[];
|
|
24
|
+
/**
|
|
25
|
+
* Queue item with a required UUID.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
type QueuedItem<T extends object = object> = QueueItem<T> & {
|
|
29
|
+
/**
|
|
30
|
+
* Item UUID.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
uuid: UUID;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* List of queued items.
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
type QueuedItems<T extends object = object> = QueuedItem<T>[];
|
|
40
|
+
/**
|
|
41
|
+
* Item shape accepted when enqueuing, with an optional UUID.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
type OptionalQueuedItem<T extends object = object> = Omit<T, 'uuid'> & Pick<QueueItem<Omit<T, 'uuid'>>, 'uuid'>;
|
|
45
|
+
/**
|
|
46
|
+
* List of items accepted when enqueuing.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
type OptionalQueuedItems<T extends object = object> = OptionalQueuedItem<T>[];
|
|
50
|
+
/**
|
|
51
|
+
* Defines the queue.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
interface Queue<T extends object = object> {
|
|
55
|
+
/**
|
|
56
|
+
* The queue items.
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
items: QueuedItems<T>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extracts the queued items type from a queue.
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
type QueuedItemsType<T extends Queue = Queue> = T['items'];
|
|
66
|
+
/**
|
|
67
|
+
* Extracts the queued item type from a queue.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
type QueuedItemType<T extends Queue = Queue> = QueuedItemsType<T>[number];
|
|
71
|
+
/**
|
|
72
|
+
* Queue shape used when creating a new queue with optional item UUIDs.
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
type NewQueue<T extends Queue = Queue> = Omit<T, 'items'> & {
|
|
76
|
+
/**
|
|
77
|
+
* The queue items.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
items: OptionalQueuedItems<QueuedItemType<T>>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type { NewQueue as N, OptionalQueuedItem as O, Queue as Q, UUID as U, QueuedItemType as a, QueuedItemsType as b, OptionalQueuedItems as c, QueueItem as d, QueueItems as e, QueuedItem as f, QueuedItems as g };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/react-hooks",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "TypeScript React utility Hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Alessio Frittoli",
|
|
@@ -44,6 +44,26 @@
|
|
|
44
44
|
"default": "./dist/index.js"
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
"./queue": {
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./dist/misc/queue/index.d.mts",
|
|
50
|
+
"default": "./dist/misc/queue/index.mjs"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./dist/misc/queue/index.d.ts",
|
|
54
|
+
"default": "./dist/misc/queue/index.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./queue/utils": {
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/misc/queue/utils.d.mts",
|
|
60
|
+
"default": "./dist/misc/queue/utils.mjs"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./dist/misc/queue/utils.d.ts",
|
|
64
|
+
"default": "./dist/misc/queue/utils.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
47
67
|
"./eslint": {
|
|
48
68
|
"import": {
|
|
49
69
|
"types": "./dist/eslint.d.mts",
|
|
@@ -96,39 +116,39 @@
|
|
|
96
116
|
"devDependencies": {
|
|
97
117
|
"@alessiofrittoli/event-emitter": "^1.6.0",
|
|
98
118
|
"@alessiofrittoli/node-scripts": "^3.3.0",
|
|
99
|
-
"@eslint/compat": "^2.0.
|
|
100
|
-
"@eslint/eslintrc": "^3.3.
|
|
119
|
+
"@eslint/compat": "^2.0.3",
|
|
120
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
101
121
|
"@eslint/js": "^10.0.1",
|
|
102
|
-
"@jest/globals": "^30.
|
|
122
|
+
"@jest/globals": "^30.3.0",
|
|
103
123
|
"@testing-library/dom": "^10.4.1",
|
|
104
124
|
"@testing-library/jest-dom": "^6.9.1",
|
|
105
125
|
"@testing-library/react": "^16.3.2",
|
|
106
126
|
"@testing-library/user-event": "^14.6.1",
|
|
107
127
|
"@types/jest": "^30.0.0",
|
|
108
|
-
"@types/node": "^25.
|
|
128
|
+
"@types/node": "^25.5.0",
|
|
109
129
|
"@types/react": "^19.2.14",
|
|
110
130
|
"@types/react-dom": "^19.2.3",
|
|
111
131
|
"concurrently": "^9.2.1",
|
|
112
132
|
"cross-env": "^10.1.0",
|
|
113
133
|
"dotenv": "^17.3.1",
|
|
114
|
-
"eslint": "^10.0.
|
|
134
|
+
"eslint": "^10.0.3",
|
|
115
135
|
"eslint-plugin-react": "^7.37.5",
|
|
116
136
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
117
137
|
"globals": "^17.4.0",
|
|
118
138
|
"http-server": "^14.1.1",
|
|
119
|
-
"jest": "^30.
|
|
120
|
-
"jest-environment-jsdom": "^30.
|
|
139
|
+
"jest": "^30.3.0",
|
|
140
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
121
141
|
"react": "^19.2.4",
|
|
122
142
|
"react-dom": "^19.2.4",
|
|
123
143
|
"ts-jest": "^29.4.6",
|
|
124
144
|
"ts-node": "^10.9.2",
|
|
125
145
|
"tsup": "^8.5.1",
|
|
126
146
|
"typescript": "^5.9.3",
|
|
127
|
-
"typescript-eslint": "^8.
|
|
147
|
+
"typescript-eslint": "^8.57.0"
|
|
128
148
|
},
|
|
129
149
|
"dependencies": {
|
|
130
150
|
"@alessiofrittoli/math-utils": "^2.0.0",
|
|
131
151
|
"@alessiofrittoli/type-utils": "^1.9.0",
|
|
132
|
-
"@alessiofrittoli/web-utils": "^2.
|
|
152
|
+
"@alessiofrittoli/web-utils": "^2.3.0"
|
|
133
153
|
}
|
|
134
154
|
}
|