react-hooks-global-states 15.0.6 → 15.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "15.0.6",
3
+ "version": "15.0.8",
4
4
  "description": "This is a package to easily handling global-state across your react-components using hooks.",
5
5
  "main": "./bundle.js",
6
6
  "types": "./index.d.ts",
@@ -143,8 +143,8 @@
143
143
  },
144
144
  "peerDependencies": {
145
145
  "json-storage-formatter": "^3.0.2",
146
- "react": "^18.0.0",
147
- "react-dom": "^18.0.0"
146
+ "react": ">=18.0.0",
147
+ "react-dom": ">=18.0.0"
148
148
  },
149
149
  "peerDependenciesMeta": {
150
150
  "react": {
package/uniqueId.d.ts CHANGED
@@ -1,31 +1,76 @@
1
+ export declare const __brand: unique symbol;
1
2
  /**
2
- * A branded unique identifier type
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
- * Generates a unique identifier string, optionally prefixed.
9
- * @param prefix - Optional string to prefix the unique ID
10
- * @returns A unique identifier string
11
- *
12
- * @example
13
- * uniqueId(); // e.g., "k9j3n5x8q2"
14
- * uniqueId('user:'); // e.g., "user:k9j3n5x8q2"
15
- *
16
- * // Creating a reusable unique ID generator for a specific prefix
17
- * const makeOrderId = uniqueId.for('order:');
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
- (): BrandedId<T>;
26
- is(value: unknown): value is BrandedId<T>;
27
- assert(value: unknown): asserts value is BrandedId<T>;
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
- of<T extends string>(): () => BrandedId<T>;
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,n,o;Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueId=void 0,e.uniqueId=(r=0,n=function(t,e){return t+Date.now().toString(36)+e.toString(36)},(o=function(t){return r===Number.MAX_SAFE_INTEGER&&(r=0),n(t,r++)}).for=function(t){var e=0,r=function(){return e===Number.MAX_SAFE_INTEGER&&(e=0),n(t,e++)};return r.is=function(e){return"string"==typeof e&&e.startsWith(t)},r.assert=function(e){if(!r.is(e))throw new Error('The value "'.concat(String(e),'" does not match the expected prefix "').concat(String(t),'"'))},r},o.of=function(){return function(){return o()}},o),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();
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();