devix 0.1.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/index.cjs +314 -0
- package/dist/index.d.cts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +300 -0
- package/package.json +31 -57
- package/dist/index.cjs.js +0 -309
- package/dist/index.esm.js +0 -295
- package/index.d.ts +0 -53
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 OpenKnights
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OpenKnights
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@ Then, utilize modern module bundling tools such as Vite or Webpack to import thi
|
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
// Using ES Module
|
|
17
|
-
import {
|
|
17
|
+
import { shallowClone } from 'devix'
|
|
18
18
|
|
|
19
19
|
// Using CommonJS
|
|
20
|
-
const {
|
|
20
|
+
const { deepClone } = require('devix')
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Usage
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/typeof.ts
|
|
3
|
+
function getDataType(target) {
|
|
4
|
+
const type = typeof target;
|
|
5
|
+
return type !== "object" ? type : Object.prototype.toString.call(target).slice(8, -1).toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
const typeCheckRules = {
|
|
8
|
+
undefined: (target) => typeof target === "undefined",
|
|
9
|
+
null: (target) => target === null,
|
|
10
|
+
number: (target) => typeof target === "number",
|
|
11
|
+
string: (target) => typeof target === "string",
|
|
12
|
+
boolean: (target) => typeof target === "boolean",
|
|
13
|
+
symbol: (target) => typeof target === "symbol",
|
|
14
|
+
bigint: (target) => typeof target === "bigint",
|
|
15
|
+
object: (target) => target !== null && typeof target === "object",
|
|
16
|
+
array: (target) => Array.isArray(target),
|
|
17
|
+
function: (target) => typeof target === "function",
|
|
18
|
+
date: (target) => target instanceof Date,
|
|
19
|
+
set: (target) => target instanceof Set,
|
|
20
|
+
map: (target) => target instanceof Map,
|
|
21
|
+
regexp: (target) => target instanceof RegExp,
|
|
22
|
+
promise: (target) => target instanceof Promise,
|
|
23
|
+
empty(target) {
|
|
24
|
+
return this.string(target) && target === "";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const isType = (type, target) => {
|
|
28
|
+
const dataType = typeCheckRules[type] ? typeCheckRules[type](target) : getDataType(target) === type;
|
|
29
|
+
return dataType;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/clone.ts
|
|
34
|
+
//! Function Shallow Copy
|
|
35
|
+
function shallowClone(source) {
|
|
36
|
+
if (isType("array", source)) return source.slice();
|
|
37
|
+
if (isType("object", source)) return { ...source };
|
|
38
|
+
return source;
|
|
39
|
+
}
|
|
40
|
+
//! Function Deep Copy
|
|
41
|
+
const isFormat = (target) => isType("object", target) || isType("function", target);
|
|
42
|
+
function handleSpeciBoundar(source, dpClone, hash) {
|
|
43
|
+
if (isType("symbol", source)) return Symbol(source.description);
|
|
44
|
+
if (!isFormat(source)) return source;
|
|
45
|
+
if (isType("set", source)) {
|
|
46
|
+
const newSet = /* @__PURE__ */ new Set();
|
|
47
|
+
source.forEach((value) => newSet.add(dpClone(value, hash)));
|
|
48
|
+
return newSet;
|
|
49
|
+
}
|
|
50
|
+
if (isType("map", source)) {
|
|
51
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
52
|
+
source.forEach((value, key) => newMap.set(key, dpClone(value, hash)));
|
|
53
|
+
return newMap;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function deepClone(source, hash = /* @__PURE__ */ new WeakMap()) {
|
|
58
|
+
if (hash.get(source)) return hash.get(source);
|
|
59
|
+
const result = handleSpeciBoundar(source, deepClone, hash);
|
|
60
|
+
if (result) return result;
|
|
61
|
+
const isArray = isType("array", source);
|
|
62
|
+
const cloneObject = isArray ? [] : {};
|
|
63
|
+
hash.set(source, cloneObject);
|
|
64
|
+
if (isArray) source.forEach((item, index) => {
|
|
65
|
+
cloneObject[index] = deepClone(item, hash);
|
|
66
|
+
});
|
|
67
|
+
else {
|
|
68
|
+
Object.keys(source).forEach((key) => {
|
|
69
|
+
cloneObject[key] = deepClone(source[key], hash);
|
|
70
|
+
});
|
|
71
|
+
Object.getOwnPropertySymbols(source).forEach((sym) => {
|
|
72
|
+
cloneObject[Symbol(sym.description)] = deepClone(source[sym], hash);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return cloneObject;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/others.ts
|
|
80
|
+
function currying(fn) {
|
|
81
|
+
function curried(...args) {
|
|
82
|
+
if (args.length >= fn.length) return fn.apply(this, args);
|
|
83
|
+
return function subCurried(...args2) {
|
|
84
|
+
return curried.apply(this, args.concat(args2));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return curried;
|
|
88
|
+
}
|
|
89
|
+
function compose(...fns) {
|
|
90
|
+
const { length } = fns;
|
|
91
|
+
if (length <= 0) return null;
|
|
92
|
+
for (let i = 0; i < length; i++) {
|
|
93
|
+
const fn = fns[i];
|
|
94
|
+
if (typeof fn !== "function") throw new TypeError(`argument with index ${i} is not a function`);
|
|
95
|
+
}
|
|
96
|
+
function executeFn(...args) {
|
|
97
|
+
let index = 0;
|
|
98
|
+
let result = fns[index].apply(this, args);
|
|
99
|
+
while (++index < length) result = fns[index].call(this, result);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
return executeFn;
|
|
103
|
+
}
|
|
104
|
+
function insertStr(soure, start, newStr) {
|
|
105
|
+
return soure.slice(0, start) + newStr + soure.slice(start);
|
|
106
|
+
}
|
|
107
|
+
function setCaseType(soure, type) {
|
|
108
|
+
const newStr = soure.slice(0, 1)[type === "upper" ? "toUpperCase" : "toLowerCase"]() + soure.slice(1).toLowerCase();
|
|
109
|
+
return newStr;
|
|
110
|
+
}
|
|
111
|
+
function stringCase(soure, separa = ["", ""], cases = ["upper", "upper"]) {
|
|
112
|
+
const [separator, separate] = separa;
|
|
113
|
+
const [firstCase, argsCase] = cases;
|
|
114
|
+
const newStr = soure.split(separator);
|
|
115
|
+
for (let i = 0; i < newStr.length; i++) newStr[i] = setCaseType(newStr[i], i === 0 ? firstCase : argsCase);
|
|
116
|
+
return newStr.join(separate);
|
|
117
|
+
}
|
|
118
|
+
const transformGetParams = (params) => {
|
|
119
|
+
let result = "";
|
|
120
|
+
for (const propName of Object.keys(params)) {
|
|
121
|
+
const value = params[propName];
|
|
122
|
+
const part = `${encodeURIComponent(propName)}=`;
|
|
123
|
+
if (isType("empty", value)) continue;
|
|
124
|
+
if (!isType("object", value)) {
|
|
125
|
+
result += `${part + encodeURIComponent(value)}&`;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
for (const key of Object.keys(value)) {
|
|
129
|
+
if (!isType("empty", value)) continue;
|
|
130
|
+
const paramsStr = `${propName}[${key}]`;
|
|
131
|
+
const subPart = `${encodeURIComponent(paramsStr)}=`;
|
|
132
|
+
result += `${subPart + encodeURIComponent(value[key])}&`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result.slice(0, -1);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/retalimit.ts
|
|
140
|
+
function debounce(callback, delay = 0, immediate = false) {
|
|
141
|
+
let timer = null;
|
|
142
|
+
let isInvoke = false;
|
|
143
|
+
function subDebounce(...args) {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
if (timer !== null) clearTimeout(timer);
|
|
146
|
+
if (immediate && !isInvoke) {
|
|
147
|
+
try {
|
|
148
|
+
const result = callback.apply(this, args);
|
|
149
|
+
resolve(result);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
reject(error);
|
|
152
|
+
}
|
|
153
|
+
isInvoke = true;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
timer = setTimeout(() => {
|
|
157
|
+
try {
|
|
158
|
+
const result = callback.apply(this, args);
|
|
159
|
+
resolve(result);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
reject(error);
|
|
162
|
+
} finally {
|
|
163
|
+
timer = null;
|
|
164
|
+
isInvoke = false;
|
|
165
|
+
}
|
|
166
|
+
}, delay);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
subDebounce.cancel = () => {
|
|
170
|
+
if (timer !== null) clearTimeout(timer);
|
|
171
|
+
timer = null;
|
|
172
|
+
isInvoke = false;
|
|
173
|
+
};
|
|
174
|
+
return subDebounce;
|
|
175
|
+
}
|
|
176
|
+
function throttle(callback, interval, options = {}) {
|
|
177
|
+
const { leading = true, trailing = false } = options;
|
|
178
|
+
let startTime = 0;
|
|
179
|
+
let timer = null;
|
|
180
|
+
function subThrottle(...args) {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
try {
|
|
183
|
+
const nowTime = Date.now();
|
|
184
|
+
let result;
|
|
185
|
+
if (!leading && startTime === 0) startTime = nowTime;
|
|
186
|
+
const waitTime = interval - (nowTime - startTime);
|
|
187
|
+
if (waitTime <= 0) {
|
|
188
|
+
if (timer) clearTimeout(timer);
|
|
189
|
+
result = callback.apply(this, args);
|
|
190
|
+
resolve(result);
|
|
191
|
+
startTime = nowTime;
|
|
192
|
+
timer = null;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (trailing && !timer) timer = setTimeout(() => {
|
|
196
|
+
result = callback.apply(this, args);
|
|
197
|
+
resolve(result);
|
|
198
|
+
startTime = Date.now();
|
|
199
|
+
timer = null;
|
|
200
|
+
}, waitTime);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
reject(error);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
subThrottle.cancel = () => {
|
|
207
|
+
if (timer) clearTimeout(timer);
|
|
208
|
+
startTime = 0;
|
|
209
|
+
timer = null;
|
|
210
|
+
};
|
|
211
|
+
return subThrottle;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/sort.ts
|
|
216
|
+
let SortType = /* @__PURE__ */ function(SortType$1) {
|
|
217
|
+
SortType$1["ASC"] = "ASC";
|
|
218
|
+
SortType$1["DESC"] = "DESC";
|
|
219
|
+
return SortType$1;
|
|
220
|
+
}({});
|
|
221
|
+
function swap(array, index1, index2) {
|
|
222
|
+
[array[index1], array[index2]] = [array[index2], array[index1]];
|
|
223
|
+
}
|
|
224
|
+
function compare(value1, value2, type) {
|
|
225
|
+
return type === SortType.ASC ? value1 > value2 : value1 < value2;
|
|
226
|
+
}
|
|
227
|
+
function bubblingSort(array, type = "ASC", key) {
|
|
228
|
+
const { length } = array;
|
|
229
|
+
if (length < 2) return array;
|
|
230
|
+
for (let i = 0; i < length - 1; i++) for (let j = 0; j < length - 1 - i; j++) {
|
|
231
|
+
const value1 = key ? array[j][key] : array[j];
|
|
232
|
+
const value2 = key ? array[j + 1][key] : array[j + 1];
|
|
233
|
+
if (compare(value1, value2, type)) swap(array, j, j + 1);
|
|
234
|
+
}
|
|
235
|
+
return array;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/timer.ts
|
|
240
|
+
const formatRules = new Map([
|
|
241
|
+
["yyyy", "year"],
|
|
242
|
+
["MM", "month"],
|
|
243
|
+
["dd", "day"],
|
|
244
|
+
["HH", "hours"],
|
|
245
|
+
["mm", "minutes"],
|
|
246
|
+
["ss", "seconds"],
|
|
247
|
+
["W", "week"]
|
|
248
|
+
]);
|
|
249
|
+
const WeekList = new Map([
|
|
250
|
+
[1, "一"],
|
|
251
|
+
[2, "二"],
|
|
252
|
+
[3, "三"],
|
|
253
|
+
[4, "四"],
|
|
254
|
+
[5, "五"],
|
|
255
|
+
[6, "六"],
|
|
256
|
+
[0, "日"]
|
|
257
|
+
]);
|
|
258
|
+
function processWeek(weekNum) {
|
|
259
|
+
return WeekList.get(weekNum) || "";
|
|
260
|
+
}
|
|
261
|
+
function formatNumber(value) {
|
|
262
|
+
return value.toString().padStart(2, "0");
|
|
263
|
+
}
|
|
264
|
+
function createTimerFormatObj(date) {
|
|
265
|
+
const dayOfWeek = date.getDay() === 0 ? 7 : date.getDay();
|
|
266
|
+
return {
|
|
267
|
+
year: date.getFullYear().toString(),
|
|
268
|
+
month: formatNumber(date.getMonth() + 1),
|
|
269
|
+
day: formatNumber(date.getDate()),
|
|
270
|
+
hours: formatNumber(date.getHours()),
|
|
271
|
+
minutes: formatNumber(date.getMinutes()),
|
|
272
|
+
seconds: formatNumber(date.getSeconds()),
|
|
273
|
+
week: processWeek(dayOfWeek),
|
|
274
|
+
weekNum: dayOfWeek.toString()
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const formatTimer = (cellValue, formatOption = "yyyy-MM-dd HH:mm:ss") => {
|
|
278
|
+
if (!cellValue) return (/* @__PURE__ */ new Date()).toISOString();
|
|
279
|
+
const date = new Date(cellValue);
|
|
280
|
+
const timerFormatObj = createTimerFormatObj(date);
|
|
281
|
+
if (isType("string", formatOption) && !formatOption.trim()) return timerFormatObj;
|
|
282
|
+
const timerFormatStr = Array.from(formatRules).reduce((currentFormat, [rule, key]) => {
|
|
283
|
+
return currentFormat.replace(new RegExp(rule, "g"), timerFormatObj[key]);
|
|
284
|
+
}, formatOption);
|
|
285
|
+
return timerFormatStr;
|
|
286
|
+
};
|
|
287
|
+
async function setTimer(execute, delay = 0, immediate = false) {
|
|
288
|
+
let timer = null;
|
|
289
|
+
const interval = async () => {
|
|
290
|
+
await execute();
|
|
291
|
+
timer = setTimeout(interval, delay);
|
|
292
|
+
};
|
|
293
|
+
if (immediate) await execute();
|
|
294
|
+
setTimeout(interval, delay);
|
|
295
|
+
return { cancel: () => {
|
|
296
|
+
if (timer !== null) clearTimeout(timer);
|
|
297
|
+
} };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
//#endregion
|
|
301
|
+
exports.SortType = SortType;
|
|
302
|
+
exports.bubblingSort = bubblingSort;
|
|
303
|
+
exports.compose = compose;
|
|
304
|
+
exports.currying = currying;
|
|
305
|
+
exports.debounce = debounce;
|
|
306
|
+
exports.deepClone = deepClone;
|
|
307
|
+
exports.formatTimer = formatTimer;
|
|
308
|
+
exports.insertStr = insertStr;
|
|
309
|
+
exports.isType = isType;
|
|
310
|
+
exports.setTimer = setTimer;
|
|
311
|
+
exports.shallowClone = shallowClone;
|
|
312
|
+
exports.stringCase = stringCase;
|
|
313
|
+
exports.throttle = throttle;
|
|
314
|
+
exports.transformGetParams = transformGetParams;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/clone.d.ts
|
|
2
|
+
declare function shallowClone<T = any>(source: T): T;
|
|
3
|
+
declare function deepClone(source: any, hash?: WeakMap<object, any>): any;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
type CaseType = 'upper' | 'lower';
|
|
7
|
+
type CaseTypeTuple = [CaseType, CaseType];
|
|
8
|
+
type FormatTimerFn = (cellValue: string | number | Date, formatType?: string) => string | TimerFormatObj;
|
|
9
|
+
interface TimerFormatObj {
|
|
10
|
+
year: string;
|
|
11
|
+
month: string;
|
|
12
|
+
day: string;
|
|
13
|
+
hours: string;
|
|
14
|
+
minutes: string;
|
|
15
|
+
seconds: string;
|
|
16
|
+
week: string;
|
|
17
|
+
weekNum: string;
|
|
18
|
+
}
|
|
19
|
+
interface ThrottleOptions {
|
|
20
|
+
leading?: boolean;
|
|
21
|
+
trailing?: boolean;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/others.d.ts
|
|
25
|
+
declare function currying(fn: (...args: any[]) => any): (this: any, ...args: any[]) => any;
|
|
26
|
+
declare function compose(...fns: ((...args: any[]) => any)[]): ((this: any, ...args: any[]) => any) | null;
|
|
27
|
+
declare function insertStr(soure: string, start: number, newStr: string): string;
|
|
28
|
+
declare function stringCase(soure: string, separa?: string[], cases?: CaseTypeTuple): string;
|
|
29
|
+
declare const transformGetParams: (params: Record<string, any>) => string;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/retalimit.d.ts
|
|
32
|
+
declare function debounce<T extends (...args: any[]) => any>(callback: T, delay?: number, immediate?: boolean): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
|
|
33
|
+
cancel: () => void;
|
|
34
|
+
};
|
|
35
|
+
declare function throttle<T extends (...args: any[]) => any>(callback: T, interval: number, options?: ThrottleOptions): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
|
|
36
|
+
cancel: () => void;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/sort.d.ts
|
|
40
|
+
declare enum SortType {
|
|
41
|
+
ASC = "ASC",
|
|
42
|
+
DESC = "DESC",
|
|
43
|
+
}
|
|
44
|
+
declare function bubblingSort<T>(array: T[], type?: string, key?: keyof T): T[];
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/timer.d.ts
|
|
47
|
+
declare const formatTimer: FormatTimerFn;
|
|
48
|
+
declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): Promise<{
|
|
49
|
+
cancel: () => void;
|
|
50
|
+
}>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/typeof.d.ts
|
|
53
|
+
declare const typeCheckRules: {
|
|
54
|
+
undefined: (target: unknown) => target is undefined;
|
|
55
|
+
null: (target: unknown) => target is null;
|
|
56
|
+
number: (target: unknown) => target is number;
|
|
57
|
+
string: (target: unknown) => target is string;
|
|
58
|
+
boolean: (target: unknown) => target is boolean;
|
|
59
|
+
symbol: (target: unknown) => target is symbol;
|
|
60
|
+
bigint: (target: unknown) => target is bigint;
|
|
61
|
+
object: (target: unknown) => target is object;
|
|
62
|
+
array: (target: unknown) => target is any[];
|
|
63
|
+
function: (target: unknown) => target is Function;
|
|
64
|
+
date: (target: unknown) => target is Date;
|
|
65
|
+
set: (target: unknown) => target is Set<any>;
|
|
66
|
+
map: (target: unknown) => target is Map<any, any>;
|
|
67
|
+
regexp: (target: unknown) => target is RegExp;
|
|
68
|
+
promise: (target: unknown) => target is Promise<any>;
|
|
69
|
+
empty(target: unknown): target is "";
|
|
70
|
+
};
|
|
71
|
+
type TypeCheckOption = keyof typeof typeCheckRules;
|
|
72
|
+
declare const isType: (type: TypeCheckOption, target: unknown) => boolean;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { SortType, bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, setTimer, shallowClone, stringCase, throttle, transformGetParams };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/clone.d.ts
|
|
2
|
+
declare function shallowClone<T = any>(source: T): T;
|
|
3
|
+
declare function deepClone(source: any, hash?: WeakMap<object, any>): any;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
type CaseType = 'upper' | 'lower';
|
|
7
|
+
type CaseTypeTuple = [CaseType, CaseType];
|
|
8
|
+
type FormatTimerFn = (cellValue: string | number | Date, formatType?: string) => string | TimerFormatObj;
|
|
9
|
+
interface TimerFormatObj {
|
|
10
|
+
year: string;
|
|
11
|
+
month: string;
|
|
12
|
+
day: string;
|
|
13
|
+
hours: string;
|
|
14
|
+
minutes: string;
|
|
15
|
+
seconds: string;
|
|
16
|
+
week: string;
|
|
17
|
+
weekNum: string;
|
|
18
|
+
}
|
|
19
|
+
interface ThrottleOptions {
|
|
20
|
+
leading?: boolean;
|
|
21
|
+
trailing?: boolean;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/others.d.ts
|
|
25
|
+
declare function currying(fn: (...args: any[]) => any): (this: any, ...args: any[]) => any;
|
|
26
|
+
declare function compose(...fns: ((...args: any[]) => any)[]): ((this: any, ...args: any[]) => any) | null;
|
|
27
|
+
declare function insertStr(soure: string, start: number, newStr: string): string;
|
|
28
|
+
declare function stringCase(soure: string, separa?: string[], cases?: CaseTypeTuple): string;
|
|
29
|
+
declare const transformGetParams: (params: Record<string, any>) => string;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/retalimit.d.ts
|
|
32
|
+
declare function debounce<T extends (...args: any[]) => any>(callback: T, delay?: number, immediate?: boolean): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
|
|
33
|
+
cancel: () => void;
|
|
34
|
+
};
|
|
35
|
+
declare function throttle<T extends (...args: any[]) => any>(callback: T, interval: number, options?: ThrottleOptions): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
|
|
36
|
+
cancel: () => void;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/sort.d.ts
|
|
40
|
+
declare enum SortType {
|
|
41
|
+
ASC = "ASC",
|
|
42
|
+
DESC = "DESC",
|
|
43
|
+
}
|
|
44
|
+
declare function bubblingSort<T>(array: T[], type?: string, key?: keyof T): T[];
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/timer.d.ts
|
|
47
|
+
declare const formatTimer: FormatTimerFn;
|
|
48
|
+
declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): Promise<{
|
|
49
|
+
cancel: () => void;
|
|
50
|
+
}>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/typeof.d.ts
|
|
53
|
+
declare const typeCheckRules: {
|
|
54
|
+
undefined: (target: unknown) => target is undefined;
|
|
55
|
+
null: (target: unknown) => target is null;
|
|
56
|
+
number: (target: unknown) => target is number;
|
|
57
|
+
string: (target: unknown) => target is string;
|
|
58
|
+
boolean: (target: unknown) => target is boolean;
|
|
59
|
+
symbol: (target: unknown) => target is symbol;
|
|
60
|
+
bigint: (target: unknown) => target is bigint;
|
|
61
|
+
object: (target: unknown) => target is object;
|
|
62
|
+
array: (target: unknown) => target is any[];
|
|
63
|
+
function: (target: unknown) => target is Function;
|
|
64
|
+
date: (target: unknown) => target is Date;
|
|
65
|
+
set: (target: unknown) => target is Set<any>;
|
|
66
|
+
map: (target: unknown) => target is Map<any, any>;
|
|
67
|
+
regexp: (target: unknown) => target is RegExp;
|
|
68
|
+
promise: (target: unknown) => target is Promise<any>;
|
|
69
|
+
empty(target: unknown): target is "";
|
|
70
|
+
};
|
|
71
|
+
type TypeCheckOption = keyof typeof typeCheckRules;
|
|
72
|
+
declare const isType: (type: TypeCheckOption, target: unknown) => boolean;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { SortType, bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, setTimer, shallowClone, stringCase, throttle, transformGetParams };
|