@cmtlyt/lingshu-toolkit 0.5.0 → 0.6.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 (130) 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 +1 -0
  54. package/dist/shared/index.js +1 -957
  55. package/dist/shared/logger/index.d.ts +2 -2
  56. package/dist/shared/logger/index.js +1 -10
  57. package/dist/shared/priority-queue/index.d.ts +45 -0
  58. package/dist/shared/priority-queue/index.js +1 -0
  59. package/dist/shared/priority-queue/types.d.ts +10 -0
  60. package/dist/shared/priority-queue/types.js +0 -0
  61. package/dist/shared/priority-queue/utils.d.ts +7 -0
  62. package/dist/shared/priority-queue/utils.js +1 -0
  63. package/dist/shared/throw-error/index.d.ts +4 -3
  64. package/dist/shared/throw-error/index.js +1 -10
  65. package/dist/shared/try-call/index.d.ts +3 -3
  66. package/dist/shared/try-call/index.js +1 -59
  67. package/dist/shared/types/index.js +1 -2
  68. package/dist/shared/types/pack.d.ts +2 -2
  69. package/dist/shared/types/pack.js +1 -1
  70. package/dist/shared/utils/base.d.ts +1 -1
  71. package/dist/shared/utils/base.js +1 -6
  72. package/dist/shared/utils/index.js +1 -2
  73. package/dist/shared/utils/verify.d.ts +1 -1
  74. package/dist/shared/utils/verify.js +1 -67
  75. package/dist/shared/with-resolvers/index.d.ts +5 -3
  76. package/dist/shared/with-resolvers/index.js +1 -15
  77. package/dist/vue/index.js +1 -29
  78. package/dist/vue/use-title/index.d.ts +2 -2
  79. package/dist/vue/use-title/index.js +1 -29
  80. package/package.json +26 -26
  81. package/dist/247.js +0 -66
  82. package/dist/707.js +0 -142
  83. package/dist/react/use-boolean/index.test.d.ts +0 -1
  84. package/dist/react/use-controllable-value/index.test.d.ts +0 -1
  85. package/dist/react/use-counter/index.test.d.ts +0 -1
  86. package/dist/react/use-force-update/index.test.d.ts +0 -1
  87. package/dist/react/use-mount/index.test.d.ts +0 -1
  88. package/dist/react/use-ref-state/index.test.d.ts +0 -1
  89. package/dist/react/use-storage/index.test.d.ts +0 -1
  90. package/dist/react/use-title/index.test.d.ts +0 -1
  91. package/dist/react/use-toggle/index.test.d.ts +0 -1
  92. package/dist/react/use-valid-data/index.test.d.ts +0 -1
  93. package/dist/shared/allx/__test__/allsettled.test.d.ts +0 -1
  94. package/dist/shared/allx/__test__/basic.test.d.ts +0 -1
  95. package/dist/shared/allx/__test__/circular-dependency.test.d.ts +0 -1
  96. package/dist/shared/allx/__test__/dependency.test.d.ts +0 -1
  97. package/dist/shared/allx/__test__/edge-cases.test.d.ts +0 -1
  98. package/dist/shared/allx/__test__/error-handling.test.d.ts +0 -1
  99. package/dist/shared/allx/__test__/execution-order.test.d.ts +0 -1
  100. package/dist/shared/allx/__test__/falsy-values.test.d.ts +0 -1
  101. package/dist/shared/allx/__test__/performance.test.d.ts +0 -1
  102. package/dist/shared/allx/__test__/type-checking.test.d.ts +0 -1
  103. package/dist/shared/allx/__test__/use-cases.test.d.ts +0 -1
  104. package/dist/shared/animation/__test__/animation-pause-resume.test.d.ts +0 -1
  105. package/dist/shared/animation/__test__/animation.test.d.ts +0 -1
  106. package/dist/shared/animation/__test__/step-animation.test.d.ts +0 -1
  107. package/dist/shared/animation/__test__/utils.test.d.ts +0 -1
  108. package/dist/shared/api-controller/__test__/index.browser.test.d.ts +0 -1
  109. package/dist/shared/api-controller/__test__/index.node.test.d.ts +0 -1
  110. package/dist/shared/condition-merge/index.test-d.js +0 -108
  111. package/dist/shared/condition-merge/index.test.d.ts +0 -1
  112. package/dist/shared/create-storage-handler/index.browser.test.d.ts +0 -1
  113. package/dist/shared/create-storage-handler/index.test.d.ts +0 -1
  114. package/dist/shared/data-handler/index.test.d.ts +0 -1
  115. package/dist/shared/data-mixed-manager/__test__/basic.test.d.ts +0 -1
  116. package/dist/shared/data-mixed-manager/__test__/build-options.test.d.ts +0 -1
  117. package/dist/shared/data-mixed-manager/__test__/constructor-options.test.d.ts +0 -1
  118. package/dist/shared/data-mixed-manager/__test__/data-management.test.d.ts +0 -1
  119. package/dist/shared/data-mixed-manager/__test__/edge-cases.test.d.ts +0 -1
  120. package/dist/shared/data-mixed-manager/__test__/events.browser.test.d.ts +0 -1
  121. package/dist/shared/data-mixed-manager/__test__/events.test.d.ts +0 -1
  122. package/dist/shared/data-mixed-manager/__test__/fixed-slots.test.d.ts +0 -1
  123. package/dist/shared/data-mixed-manager/__test__/insert-mode.test.d.ts +0 -1
  124. package/dist/shared/throw-error/index.test.d.ts +0 -1
  125. package/dist/shared/try-call/index.test.d.ts +0 -1
  126. package/dist/shared/utils/__test__/base.test.d.ts +0 -1
  127. package/dist/shared/utils/__test__/verify.test.d.ts +0 -1
  128. package/dist/shared/with-resolvers/index.test.d.ts +0 -1
  129. package/dist/test/utils.d.ts +0 -13
  130. package/dist/vue/use-title/index.test.d.ts +0 -1
@@ -2,9 +2,9 @@ type Logger = {
2
2
  [K in keyof Omit<Console, 'table'> as Console[K] extends (...args: any[]) => any ? K : never]: Console[K] extends (...args: [any, ...infer AS]) => infer R ? (fnName: string, ...args: AS) => R : never;
3
3
  };
4
4
  declare global {
5
- var $$lingshu$$: {
5
+ var $$lingshu$$: Partial<{
6
6
  disableLogger: boolean;
7
- };
7
+ }>;
8
8
  }
9
9
  export declare const logger: Logger;
10
10
  export {};
@@ -1,10 +1 @@
1
- const logger = new Proxy(console, {
2
- get (target, prop, receiver) {
3
- if ((globalThis.$$lingshu$$ || {}).disableLogger) return ()=>void 0;
4
- const oldLog = Reflect.get(target, prop, receiver).bind(console);
5
- return (fnName, ...args)=>{
6
- oldLog(`[@cmtlyt/lingshu-toolkit#${fnName}]:`, ...args);
7
- };
8
- }
9
- });
10
- export { logger };
1
+ let e=new Proxy(console,{get(e,l,o){if((globalThis.$$lingshu$$||{}).disableLogger)return()=>void 0;let t=Reflect.get(e,l,o).bind(console);return(e,...l)=>{t(`[@cmtlyt/lingshu-toolkit#${e}]:`,...l)}}});export{e as logger};
@@ -0,0 +1,45 @@
1
+ import type { PriorityQueueOptions } from './types';
2
+ declare class PriorityQueue<T> {
3
+ private readonly heap;
4
+ private readonly itemSet;
5
+ private readonly compare;
6
+ private readonly allowDuplicate;
7
+ private insertCounter;
8
+ constructor(options?: PriorityQueueOptions<T>);
9
+ private swapItems;
10
+ private heapifyUp;
11
+ private heapifyDown;
12
+ private isDuplicate;
13
+ enqueue(item: T): boolean;
14
+ enqueueMany(items: T[]): boolean[];
15
+ dequeue(): T | undefined;
16
+ peek(): T | undefined;
17
+ size(): number;
18
+ isEmpty(): boolean;
19
+ clear(): void;
20
+ /**
21
+ * 返回队列中所有元素的有序数组副本
22
+ *
23
+ * @description
24
+ * 该方法返回一个新数组,包含队列中的所有元素,按照以下顺序排列:
25
+ * 1. 优先级从小到大(根据 compare 函数)
26
+ * 2. 相同优先级的元素按照插入顺序(FIFO)
27
+ *
28
+ * 注意:返回的是数组副本,修改返回的数组不会影响原队列
29
+ *
30
+ * @returns 按优先级和插入顺序排序的元素数组
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const queue = priorityQueue<number>();
35
+ * queue.enqueue(3);
36
+ * queue.enqueue(1);
37
+ * queue.enqueue(2);
38
+ *
39
+ * console.log(queue.toArray()); // [1, 2, 3]
40
+ * ```
41
+ */
42
+ toArray(): T[];
43
+ }
44
+ declare function priorityQueue<T>(options?: PriorityQueueOptions<T>): PriorityQueue<T>;
45
+ export { priorityQueue };
@@ -0,0 +1 @@
1
+ import{$dt as e,$t as t,dataHandler as i}from"../data-handler/index.js";import{logger as h}from"../logger/index.js";import{tryCall as r}from"../try-call/index.js";import{defaultCompare as s,getLeftChildIndex as a,getParentIndex as p,getRightChildIndex as n,updateSmallestIndex as l}from"./utils.js";let o=e({compare:t.function(()=>s),allowDuplicate:t.boolean(!1)});class u{heap=[];itemSet=new Set;compare;allowDuplicate;insertCounter=0;constructor(e={}){let{compare:t,allowDuplicate:h}=i(e||{},o,{unwrap:!0});this.compare=t,this.allowDuplicate=h}swapItems(e,t){[this.heap[e],this.heap[t]]=[this.heap[t],this.heap[e]]}heapifyUp(e){let t=e;for(;t>0;){let e=p(t),i=this.heap[t],h=this.heap[e];if(0>this.compare(i.item,h.item))this.swapItems(t,e),t=e;else break}}heapifyDown(e){let t=e,i=this.heap.length;for(;t<i;){let e=a(t),h=n(t),r=t;if(r=l(e,r,i,this.heap,this.compare),(r=l(h,r,i,this.heap,this.compare))===t)break;this.swapItems(t,r),t=r}}isDuplicate(e){return!this.allowDuplicate&&this.itemSet.has(e)}enqueue(e){if(this.isDuplicate(e)){let t=r(()=>"object"==typeof e&&null!==e?JSON.stringify(e):String(e),()=>Object.prototype.toString.call(e));return h.warn("PriorityQueue.enqueue",`Duplicate item detected: ${t}`),!1}let t={item:e,insertOrder:this.insertCounter++};return this.allowDuplicate||this.itemSet.add(e),this.heap.push(t),this.heapifyUp(this.heap.length-1),!0}enqueueMany(e){return e.map(e=>this.enqueue(e))}dequeue(){let e;if(0!==this.heap.length)return 1===this.heap.length?e=this.heap.pop().item:(e=this.heap[0].item,this.heap[0]=this.heap.pop(),this.heapifyDown(0)),this.itemSet.delete(e),e}peek(){if(0!==this.heap.length)return this.heap[0].item}size(){return this.heap.length}isEmpty(){return 0===this.heap.length}clear(){this.heap.length=0,this.itemSet.clear(),this.insertCounter=0}toArray(){let e=[...this.heap];return e.sort((e,t)=>{let i=this.compare(e.item,t.item);return 0!==i?i:e.insertOrder-t.insertOrder}),e.map(e=>e.item)}}function m(e){return new u(e)}export{m as priorityQueue};
@@ -0,0 +1,10 @@
1
+ type CompareFn<T> = (first: T, second: T) => number;
2
+ interface PriorityQueueOptions<T> {
3
+ compare?: CompareFn<T>;
4
+ allowDuplicate?: boolean;
5
+ }
6
+ interface HeapItem<T> {
7
+ item: T;
8
+ insertOrder: number;
9
+ }
10
+ export type { CompareFn, HeapItem, PriorityQueueOptions };
File without changes
@@ -0,0 +1,7 @@
1
+ import type { CompareFn, HeapItem } from './types';
2
+ declare function defaultCompare<T>(left: T, right: T): number;
3
+ declare function getParentIndex(index: number): number;
4
+ declare function getLeftChildIndex(index: number): number;
5
+ declare function getRightChildIndex(index: number): number;
6
+ declare function updateSmallestIndex<T>(childIndex: number, smallestIndex: number, size: number, heap: HeapItem<T>[], compare: CompareFn<T>): number;
7
+ export { defaultCompare, getLeftChildIndex, getParentIndex, getRightChildIndex, updateSmallestIndex };
@@ -0,0 +1 @@
1
+ import{logger as e}from"../logger/index.js";import{getType as t}from"../utils/index.js";let r=new Set(["number","string","date"]);function n(n,i){return r.has(t(n))&&r.has(t(i))?n<i?-1:+(n>i):(e.warn("PriorityQueue",`Unsupported type: ${t(n)} ${t(i)}`),0)}function i(e){return Math.floor((e-1)/2)}function u(e){return 2*e+1}function o(e){return 2*e+2}function d(e,t,r,n,i){if(e>=r)return t;let u=i(n[e].item,n[t].item);return u<0||0===u&&n[e].insertOrder<n[t].insertOrder?e:t}export{n as defaultCompare,u as getLeftChildIndex,i as getParentIndex,o as getRightChildIndex,d as updateSmallestIndex};
@@ -1,3 +1,4 @@
1
- export declare function createError(fnName: string, message: string, ErrorClass?: ErrorConstructor): Error;
2
- export declare function throwError(fnName: string, message: string, ErrorClass?: ErrorConstructor): never;
3
- export declare function throwType(fnName: string, message: string): never;
1
+ declare function createError(fnName: string, message: string, ErrorClass?: ErrorConstructor): Error;
2
+ declare function throwError(fnName: string, message: string, ErrorClass?: ErrorConstructor): never;
3
+ declare function throwType(fnName: string, message: string): never;
4
+ export { createError, throwError, throwType };
@@ -1,10 +1 @@
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
- export { createError, throwError, throwType };
1
+ function r(o,t,n=Error){return new n(`[@cmtlyt/lingshu-toolkit#${o}]: ${t}`)}function o(t,n,e=Error){throw r(t,n,e)}function t(r,t){o(r,t,TypeError)}export{r as createError,o as throwError,t as throwType};
@@ -9,7 +9,7 @@ type TryCallFinalArgs<R, E> = TryCallResultValue<R, E> | Error;
9
9
  * @param cb 回调函数
10
10
  * @param onError 错误处理函数
11
11
  */
12
- export declare function tryCallFunc<A extends any[], R, E = never>(cb: (...args: A) => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): (...args: A) => TryCallResult<R, E>;
12
+ declare function tryCallFunc<A extends any[], R, E = never>(cb: (...args: A) => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): (...args: A) => TryCallResult<R, E>;
13
13
  /**
14
14
  * 尝试调用函数
15
15
  *
@@ -18,5 +18,5 @@ export declare function tryCallFunc<A extends any[], R, E = never>(cb: (...args:
18
18
  * @param cb 回调函数
19
19
  * @param onError 错误处理函数
20
20
  */
21
- export declare function tryCall<R, E = never>(this: any, cb: () => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): TryCallResult<R, E>;
22
- export {};
21
+ declare function tryCall<R, E = never>(this: any, cb: () => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): TryCallResult<R, E>;
22
+ export { tryCall, tryCallFunc };
@@ -1,59 +1 @@
1
- import { throwType } from "../throw-error/index.js";
2
- import { isFunction, isPromiseLike } from "../utils/verify.js";
3
- const EMPTY = Symbol('EMPTY');
4
- function tryCallFunc(cb, onError, onFinal) {
5
- if (!isFunction(cb)) throwType('tryCallFunc', 'callback is not a function');
6
- const catchFn = (self, ctx, error)=>{
7
- if (isFunction(onError)) try {
8
- ctx.errorResult = Reflect.apply(onError, self, [
9
- error
10
- ]);
11
- } catch (err) {
12
- ctx.error = err;
13
- }
14
- else ctx.error = error;
15
- return ctx.errorResult;
16
- };
17
- const finallyFn = (self, ctx, result)=>{
18
- try {
19
- if (ctx.error !== EMPTY) throw ctx.error;
20
- } finally{
21
- if (isFunction(onFinal)) if (ctx.errorResult !== EMPTY) Reflect.apply(onFinal, self, [
22
- ctx.errorResult
23
- ]);
24
- else if (ctx.error !== EMPTY) Reflect.apply(onFinal, self, [
25
- ctx.error
26
- ]);
27
- else Reflect.apply(onFinal, self, [
28
- result
29
- ]);
30
- }
31
- };
32
- return function(...args) {
33
- const ctx = {
34
- oriResult: EMPTY,
35
- errorResult: EMPTY,
36
- error: EMPTY
37
- };
38
- const asyncFn = async ()=>{
39
- try {
40
- ctx.oriResult = Reflect.apply(cb, this, args);
41
- return ctx.oriResult;
42
- } catch (error) {
43
- return catchFn(this, ctx, error);
44
- }
45
- };
46
- const fnPromise = asyncFn().catch((error)=>catchFn(this, ctx, error));
47
- if (isPromiseLike(ctx.oriResult)) return fnPromise.then((result)=>{
48
- finallyFn(this, ctx, result);
49
- return result;
50
- });
51
- finallyFn(this, ctx, ctx.oriResult);
52
- return ctx.oriResult !== EMPTY ? ctx.oriResult : ctx.errorResult;
53
- };
54
- }
55
- function tryCall(cb, onError, onFinal) {
56
- if (!isFunction(cb)) throwType('tryCall', 'callback is not a function');
57
- return tryCallFunc(cb, onError, onFinal).call(this);
58
- }
59
- export { tryCall, tryCallFunc };
1
+ import{throwType as r}from"../throw-error/index.js";import{isFunction as t,isPromiseLike as e}from"../utils/verify.js";let l=Symbol("EMPTY");function o(o,i,n){t(o)||r("tryCallFunc","callback is not a function");let u=(r,e,l)=>{if(t(i))try{e.errorResult=Reflect.apply(i,r,[l])}catch(r){e.error=r}else e.error=l;return e.errorResult},s=(r,e,o)=>{try{if(e.error!==l)throw e.error}finally{t(n)&&Reflect.apply(n,r,e.error===l?[o]:[e.error])}};return function(...r){let t={oriResult:l,errorResult:l,error:l},i=(async()=>{try{return t.oriResult=Reflect.apply(o,this,r),t.oriResult}catch(r){return u(this,t,r)}})().catch(r=>u(this,t,r));if(e(t.oriResult))return i.then(r=>(s(this,t,r),r));let n=t.oriResult===l?t.errorResult:t.oriResult;return s(this,t,n),n}}function i(e,l,i){return t(e)||r("tryCall","callback is not a function"),o(e,l,i).call(this)}export{i as tryCall,o as tryCallFunc};
@@ -1,2 +1 @@
1
- export * from "./base.js";
2
- export * from "./pack.js";
1
+ export*from"./base.js";export*from"./pack.js";
@@ -1,7 +1,7 @@
1
1
  declare const __PACK__: unique symbol;
2
- export type Pack<T> = {
2
+ export interface Pack<T> {
3
3
  [__PACK__]: T;
4
- };
4
+ }
5
5
  export type Unpack<T extends Pack<any>> = T extends Pack<infer U> ? U : never;
6
6
  export type SafeUnpack<T> = T extends Pack<infer U> ? U : T;
7
7
  export type IsPack<T> = Pack<any> extends T ? true : false;
@@ -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.6.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",
43
+ "@biomejs/biome": "2.4.11",
44
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",
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 };