react-hooks-global-states 15.0.5 → 15.0.7
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/index.d.ts +1 -1
- package/package.json +1 -1
- package/uniqueId.d.ts +68 -23
- package/uniqueId.js +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { StateApi, ObservableFragment, MetadataSetter, StateChanges, StoreTools, ActionCollectionResult, GlobalStoreCallbacks, UseHookOptions, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, BaseMetadata, MetadataGetter, SelectorCallback, SubscriberParameters, SubscriptionCallback, StateHook, ActionCollectionConfig, } from './types';
|
|
2
2
|
export { GlobalStore } from './GlobalStore';
|
|
3
|
-
export { createGlobalState, type InferActionsType, type InferStateApi } from './createGlobalState';
|
|
3
|
+
export { createGlobalState, type InferActionsType, type InferStateApi, AnyActions, } from './createGlobalState';
|
|
4
4
|
export { shallowCompare } from './shallowCompare';
|
|
5
5
|
export { uniqueId, type BrandedId } from './uniqueId';
|
|
6
6
|
export { throwWrongKeyOnActionCollectionConfig } from './throwWrongKeyOnActionCollectionConfig';
|
package/package.json
CHANGED
package/uniqueId.d.ts
CHANGED
|
@@ -1,31 +1,76 @@
|
|
|
1
|
+
export declare const __brand: unique symbol;
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Branded unique identifier
|
|
3
4
|
*/
|
|
4
5
|
export type BrandedId<T extends string | undefined> = `${T extends string ? T : ''}${string}` & {
|
|
5
|
-
__brand: T;
|
|
6
|
+
[__brand]: T;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* makeOrderId(); // e.g., "order:k9j3n5x8q2"
|
|
19
|
-
* makeOrderId.assert('order:k9j3n5x8q2'); // true
|
|
20
|
-
* makeOrderId.assert('user:k9j3n5x8q2
|
|
21
|
-
*/
|
|
22
|
-
export declare const uniqueId: {
|
|
8
|
+
interface UniqueId {
|
|
9
|
+
/**
|
|
10
|
+
* Generates a unique identifier string, optionally prefixed.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* uniqueId(); // "k9j3n5x8q2"
|
|
14
|
+
* type Id1 = `${string}` & { [__brand]: undefined };
|
|
15
|
+
*
|
|
16
|
+
* uniqueId('user:'); // "user:k9j3n5x8q2"
|
|
17
|
+
* type Id2 = `user:${string}` & { [__brand]: 'user:' };
|
|
18
|
+
*/
|
|
23
19
|
<T extends string | undefined>(prefix?: T): BrandedId<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a reusable unique ID generator for a specific prefix.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const makeOrderId = uniqueId.for('order:');
|
|
25
|
+
* const id = makeOrderId(); // "order:k9j3n5x8q2"
|
|
26
|
+
* type OrderId = `order:${string}` & { [__brand]: 'order:' };
|
|
27
|
+
*/
|
|
24
28
|
for<T extends string>(prefix: T): {
|
|
25
|
-
():
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
(): `${T}${string}` & {
|
|
30
|
+
[__brand]: T;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the given value matches the branded ID for this prefix.
|
|
34
|
+
*/
|
|
35
|
+
is(value: unknown): value is `${T}${string}` & {
|
|
36
|
+
[__brand]: T;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Asserts that the value matches this branded ID, throws otherwise.
|
|
40
|
+
*/
|
|
41
|
+
assert(value: unknown): asserts value is `${T}${string}` & {
|
|
42
|
+
[__brand]: T;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Returns a strictly branded generator using a custom symbol brand.
|
|
46
|
+
*/
|
|
47
|
+
strict<Brand extends symbol>(): {
|
|
48
|
+
(): `${T}${string}` & {
|
|
49
|
+
[__brand]: Brand;
|
|
50
|
+
};
|
|
51
|
+
is(value: unknown): value is `${T}${string}` & {
|
|
52
|
+
[__brand]: Brand;
|
|
53
|
+
};
|
|
54
|
+
assert(value: unknown): asserts value is `${T}${string}` & {
|
|
55
|
+
[__brand]: Brand;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
28
58
|
};
|
|
29
|
-
|
|
30
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Creates a reusable unique ID generator without a prefix.
|
|
61
|
+
*/
|
|
62
|
+
of<T extends string>(): () => string & {
|
|
63
|
+
[__brand]: T;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Creates a strictly branded unique ID generator without a prefix.
|
|
67
|
+
*/
|
|
68
|
+
strict<Brand extends symbol>(): () => string & {
|
|
69
|
+
[__brand]: Brand;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generates a unique identifier string, optionally prefixed.
|
|
74
|
+
*/
|
|
75
|
+
export declare const uniqueId: UniqueId;
|
|
31
76
|
export default uniqueId;
|
package/uniqueId.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t;t=()=>(()=>{"use strict";var t={};return((t,e)=>{var r,
|
|
1
|
+
var t;t=()=>(()=>{"use strict";var t={};return((t,e)=>{var n,r,o,u;Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueId=void 0,e.uniqueId=(n=0,r=function(){return n===Number.MAX_SAFE_INTEGER&&(n=0),n++},o=function(t,e){return(null!=t?t:"")+Date.now().toString(36)+e.toString(36)},(u=function(t){return o(t,r())}).for=function(t){var e=function(){return o(t,r())};return e.is=function(e){return"string"==typeof e&&e.startsWith(t)},e.assert=function(n){if(!e.is(n))throw new Error('The value "'.concat(String(n),'" does not match the expected prefix "').concat(String(t),'"'))},e.strict=function(){return e},e},u.of=function(){return u.for("")},u.strict=function(){return u},u),e.default=e.uniqueId})(0,t),t})(),"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-hooks-global-states"]=t():this["react-hooks-global-states"]=t();
|