@cmtlyt/lingshu-toolkit 0.5.0 → 0.7.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.
Files changed (211) hide show
  1. package/README.md +10 -0
  2. package/dist/665.js +1 -0
  3. package/dist/893.js +1 -0
  4. package/dist/react/index.js +1 -205
  5. package/dist/react/use-boolean/index.d.ts +2 -1
  6. package/dist/react/use-boolean/index.js +1 -16
  7. package/dist/react/use-controllable-value/index.d.ts +3 -3
  8. package/dist/react/use-controllable-value/index.js +1 -32
  9. package/dist/react/use-counter/index.d.ts +2 -2
  10. package/dist/react/use-counter/index.js +1 -49
  11. package/dist/react/use-force-update/index.d.ts +2 -1
  12. package/dist/react/use-force-update/index.js +1 -6
  13. package/dist/react/use-mount/index.d.ts +2 -1
  14. package/dist/react/use-mount/index.js +1 -16
  15. package/dist/react/use-ref-state/index.d.ts +3 -2
  16. package/dist/react/use-ref-state/index.js +1 -33
  17. package/dist/react/use-storage/index.d.ts +2 -1
  18. package/dist/react/use-storage/index.js +1 -15
  19. package/dist/react/use-title/index.d.ts +2 -2
  20. package/dist/react/use-title/index.js +1 -24
  21. package/dist/react/use-toggle/index.d.ts +4 -4
  22. package/dist/react/use-toggle/index.js +1 -26
  23. package/dist/react/use-valid-data/index.d.ts +5 -4
  24. package/dist/react/use-valid-data/index.js +1 -14
  25. package/dist/shared/allx/index.d.ts +2 -1
  26. package/dist/shared/allx/index.js +1 -44
  27. package/dist/shared/allx/types.d.ts +6 -0
  28. package/dist/shared/allx/utils.d.ts +9 -7
  29. package/dist/shared/allx/utils.js +1 -94
  30. package/dist/shared/animation/index.d.ts +3 -2
  31. package/dist/shared/animation/index.js +1 -77
  32. package/dist/shared/animation/types.d.ts +8 -0
  33. package/dist/shared/animation/utils.d.ts +3 -10
  34. package/dist/shared/animation/utils.js +1 -134
  35. package/dist/shared/api-controller/create-api.js +1 -79
  36. package/dist/shared/api-controller/index.js +1 -3
  37. package/dist/shared/api-controller/request.js +1 -66
  38. package/dist/shared/api-controller/types.d.ts +26 -27
  39. package/dist/shared/api-controller/utils.d.ts +6 -15
  40. package/dist/shared/api-controller/utils.js +1 -96
  41. package/dist/shared/condition-merge/index.d.ts +6 -6
  42. package/dist/shared/condition-merge/index.js +1 -30
  43. package/dist/shared/create-storage-handler/index.d.ts +4 -3
  44. package/dist/shared/create-storage-handler/index.js +1 -68
  45. package/dist/shared/data-handler/index.d.ts +4 -3
  46. package/dist/shared/data-handler/index.js +1 -77
  47. package/dist/shared/data-handler/tools.d.ts +6 -23
  48. package/dist/shared/data-handler/tools.js +1 -48
  49. package/dist/shared/data-handler/types.d.ts +20 -2
  50. package/dist/shared/data-mixed-manager/constants.js +1 -9
  51. package/dist/shared/data-mixed-manager/index.js +1 -226
  52. package/dist/shared/data-mixed-manager/types.d.ts +1 -2
  53. package/dist/shared/index.d.ts +2 -0
  54. package/dist/shared/index.js +1 -957
  55. package/dist/shared/lock-data/__test__/_helpers/memory-adapters.d.ts +95 -0
  56. package/dist/shared/lock-data/__test__/_helpers/memory-adapters.js +1 -0
  57. package/dist/shared/lock-data/__test__/playground.js +1 -0
  58. package/dist/shared/lock-data/adapters/authority.d.ts +40 -0
  59. package/dist/shared/lock-data/adapters/authority.js +1 -0
  60. package/dist/shared/lock-data/adapters/channel.d.ts +39 -0
  61. package/dist/shared/lock-data/adapters/channel.js +1 -0
  62. package/dist/shared/lock-data/adapters/index.d.ts +58 -0
  63. package/dist/shared/lock-data/adapters/index.js +1 -0
  64. package/dist/shared/lock-data/adapters/logger.d.ts +56 -0
  65. package/dist/shared/lock-data/adapters/logger.js +1 -0
  66. package/dist/shared/lock-data/adapters/session-store.d.ts +37 -0
  67. package/dist/shared/lock-data/adapters/session-store.js +1 -0
  68. package/dist/shared/lock-data/authority/epoch.d.ts +135 -0
  69. package/dist/shared/lock-data/authority/epoch.js +1 -0
  70. package/dist/shared/lock-data/authority/extract.d.ts +107 -0
  71. package/dist/shared/lock-data/authority/extract.js +1 -0
  72. package/dist/shared/lock-data/authority/index.d.ts +182 -0
  73. package/dist/shared/lock-data/authority/index.js +1 -0
  74. package/dist/shared/lock-data/authority/serialize.d.ts +35 -0
  75. package/dist/shared/lock-data/authority/serialize.js +1 -0
  76. package/dist/shared/lock-data/constants.d.ts +46 -0
  77. package/dist/shared/lock-data/constants.js +1 -0
  78. package/dist/shared/lock-data/core/actions-helpers.d.ts +163 -0
  79. package/dist/shared/lock-data/core/actions-helpers.js +1 -0
  80. package/dist/shared/lock-data/core/actions.d.ts +72 -0
  81. package/dist/shared/lock-data/core/actions.js +1 -0
  82. package/dist/shared/lock-data/core/draft.d.ts +64 -0
  83. package/dist/shared/lock-data/core/draft.js +1 -0
  84. package/dist/shared/lock-data/core/entry.d.ts +133 -0
  85. package/dist/shared/lock-data/core/entry.js +1 -0
  86. package/dist/shared/lock-data/core/fanout.d.ts +42 -0
  87. package/dist/shared/lock-data/core/fanout.js +1 -0
  88. package/dist/shared/lock-data/core/readonly-view.d.ts +49 -0
  89. package/dist/shared/lock-data/core/readonly-view.js +1 -0
  90. package/dist/shared/lock-data/core/registry.d.ts +282 -0
  91. package/dist/shared/lock-data/core/registry.js +1 -0
  92. package/dist/shared/lock-data/core/signal.d.ts +33 -0
  93. package/dist/shared/lock-data/core/signal.js +1 -0
  94. package/dist/shared/lock-data/drivers/broadcast-protocol.d.ts +71 -0
  95. package/dist/shared/lock-data/drivers/broadcast-protocol.js +1 -0
  96. package/dist/shared/lock-data/drivers/broadcast-state.d.ts +125 -0
  97. package/dist/shared/lock-data/drivers/broadcast-state.js +1 -0
  98. package/dist/shared/lock-data/drivers/broadcast.d.ts +36 -0
  99. package/dist/shared/lock-data/drivers/broadcast.js +1 -0
  100. package/dist/shared/lock-data/drivers/custom.d.ts +27 -0
  101. package/dist/shared/lock-data/drivers/custom.js +1 -0
  102. package/dist/shared/lock-data/drivers/index.d.ts +59 -0
  103. package/dist/shared/lock-data/drivers/index.js +1 -0
  104. package/dist/shared/lock-data/drivers/local.d.ts +86 -0
  105. package/dist/shared/lock-data/drivers/local.js +1 -0
  106. package/dist/shared/lock-data/drivers/storage-protocol.d.ts +67 -0
  107. package/dist/shared/lock-data/drivers/storage-protocol.js +1 -0
  108. package/dist/shared/lock-data/drivers/storage-state.d.ts +103 -0
  109. package/dist/shared/lock-data/drivers/storage-state.js +1 -0
  110. package/dist/shared/lock-data/drivers/storage.d.ts +71 -0
  111. package/dist/shared/lock-data/drivers/storage.js +1 -0
  112. package/dist/shared/lock-data/drivers/types.d.ts +73 -0
  113. package/dist/shared/lock-data/drivers/types.js +0 -0
  114. package/dist/shared/lock-data/drivers/web-locks.d.ts +123 -0
  115. package/dist/shared/lock-data/drivers/web-locks.js +1 -0
  116. package/dist/shared/lock-data/errors/index.d.ts +12 -0
  117. package/dist/shared/lock-data/errors/index.js +1 -0
  118. package/dist/shared/lock-data/errors/invalid-options-error.d.ts +11 -0
  119. package/dist/shared/lock-data/errors/invalid-options-error.js +1 -0
  120. package/dist/shared/lock-data/errors/lock-aborted-error.d.ts +10 -0
  121. package/dist/shared/lock-data/errors/lock-aborted-error.js +1 -0
  122. package/dist/shared/lock-data/errors/lock-disposed-error.d.ts +14 -0
  123. package/dist/shared/lock-data/errors/lock-disposed-error.js +1 -0
  124. package/dist/shared/lock-data/errors/lock-revoked-error.d.ts +10 -0
  125. package/dist/shared/lock-data/errors/lock-revoked-error.js +1 -0
  126. package/dist/shared/lock-data/errors/lock-timeout-error.d.ts +9 -0
  127. package/dist/shared/lock-data/errors/lock-timeout-error.js +1 -0
  128. package/dist/shared/lock-data/errors/readonly-mutation-error.d.ts +11 -0
  129. package/dist/shared/lock-data/errors/readonly-mutation-error.js +1 -0
  130. package/dist/shared/lock-data/index.d.ts +57 -0
  131. package/dist/shared/lock-data/index.js +1 -0
  132. package/dist/shared/lock-data/types.d.ts +347 -0
  133. package/dist/shared/lock-data/types.js +0 -0
  134. package/dist/shared/lock-data/utils/json-safe.d.ts +69 -0
  135. package/dist/shared/lock-data/utils/json-safe.js +1 -0
  136. package/dist/shared/logger/index.d.ts +2 -2
  137. package/dist/shared/logger/index.js +1 -10
  138. package/dist/shared/priority-queue/index.d.ts +45 -0
  139. package/dist/shared/priority-queue/index.js +1 -0
  140. package/dist/shared/priority-queue/types.d.ts +10 -0
  141. package/dist/shared/priority-queue/types.js +0 -0
  142. package/dist/shared/priority-queue/utils.d.ts +7 -0
  143. package/dist/shared/priority-queue/utils.js +1 -0
  144. package/dist/shared/throw-error/index.d.ts +11 -3
  145. package/dist/shared/throw-error/index.js +1 -10
  146. package/dist/shared/try-call/index.d.ts +3 -3
  147. package/dist/shared/try-call/index.js +1 -59
  148. package/dist/shared/types/index.js +1 -2
  149. package/dist/shared/types/pack.d.ts +2 -2
  150. package/dist/shared/types/pack.js +1 -1
  151. package/dist/shared/utils/base.d.ts +1 -1
  152. package/dist/shared/utils/base.js +1 -6
  153. package/dist/shared/utils/index.js +1 -2
  154. package/dist/shared/utils/verify.d.ts +1 -1
  155. package/dist/shared/utils/verify.js +1 -67
  156. package/dist/shared/with-resolvers/index.d.ts +5 -3
  157. package/dist/shared/with-resolvers/index.js +1 -15
  158. package/dist/vue/index.js +1 -29
  159. package/dist/vue/use-title/index.d.ts +2 -2
  160. package/dist/vue/use-title/index.js +1 -29
  161. package/package.json +27 -27
  162. package/dist/247.js +0 -66
  163. package/dist/707.js +0 -142
  164. package/dist/react/use-force-update/index.test.d.ts +0 -1
  165. package/dist/react/use-mount/index.test.d.ts +0 -1
  166. package/dist/react/use-ref-state/index.test.d.ts +0 -1
  167. package/dist/react/use-storage/index.test.d.ts +0 -1
  168. package/dist/react/use-title/index.test.d.ts +0 -1
  169. package/dist/react/use-toggle/index.test.d.ts +0 -1
  170. package/dist/react/use-valid-data/index.test.d.ts +0 -1
  171. package/dist/shared/allx/__test__/allsettled.test.d.ts +0 -1
  172. package/dist/shared/allx/__test__/basic.test.d.ts +0 -1
  173. package/dist/shared/allx/__test__/circular-dependency.test.d.ts +0 -1
  174. package/dist/shared/allx/__test__/dependency.test.d.ts +0 -1
  175. package/dist/shared/allx/__test__/edge-cases.test.d.ts +0 -1
  176. package/dist/shared/allx/__test__/error-handling.test.d.ts +0 -1
  177. package/dist/shared/allx/__test__/execution-order.test.d.ts +0 -1
  178. package/dist/shared/allx/__test__/falsy-values.test.d.ts +0 -1
  179. package/dist/shared/allx/__test__/performance.test.d.ts +0 -1
  180. package/dist/shared/allx/__test__/type-checking.test.d.ts +0 -1
  181. package/dist/shared/allx/__test__/use-cases.test.d.ts +0 -1
  182. package/dist/shared/animation/__test__/animation-pause-resume.test.d.ts +0 -1
  183. package/dist/shared/animation/__test__/animation.test.d.ts +0 -1
  184. package/dist/shared/animation/__test__/step-animation.test.d.ts +0 -1
  185. package/dist/shared/animation/__test__/utils.test.d.ts +0 -1
  186. package/dist/shared/api-controller/__test__/index.browser.test.d.ts +0 -1
  187. package/dist/shared/api-controller/__test__/index.node.test.d.ts +0 -1
  188. package/dist/shared/condition-merge/index.test-d.js +0 -108
  189. package/dist/shared/condition-merge/index.test.d.ts +0 -1
  190. package/dist/shared/create-storage-handler/index.browser.test.d.ts +0 -1
  191. package/dist/shared/create-storage-handler/index.test.d.ts +0 -1
  192. package/dist/shared/data-handler/index.test.d.ts +0 -1
  193. package/dist/shared/data-mixed-manager/__test__/basic.test.d.ts +0 -1
  194. package/dist/shared/data-mixed-manager/__test__/build-options.test.d.ts +0 -1
  195. package/dist/shared/data-mixed-manager/__test__/constructor-options.test.d.ts +0 -1
  196. package/dist/shared/data-mixed-manager/__test__/data-management.test.d.ts +0 -1
  197. package/dist/shared/data-mixed-manager/__test__/edge-cases.test.d.ts +0 -1
  198. package/dist/shared/data-mixed-manager/__test__/events.browser.test.d.ts +0 -1
  199. package/dist/shared/data-mixed-manager/__test__/events.test.d.ts +0 -1
  200. package/dist/shared/data-mixed-manager/__test__/fixed-slots.test.d.ts +0 -1
  201. package/dist/shared/data-mixed-manager/__test__/insert-mode.test.d.ts +0 -1
  202. package/dist/shared/throw-error/index.test.d.ts +0 -1
  203. package/dist/shared/try-call/index.test.d.ts +0 -1
  204. package/dist/shared/utils/__test__/base.test.d.ts +0 -1
  205. package/dist/shared/utils/__test__/verify.test.d.ts +0 -1
  206. package/dist/shared/with-resolvers/index.test.d.ts +0 -1
  207. package/dist/test/utils.d.ts +0 -13
  208. package/dist/vue/use-title/index.test.d.ts +0 -1
  209. /package/dist/{react/use-boolean/index.test.d.ts → shared/lock-data/__test__/index.test-d.d.ts} +0 -0
  210. /package/dist/{react/use-controllable-value/index.test.d.ts → shared/lock-data/__test__/integration/entry.test-d.d.ts} +0 -0
  211. /package/dist/{react/use-counter/index.test.d.ts → shared/lock-data/__test__/playground.d.ts} +0 -0
@@ -1 +1 @@
1
- Symbol('__PACK__');
1
+ Symbol("__PACK__");
@@ -1,3 +1,3 @@
1
- export declare const noop: () => undefined;
1
+ export declare const noop: () => void;
2
2
  export declare const identity: <T>(_v: T) => T;
3
3
  export declare function getType(_v: any): string;
@@ -1,6 +1 @@
1
- const noop = ()=>void 0;
2
- const identity = (_v)=>_v;
3
- function getType(_v) {
4
- return Object.prototype.toString.call(_v).slice(8, -1).toLowerCase();
5
- }
6
- export { getType, identity, noop };
1
+ let t=()=>void 0,e=t=>t;function o(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}export{o as getType,e as identity,t as noop};
@@ -1,2 +1 @@
1
- export * from "./base.js";
2
- export * from "./verify.js";
1
+ export*from"./base.js";export*from"./verify.js";
@@ -49,5 +49,5 @@ export declare function isTruthy<T>(_v: T): _v is Exclude<T, false | 0 | '' | nu
49
49
  export declare function isFalsy(_v: unknown): _v is false | 0 | '' | null | undefined;
50
50
  /** 判断是一个函数 */
51
51
  export declare function isFunction(_v: unknown): _v is AnyFunc;
52
- /** 判断是一个 Promise */
52
+ /** 判断是一个 PromiseLike */
53
53
  export declare function isPromiseLike(_v: unknown): _v is PromiseLike<any>;
@@ -1,67 +1 @@
1
- function isSymbol(_v) {
2
- return 'symbol' == typeof _v;
3
- }
4
- function isUndef(_v) {
5
- return void 0 === _v;
6
- }
7
- function isNull(_v) {
8
- return null === _v;
9
- }
10
- function isNullOrUndef(_v) {
11
- return isNull(_v) || isUndef(_v);
12
- }
13
- function verify_isNaN(_v) {
14
- return Number.isNaN(_v);
15
- }
16
- function isPlainSymbol(_v) {
17
- return isSymbol(_v) && isUndef(Symbol.keyFor(_v));
18
- }
19
- function isObject(_v) {
20
- return 'object' == typeof _v && !isNull(_v);
21
- }
22
- function isPlainObject(_v) {
23
- return isObject(_v) && !isArray(_v);
24
- }
25
- function isArray(_v) {
26
- return Array.isArray(_v);
27
- }
28
- function isEmptyArray(_v) {
29
- return isArray(_v) && 0 === _v.length;
30
- }
31
- function isString(_v) {
32
- return 'string' == typeof _v;
33
- }
34
- function isEmptyString(_v) {
35
- return isString(_v) && 0 === _v.length;
36
- }
37
- function isNumber(_v) {
38
- return 'number' == typeof _v;
39
- }
40
- function isPlainNumber(_v) {
41
- return isNumber(_v) && !verify_isNaN(_v);
42
- }
43
- function isPropertyKey(_v) {
44
- return isString(_v) || isNumber(_v) || isSymbol(_v);
45
- }
46
- function isBoolean(_v) {
47
- return 'boolean' == typeof _v;
48
- }
49
- function isTrue(_v) {
50
- return true === _v || isString(_v) && 'true' === _v.toLowerCase();
51
- }
52
- function isFalse(_v) {
53
- return false === _v || isString(_v) && 'false' === _v.toLowerCase();
54
- }
55
- function isTruthy(_v) {
56
- return !!_v;
57
- }
58
- function isFalsy(_v) {
59
- return !(verify_isNaN(_v) || _v);
60
- }
61
- function isFunction(_v) {
62
- return 'function' == typeof _v;
63
- }
64
- function isPromiseLike(_v) {
65
- return isObject(_v) && isFunction(_v.then);
66
- }
67
- export { isArray, isBoolean, isEmptyArray, isEmptyString, isFalse, isFalsy, isFunction, verify_isNaN as isNaN, isNull, isNullOrUndef, isNumber, isObject, isPlainNumber, isPlainObject, isPlainSymbol, isPromiseLike, isPropertyKey, isString, isSymbol, isTrue, isTruthy, isUndef };
1
+ function n(n){return"symbol"==typeof n}function r(n){return void 0===n}function t(n){return null===n}function i(n){return t(n)||r(n)}function e(n){return Number.isNaN(n)}function u(t){return n(t)&&r(Symbol.keyFor(t))}function o(n){return"object"==typeof n&&!t(n)}function s(n){return o(n)&&!f(n)}function f(n){return Array.isArray(n)}function c(n){return f(n)&&0===n.length}function y(n){return"string"==typeof n}function l(n){return y(n)&&0===n.length}function a(n){return"number"==typeof n}function b(n){return a(n)&&!e(n)}function m(r){return y(r)||a(r)||n(r)}function N(n){return"boolean"==typeof n}function p(n){return!0===n||y(n)&&"true"===n.toLowerCase()}function g(n){return!1===n||y(n)&&"false"===n.toLowerCase()}function P(n){return!!n}function S(n){return!(e(n)||n)}function h(n){return"function"==typeof n}function A(n){return(o(n)||h(n))&&h(n.then)}export{f as isArray,N as isBoolean,c as isEmptyArray,l as isEmptyString,g as isFalse,S as isFalsy,h as isFunction,t as isNull,i as isNullOrUndef,a as isNumber,o as isObject,b as isPlainNumber,s as isPlainObject,u as isPlainSymbol,A as isPromiseLike,m as isPropertyKey,y as isString,n as isSymbol,p as isTrue,P as isTruthy,r as isUndef,e as isNaN};
@@ -1,6 +1,8 @@
1
- export type Resolver<T> = {
1
+ interface Resolver<T> {
2
2
  promise: Promise<T>;
3
3
  resolve: (value: T | PromiseLike<T>) => void;
4
4
  reject: (reason?: any) => void;
5
- };
6
- export declare function withResolvers<T>(): Resolver<T>;
5
+ }
6
+ declare function withResolvers<T>(): Resolver<T>;
7
+ export type { Resolver };
8
+ export { withResolvers };
@@ -1,15 +1 @@
1
- function withResolvers() {
2
- return 'function' == typeof Promise.withResolvers ? Promise.withResolvers() : (()=>{
3
- const resolver = {
4
- promise: null,
5
- resolve: null,
6
- reject: null
7
- };
8
- resolver.promise = new Promise((resolve, reject)=>{
9
- resolver.resolve = resolve;
10
- resolver.reject = reject;
11
- });
12
- return resolver;
13
- })();
14
- }
15
- export { withResolvers };
1
+ function e(){let e;return"function"==typeof Promise.withResolvers?Promise.withResolvers():((e={promise:null,resolve:null,reject:null}).promise=new Promise((r,o)=>{e.resolve=r,e.reject=o}),e)}export{e as withResolvers};
package/dist/vue/index.js CHANGED
@@ -1,29 +1 @@
1
- import { onScopeDispose, ref, toValue, watch } from "vue";
2
- import { dataHandler, $t, $dt } from "../707.js";
3
- function setTitle(title) {
4
- if (!title || "u" < typeof document) return;
5
- const oldTitle = document.title;
6
- document.title = title;
7
- return oldTitle;
8
- }
9
- const validInfo = $dt({
10
- restoreOnUnmount: $t.boolean(true)
11
- });
12
- function useTitle(newTitle = '', options = {}) {
13
- const { restoreOnUnmount } = dataHandler(options, validInfo, {
14
- unwrap: true
15
- });
16
- const title = ref(toValue(newTitle));
17
- const originalTitle = setTitle(title.value);
18
- watch(title, setTitle, {
19
- flush: 'sync'
20
- });
21
- watch(()=>toValue(newTitle), (value)=>{
22
- title.value = value;
23
- });
24
- if (restoreOnUnmount) onScopeDispose(()=>{
25
- setTitle(originalTitle);
26
- });
27
- return title;
28
- }
29
- export { useTitle };
1
+ import{onScopeDispose as t,ref as e,toValue as n,watch as u}from"vue";import{dataHandler as o,$t as r,$dt as l}from"../665.js";function i(t){if(!t||"u"<typeof document)return;let e=document.title;return document.title=t,e}let m=l({restoreOnUnmount:r.boolean(!0)});function f(r="",l={}){let{restoreOnUnmount:c}=o(l,m,{unwrap:!0}),a=e(n(r)),p=i(a.value);return u(a,i,{flush:"sync"}),u(()=>n(r),t=>{a.value=t}),c&&t(()=>{i(p)}),a}export{f as useTitle};
@@ -2,5 +2,5 @@ import { type MaybeRefOrGetter } from 'vue';
2
2
  interface UseTitleOptions {
3
3
  restoreOnUnmount: boolean;
4
4
  }
5
- export declare function useTitle(newTitle?: MaybeRefOrGetter<string>, options?: Partial<UseTitleOptions>): import("vue").Ref<string, string>;
6
- export {};
5
+ declare function useTitle(newTitle?: MaybeRefOrGetter<string>, options?: Partial<UseTitleOptions>): import("vue").Ref<string, string>;
6
+ export { useTitle };
@@ -1,29 +1 @@
1
- import { onScopeDispose, ref, toValue, watch } from "vue";
2
- import { $dt, $t, dataHandler } from "../../shared/data-handler/index.js";
3
- function setTitle(title) {
4
- if (!title || "u" < typeof document) return;
5
- const oldTitle = document.title;
6
- document.title = title;
7
- return oldTitle;
8
- }
9
- const validInfo = $dt({
10
- restoreOnUnmount: $t.boolean(true)
11
- });
12
- function useTitle(newTitle = '', options = {}) {
13
- const { restoreOnUnmount } = dataHandler(options, validInfo, {
14
- unwrap: true
15
- });
16
- const title = ref(toValue(newTitle));
17
- const originalTitle = setTitle(title.value);
18
- watch(title, setTitle, {
19
- flush: 'sync'
20
- });
21
- watch(()=>toValue(newTitle), (value)=>{
22
- title.value = value;
23
- });
24
- if (restoreOnUnmount) onScopeDispose(()=>{
25
- setTitle(originalTitle);
26
- });
27
- return title;
28
- }
29
- export { useTitle };
1
+ import{onScopeDispose as e,ref as t,toValue as n,watch as r}from"vue";import{$dt as u,$t as o,dataHandler as l}from"../../shared/data-handler/index.js";function i(e){if(!e||"u"<typeof document)return;let t=document.title;return document.title=e,t}let a=u({restoreOnUnmount:o.boolean(!0)});function m(u="",o={}){let{restoreOnUnmount:d}=l(o,a,{unwrap:!0}),f=t(n(u)),c=i(f.value);return r(f,i,{flush:"sync"}),r(()=>n(u),e=>{f.value=e}),d&&e(()=>{i(c)}),f}export{m as useTitle};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmtlyt/lingshu-toolkit",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "main": "./dist/shared.js",
6
6
  "module": "./dist/shared.js",
@@ -40,35 +40,35 @@
40
40
  "email": "cmtlyt@163.com"
41
41
  },
42
42
  "devDependencies": {
43
- "@biomejs/biome": "2.3.8",
44
- "@cmtlyt/unplugin-shadcn-registry-generate": "^0.1.5",
45
- "@commitlint/cli": "^20.3.1",
46
- "@commitlint/config-conventional": "^20.3.1",
47
- "@rslib/core": "^0.19.3",
43
+ "@biomejs/biome": "2.4.11",
44
+ "@cmtlyt/unplugin-shadcn-registry-generate": "^0.1.6",
45
+ "@commitlint/cli": "^20.5.0",
46
+ "@commitlint/config-conventional": "^20.5.0",
47
+ "@rslib/core": "^0.21.0",
48
48
  "@rspress/core": "^2.0.8",
49
- "@types/node": "^24.10.9",
50
- "@types/react": "^19.2.9",
51
- "@vitejs/plugin-react": "^5.1.2",
52
- "@vitejs/plugin-vue": "^6.0.3",
53
- "@vitest/browser-playwright": "4.0.18",
54
- "@vitest/coverage-v8": "4.0.18",
55
- "@vitest/ui": "4.0.18",
49
+ "@types/node": "^25.5.2",
50
+ "@types/react": "^19.2.14",
51
+ "@vitejs/plugin-react": "^5.2.0",
52
+ "@vitejs/plugin-vue": "^6.0.5",
53
+ "@vitest/browser-playwright": "4.1.4",
54
+ "@vitest/coverage-v8": "4.1.4",
55
+ "@vitest/ui": "4.1.4",
56
56
  "changelogithub": "^14.0.0",
57
57
  "cross-env": "^10.1.0",
58
+ "depcheck": "^1.4.7",
58
59
  "esno": "^4.8.0",
59
60
  "husky": "^9.1.7",
60
- "jsdom": "^27.4.0",
61
- "lint-staged": "^16.2.7",
62
- "msw": "^2.12.14",
63
- "playwright": "^1.58.1",
64
- "react": "^19.2.4",
65
- "react-dom": "^19.2.4",
66
- "typescript": "^5.9.3",
67
- "vite-tsconfig-paths": "^6.0.4",
68
- "vitest": "4.0.18",
69
- "vitest-browser-react": "2.0.2",
70
- "vitest-browser-vue": "2.0.2",
71
- "vue": "^3.5.27"
61
+ "lint-staged": "^16.4.0",
62
+ "msw": "^2.13.2",
63
+ "playwright": "^1.59.1",
64
+ "react": "^19.2.5",
65
+ "react-dom": "^19.2.5",
66
+ "typescript": "^6.0.2",
67
+ "vite-tsconfig-paths": "^6.1.1",
68
+ "vitest": "4.1.4",
69
+ "vitest-browser-react": "2.2.0",
70
+ "vitest-browser-vue": "2.1.0",
71
+ "vue": "^3.5.32"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react": "^19.2.3",
@@ -121,8 +121,8 @@
121
121
  "preview:docs": "rspress preview",
122
122
  "format": "biome format --write",
123
123
  "test": "vitest --config=vitest.project.config.ts --coverage.enabled --ui",
124
- "test:ci": "cross-env skip_type_check=true gen_file_disabled=true vitest run --config=vitest.project.config.ts",
125
- "test:lib:ci": "cross-env skip_type_check=true gen_file_disabled=true vitest run",
124
+ "test:ci": "cross-env ci_test=true gen_file_disabled=true vitest run --config=vitest.project.config.ts",
125
+ "test:lib:ci": "cross-env ci_test=true gen_file_disabled=true vitest run",
126
126
  "test:lib": "vitest --coverage.enabled --ui",
127
127
  "script:gen-file": "esno scripts/gen-file.ts"
128
128
  }
package/dist/247.js DELETED
@@ -1,66 +0,0 @@
1
- import { dataHandler, logger, $dt, throwError, $t } from "./707.js";
2
- const validInfo = $dt({
3
- storageKey: 'validString',
4
- storageType: $t["enum"]([
5
- 'local',
6
- 'session',
7
- 'memory'
8
- ], 'local'),
9
- autoSaveInterval: $t.number(0)
10
- });
11
- const memoryStorage = {
12
- data: {},
13
- getItem (key) {
14
- return this.data[key];
15
- },
16
- setItem (key, value) {
17
- this.data[key] = value;
18
- },
19
- removeItem (key) {
20
- delete this.data[key];
21
- }
22
- };
23
- function getStorage(storageType) {
24
- try {
25
- if ('memory' === storageType) return memoryStorage;
26
- return 'local' === storageType ? localStorage : sessionStorage;
27
- } catch {
28
- logger.warn('createStorage', 'Failed to access localStorage or sessionStorage, using memoryStorage instead.');
29
- return memoryStorage;
30
- }
31
- }
32
- const CLEAR_FLAG = Symbol('cleared');
33
- function createStorageHandler(storageKey, initialData, options = {}) {
34
- const { storageKey: validStorageKey, storageType, autoSaveInterval } = dataHandler({
35
- storageKey,
36
- ...options
37
- }, validInfo, {
38
- unwrap: true
39
- });
40
- const storage = getStorage(storageType);
41
- const storageData = storage.getItem(validStorageKey);
42
- const context = {
43
- data: storageData ? JSON.parse(storageData) : initialData || {}
44
- };
45
- return {
46
- get (key) {
47
- if (context.data === CLEAR_FLAG) throwError('createStorageHandler', 'Storage has been cleared.');
48
- if (null == key) return context.data;
49
- return context.data[key];
50
- },
51
- set (value, key) {
52
- if (context.data === CLEAR_FLAG) throwError('createStorageHandler', 'Storage has been cleared.');
53
- if (null == key) context.data = value;
54
- else context.data[key] = value;
55
- if (autoSaveInterval > 0) setTimeout(()=>{
56
- storage.setItem(validStorageKey, JSON.stringify(context.data));
57
- }, autoSaveInterval);
58
- else storage.setItem(validStorageKey, JSON.stringify(context.data));
59
- },
60
- clear () {
61
- context.data = CLEAR_FLAG;
62
- storage.removeItem(validStorageKey);
63
- }
64
- };
65
- }
66
- export { createStorageHandler };
package/dist/707.js DELETED
@@ -1,142 +0,0 @@
1
- function createError(fnName, message, ErrorClass = Error) {
2
- return new ErrorClass(`[@cmtlyt/lingshu-toolkit#${fnName}]: ${message}`);
3
- }
4
- function throwError(fnName, message, ErrorClass = Error) {
5
- throw createError(fnName, message, ErrorClass);
6
- }
7
- function throwType(fnName, message) {
8
- throwError(fnName, message, TypeError);
9
- }
10
- const logger = new Proxy(console, {
11
- get (target, prop, receiver) {
12
- if ((globalThis.$$lingshu$$ || {}).disableLogger) return ()=>void 0;
13
- const oldLog = Reflect.get(target, prop, receiver).bind(console);
14
- return (fnName, ...args)=>{
15
- oldLog(`[@cmtlyt/lingshu-toolkit#${fnName}]:`, ...args);
16
- };
17
- }
18
- });
19
- const noop = ()=>void 0;
20
- const identity = (_v)=>_v;
21
- function getType(_v) {
22
- return Object.prototype.toString.call(_v).slice(8, -1).toLowerCase();
23
- }
24
- function typeHandler(type, verifyFn) {
25
- return (fullback)=>(_v, actions)=>{
26
- if (verifyFn ? verifyFn(_v) : getType(_v) === type) return true;
27
- if (null == fullback) return false;
28
- let fullbackValue = fullback;
29
- if ('function' == typeof fullback) fullbackValue = fullback(_v);
30
- actions.transform(fullbackValue);
31
- };
32
- }
33
- const $t = {
34
- notNullable: typeHandler('notNullable', (_v)=>null != _v),
35
- string: typeHandler('string'),
36
- validString: typeHandler('validString', (_v)=>'string' == typeof _v && _v.length > 0),
37
- number: typeHandler('number'),
38
- validNumber: typeHandler('validNumber', (_v)=>'number' == typeof _v && !Number.isNaN(_v)),
39
- boolean: typeHandler('boolean'),
40
- object: typeHandler('object'),
41
- array: typeHandler('array'),
42
- function: typeHandler('function'),
43
- symbol: typeHandler('symbol'),
44
- enum: (list, fullback)=>{
45
- if (!Array.isArray(list)) throwType('$t.enum', 'list must be an array');
46
- const set = new Set(list);
47
- return typeHandler('enum', (_v)=>set.has(_v))(fullback);
48
- }
49
- };
50
- function defineTransform(dataInfo) {
51
- const verifyInfo = {};
52
- const keys = Reflect.ownKeys(dataInfo);
53
- for(let i = 0, key = keys[i], item = dataInfo[key]; i < keys.length; key = keys[++i], item = dataInfo[key]){
54
- if ('function' == typeof item) {
55
- verifyInfo[key] = item;
56
- continue;
57
- }
58
- const handler = $t[item];
59
- if (!handler) {
60
- logger.warn('defineTransform', `${item} is not a valid type`);
61
- continue;
62
- }
63
- verifyInfo[key] = handler();
64
- }
65
- return verifyInfo;
66
- }
67
- const $dt = defineTransform;
68
- function createActions() {
69
- const ctx = {
70
- errors: [],
71
- transforms: [],
72
- handledErrorKeys: new Set()
73
- };
74
- const handler = {
75
- addError (key, msg = `${String(key)} is not valid`) {
76
- if (ctx.handledErrorKeys.has(key)) return;
77
- ctx.handledErrorKeys.add(key);
78
- ctx.errors.push(msg);
79
- },
80
- addTransform (key, value) {
81
- ctx.transforms.push([
82
- key,
83
- value
84
- ]);
85
- }
86
- };
87
- return [
88
- ctx,
89
- handler,
90
- (key)=>({
91
- assert: (flag, msg = `${String(key)} is not valid`)=>{
92
- if (!flag) handler.addError(key, msg);
93
- return flag;
94
- },
95
- transform: (value)=>{
96
- if (!ctx.handledErrorKeys.has(key)) handler.addTransform(key, value);
97
- return value;
98
- }
99
- })
100
- ];
101
- }
102
- function transformApply(data, transforms) {
103
- if (!transforms.length) return;
104
- for(let i = 0, [key, value] = transforms[i]; i < transforms.length; [key, value] = transforms[++i] || [])data[key] = value;
105
- }
106
- function handleProcess(data, keys, handleFn, getActions, actionHandlers) {
107
- for(let i = 0, key = keys[i]; i < keys.length; key = keys[++i]){
108
- const flag = handleFn(data[key], key, getActions(key), data);
109
- if (false === flag) actionHandlers.addError(key);
110
- }
111
- }
112
- function errorProcess(errors, errorHandler, strict) {
113
- if (!errors.length) return;
114
- if (errorHandler) errorHandler(errors);
115
- else if (strict) throwType('dataHandler', errors.join('\n'));
116
- }
117
- function filterData(data, ctx, defaultValue = {}) {
118
- ctx.handledErrorKeys.forEach((key)=>{
119
- data[key] = defaultValue[key];
120
- });
121
- }
122
- function dataHandler(data, handler, options) {
123
- if (!handler) throwType('dataHandler', 'handler is required');
124
- const { strict = false, errorHandler, defaultValue, unwrap = false } = options || {};
125
- const handlerIsFunction = 'function' == typeof handler;
126
- const handleFn = handlerIsFunction ? handler : (value, key, ...args)=>handler[key](value, ...args);
127
- const tempData = {
128
- ...defaultValue,
129
- ...data
130
- };
131
- const keys = handlerIsFunction ? Reflect.ownKeys(data) : Reflect.ownKeys(handler);
132
- const [ctx, actionHandler, getActions] = createActions();
133
- handleProcess(tempData, keys, handleFn, getActions, actionHandler);
134
- errorProcess(ctx.errors, errorHandler, strict);
135
- transformApply(tempData, ctx.transforms);
136
- filterData(tempData, ctx, defaultValue);
137
- return unwrap ? tempData : {
138
- result: tempData,
139
- errors: ctx.errors
140
- };
141
- }
142
- export { $dt, $t, createError, dataHandler, defineTransform, getType, identity, logger, noop, throwError, throwType };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};