@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
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 {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,108 +0,0 @@
1
- import { describe, expectTypeOf, test } from "vitest";
2
- import { conditionMerge } from "./index.js";
3
- describe('conditionMerge 类型测试', ()=>{
4
- test(': 混合布尔类型', ()=>{
5
- const t1 = conditionMerge([
6
- {
7
- condition: true,
8
- value: {
9
- num: 1
10
- }
11
- },
12
- {
13
- condition: Math.random() > 0.5,
14
- value: {
15
- num: 3,
16
- str: '3'
17
- },
18
- fullback: {
19
- str: '4'
20
- }
21
- }
22
- ]);
23
- expectTypeOf(t1).pick().toEqualTypeOf();
24
- expectTypeOf(t1).pick().toEqualTypeOf();
25
- expectTypeOf(conditionMerge({
26
- condition: true,
27
- value: {
28
- num: 1
29
- }
30
- }, {
31
- condition: Math.random() > 0.5,
32
- value: {
33
- num: 3,
34
- str: '3'
35
- },
36
- fullback: {
37
- str: '4'
38
- }
39
- })).toEqualTypeOf(t1);
40
- const t3 = conditionMerge([
41
- {
42
- condition: true,
43
- value: {
44
- num: 1
45
- }
46
- },
47
- {
48
- condition: false,
49
- value: {
50
- num: 1
51
- },
52
- fullback: {
53
- bool: true
54
- }
55
- },
56
- {
57
- condition: Math.random() > 0.5,
58
- value: {
59
- num: 3,
60
- str: '3'
61
- },
62
- fullback: {
63
- str: '4'
64
- }
65
- }
66
- ]);
67
- expectTypeOf(t3).pick().toEqualTypeOf();
68
- expectTypeOf(t3).pick().toEqualTypeOf();
69
- expectTypeOf(t3).pick().toEqualTypeOf();
70
- });
71
- test('类型测试: 纯 boolean 类型测试', ()=>{
72
- const t1 = conditionMerge([
73
- {
74
- condition: Math.random() > 0.1,
75
- value: {
76
- num: 1
77
- }
78
- },
79
- {
80
- condition: Math.random() > 0.5,
81
- value: {
82
- num: 3,
83
- str: '3'
84
- },
85
- fullback: {
86
- str: '4'
87
- }
88
- }
89
- ]);
90
- expectTypeOf(t1).pick().toEqualTypeOf();
91
- expectTypeOf(t1).pick().toEqualTypeOf();
92
- expectTypeOf(conditionMerge({
93
- condition: Math.random() > 0.1,
94
- value: {
95
- num: 1
96
- }
97
- }, {
98
- condition: Math.random() > 0.5,
99
- value: {
100
- num: 3,
101
- str: '3'
102
- },
103
- fullback: {
104
- str: '4'
105
- }
106
- })).toEqualTypeOf(t1);
107
- });
108
- });
@@ -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,13 +0,0 @@
1
- import { Component, type PropsWithChildren } from 'react';
2
- export declare class ErrorBoundary extends Component<PropsWithChildren<{
3
- onError: () => void;
4
- }>> {
5
- state: {
6
- hasError: boolean;
7
- };
8
- static getDerivedStateFromError(): {
9
- hasError: boolean;
10
- };
11
- componentDidCatch(): void;
12
- render(): import("react").ReactNode;
13
- }
@@ -1 +0,0 @@
1
- export {};