@cmtlyt/lingshu-toolkit 0.4.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 (132) 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.d.ts +26 -0
  36. package/dist/shared/api-controller/create-api.js +1 -0
  37. package/dist/shared/api-controller/index.d.ts +3 -0
  38. package/dist/shared/api-controller/index.js +1 -0
  39. package/dist/shared/api-controller/request.d.ts +7 -0
  40. package/dist/shared/api-controller/request.js +1 -0
  41. package/dist/shared/api-controller/types.d.ts +140 -0
  42. package/dist/shared/api-controller/types.js +0 -0
  43. package/dist/shared/api-controller/utils.d.ts +13 -0
  44. package/dist/shared/api-controller/utils.js +1 -0
  45. package/dist/shared/condition-merge/index.d.ts +6 -6
  46. package/dist/shared/condition-merge/index.js +1 -30
  47. package/dist/shared/create-storage-handler/index.d.ts +4 -3
  48. package/dist/shared/create-storage-handler/index.js +1 -68
  49. package/dist/shared/data-handler/index.d.ts +4 -3
  50. package/dist/shared/data-handler/index.js +1 -77
  51. package/dist/shared/data-handler/tools.d.ts +6 -23
  52. package/dist/shared/data-handler/tools.js +1 -48
  53. package/dist/shared/data-handler/types.d.ts +20 -2
  54. package/dist/shared/data-mixed-manager/constants.js +1 -9
  55. package/dist/shared/data-mixed-manager/index.js +1 -226
  56. package/dist/shared/data-mixed-manager/types.d.ts +1 -2
  57. package/dist/shared/index.d.ts +3 -0
  58. package/dist/shared/index.js +1 -2
  59. package/dist/shared/logger/index.d.ts +5 -0
  60. package/dist/shared/logger/index.js +1 -9
  61. package/dist/shared/priority-queue/index.d.ts +45 -0
  62. package/dist/shared/priority-queue/index.js +1 -0
  63. package/dist/shared/priority-queue/types.d.ts +10 -0
  64. package/dist/shared/priority-queue/types.js +0 -0
  65. package/dist/shared/priority-queue/utils.d.ts +7 -0
  66. package/dist/shared/priority-queue/utils.js +1 -0
  67. package/dist/shared/throw-error/index.d.ts +4 -3
  68. package/dist/shared/throw-error/index.js +1 -10
  69. package/dist/shared/try-call/index.d.ts +22 -0
  70. package/dist/shared/try-call/index.js +1 -0
  71. package/dist/shared/types/base.d.ts +2 -0
  72. package/dist/shared/types/index.js +1 -2
  73. package/dist/shared/types/pack.d.ts +3 -3
  74. package/dist/shared/types/pack.js +1 -1
  75. package/dist/shared/utils/base.d.ts +1 -1
  76. package/dist/shared/utils/base.js +1 -6
  77. package/dist/shared/utils/index.js +1 -2
  78. package/dist/shared/utils/verify.d.ts +1 -1
  79. package/dist/shared/utils/verify.js +1 -67
  80. package/dist/shared/with-resolvers/index.d.ts +5 -3
  81. package/dist/shared/with-resolvers/index.js +1 -15
  82. package/dist/vue/index.js +1 -29
  83. package/dist/vue/use-title/index.d.ts +2 -2
  84. package/dist/vue/use-title/index.js +1 -29
  85. package/package.json +29 -26
  86. package/dist/607.js +0 -737
  87. package/dist/707.js +0 -141
  88. package/dist/react/use-boolean/index.test.d.ts +0 -1
  89. package/dist/react/use-controllable-value/index.test.d.ts +0 -1
  90. package/dist/react/use-counter/index.test.d.ts +0 -1
  91. package/dist/react/use-force-update/index.test.d.ts +0 -1
  92. package/dist/react/use-mount/index.test.d.ts +0 -1
  93. package/dist/react/use-ref-state/index.test.d.ts +0 -1
  94. package/dist/react/use-storage/index.test.d.ts +0 -1
  95. package/dist/react/use-title/index.test.d.ts +0 -1
  96. package/dist/react/use-toggle/index.test.d.ts +0 -1
  97. package/dist/react/use-valid-data/index.test.d.ts +0 -1
  98. package/dist/shared/allx/__test__/allsettled.test.d.ts +0 -1
  99. package/dist/shared/allx/__test__/basic.test.d.ts +0 -1
  100. package/dist/shared/allx/__test__/circular-dependency.test.d.ts +0 -1
  101. package/dist/shared/allx/__test__/dependency.test.d.ts +0 -1
  102. package/dist/shared/allx/__test__/edge-cases.test.d.ts +0 -1
  103. package/dist/shared/allx/__test__/error-handling.test.d.ts +0 -1
  104. package/dist/shared/allx/__test__/execution-order.test.d.ts +0 -1
  105. package/dist/shared/allx/__test__/falsy-values.test.d.ts +0 -1
  106. package/dist/shared/allx/__test__/performance.test.d.ts +0 -1
  107. package/dist/shared/allx/__test__/type-checking.test.d.ts +0 -1
  108. package/dist/shared/allx/__test__/use-cases.test.d.ts +0 -1
  109. package/dist/shared/animation/__test__/animation-pause-resume.test.d.ts +0 -1
  110. package/dist/shared/animation/__test__/animation.test.d.ts +0 -1
  111. package/dist/shared/animation/__test__/step-animation.test.d.ts +0 -1
  112. package/dist/shared/animation/__test__/utils.test.d.ts +0 -1
  113. package/dist/shared/condition-merge/index.test-d.js +0 -108
  114. package/dist/shared/condition-merge/index.test.d.ts +0 -1
  115. package/dist/shared/create-storage-handler/index.browser.test.d.ts +0 -1
  116. package/dist/shared/create-storage-handler/index.test.d.ts +0 -1
  117. package/dist/shared/data-handler/index.test.d.ts +0 -1
  118. package/dist/shared/data-mixed-manager/__test__/basic.test.d.ts +0 -1
  119. package/dist/shared/data-mixed-manager/__test__/build-options.test.d.ts +0 -1
  120. package/dist/shared/data-mixed-manager/__test__/constructor-options.test.d.ts +0 -1
  121. package/dist/shared/data-mixed-manager/__test__/data-management.test.d.ts +0 -1
  122. package/dist/shared/data-mixed-manager/__test__/edge-cases.test.d.ts +0 -1
  123. package/dist/shared/data-mixed-manager/__test__/events.browser.test.d.ts +0 -1
  124. package/dist/shared/data-mixed-manager/__test__/events.test.d.ts +0 -1
  125. package/dist/shared/data-mixed-manager/__test__/fixed-slots.test.d.ts +0 -1
  126. package/dist/shared/data-mixed-manager/__test__/insert-mode.test.d.ts +0 -1
  127. package/dist/shared/throw-error/index.test.d.ts +0 -1
  128. package/dist/shared/utils/__test__/base.test.d.ts +0 -1
  129. package/dist/shared/utils/__test__/verify.test.d.ts +0 -1
  130. package/dist/shared/with-resolvers/index.test.d.ts +0 -1
  131. package/dist/test/utils.d.ts +0 -13
  132. package/dist/vue/use-title/index.test.d.ts +0 -1
package/dist/707.js DELETED
@@ -1,141 +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
- const oldLog = Reflect.get(target, prop, receiver).bind(console);
13
- return (fnName, ...args)=>{
14
- oldLog(`[@cmtlyt/lingshu-toolkit#${fnName}]:`, ...args);
15
- };
16
- }
17
- });
18
- const noop = ()=>void 0;
19
- const identity = (_v)=>_v;
20
- function getType(_v) {
21
- return Object.prototype.toString.call(_v).slice(8, -1).toLowerCase();
22
- }
23
- function typeHandler(type, verifyFn) {
24
- return (fullback)=>(_v, actions)=>{
25
- if (verifyFn ? verifyFn(_v) : getType(_v) === type) return true;
26
- if (null == fullback) return false;
27
- let fullbackValue = fullback;
28
- if ('function' == typeof fullback) fullbackValue = fullback(_v);
29
- actions.transform(fullbackValue);
30
- };
31
- }
32
- const $t = {
33
- notNullable: typeHandler('notNullable', (_v)=>null != _v),
34
- string: typeHandler('string'),
35
- validString: typeHandler('validString', (_v)=>'string' == typeof _v && _v.length > 0),
36
- number: typeHandler('number'),
37
- validNumber: typeHandler('validNumber', (_v)=>'number' == typeof _v && !Number.isNaN(_v)),
38
- boolean: typeHandler('boolean'),
39
- object: typeHandler('object'),
40
- array: typeHandler('array'),
41
- function: typeHandler('function'),
42
- symbol: typeHandler('symbol'),
43
- enum: (list, fullback)=>{
44
- if (!Array.isArray(list)) throwType('$t.enum', 'list must be an array');
45
- const set = new Set(list);
46
- return typeHandler('enum', (_v)=>set.has(_v))(fullback);
47
- }
48
- };
49
- function defineTransform(dataInfo) {
50
- const verifyInfo = {};
51
- const keys = Reflect.ownKeys(dataInfo);
52
- for(let i = 0, key = keys[i], item = dataInfo[key]; i < keys.length; key = keys[++i], item = dataInfo[key]){
53
- if ('function' == typeof item) {
54
- verifyInfo[key] = item;
55
- continue;
56
- }
57
- const handler = $t[item];
58
- if (!handler) {
59
- logger.warn('defineTransform', `${item} is not a valid type`);
60
- continue;
61
- }
62
- verifyInfo[key] = handler();
63
- }
64
- return verifyInfo;
65
- }
66
- const $dt = defineTransform;
67
- function createActions() {
68
- const ctx = {
69
- errors: [],
70
- transforms: [],
71
- handledErrorKeys: new Set()
72
- };
73
- const handler = {
74
- addError (key, msg = `${String(key)} is not valid`) {
75
- if (ctx.handledErrorKeys.has(key)) return;
76
- ctx.handledErrorKeys.add(key);
77
- ctx.errors.push(msg);
78
- },
79
- addTransform (key, value) {
80
- ctx.transforms.push([
81
- key,
82
- value
83
- ]);
84
- }
85
- };
86
- return [
87
- ctx,
88
- handler,
89
- (key)=>({
90
- assert: (flag, msg = `${String(key)} is not valid`)=>{
91
- if (!flag) handler.addError(key, msg);
92
- return flag;
93
- },
94
- transform: (value)=>{
95
- if (!ctx.handledErrorKeys.has(key)) handler.addTransform(key, value);
96
- return value;
97
- }
98
- })
99
- ];
100
- }
101
- function transformApply(data, transforms) {
102
- if (!transforms.length) return;
103
- for(let i = 0, [key, value] = transforms[i]; i < transforms.length; [key, value] = transforms[++i] || [])data[key] = value;
104
- }
105
- function handleProcess(data, keys, handleFn, getActions, actionHandlers) {
106
- for(let i = 0, key = keys[i]; i < keys.length; key = keys[++i]){
107
- const flag = handleFn(data[key], key, getActions(key), data);
108
- if (false === flag) actionHandlers.addError(key);
109
- }
110
- }
111
- function errorProcess(errors, errorHandler, strict) {
112
- if (!errors.length) return;
113
- if (errorHandler) errorHandler(errors);
114
- else if (strict) throwType('dataHandler', errors.join('\n'));
115
- }
116
- function filterData(data, ctx, defaultValue = {}) {
117
- ctx.handledErrorKeys.forEach((key)=>{
118
- data[key] = defaultValue[key];
119
- });
120
- }
121
- function dataHandler(data, handler, options) {
122
- if (!handler) throwType('dataHandler', 'handler is required');
123
- const { strict = false, errorHandler, defaultValue, unwrap = false } = options || {};
124
- const handlerIsFunction = 'function' == typeof handler;
125
- const handleFn = handlerIsFunction ? handler : (value, key, ...args)=>handler[key](value, ...args);
126
- const tempData = {
127
- ...defaultValue,
128
- ...data
129
- };
130
- const keys = handlerIsFunction ? Reflect.ownKeys(data) : Reflect.ownKeys(handler);
131
- const [ctx, actionHandler, getActions] = createActions();
132
- handleProcess(tempData, keys, handleFn, getActions, actionHandler);
133
- errorProcess(ctx.errors, errorHandler, strict);
134
- transformApply(tempData, ctx.transforms);
135
- filterData(tempData, ctx, defaultValue);
136
- return unwrap ? tempData : {
137
- result: tempData,
138
- errors: ctx.errors
139
- };
140
- }
141
- 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,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 {};