a-js-tools 0.0.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.
- package/LICENSE +13 -0
- package/README.md +25 -0
- package/cjs/index.cjs +14 -0
- package/cjs/src/data.cjs +9 -0
- package/cjs/src/pureFunction.cjs +120 -0
- package/mjs/index.mjs +2 -0
- package/mjs/src/data.mjs +6 -0
- package/mjs/src/pureFunction.mjs +114 -0
- package/package.json +68 -0
- package/types/index.d.ts +2 -0
- package/types/src/data.d.ts +4 -0
- package/types/src/pureFunction.d.ts +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright (c) <2024> <letmiseesee>
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# a-js-tools
|
|
2
|
+
|
|
3
|
+
A purely functional tool that includes
|
|
4
|
+
|
|
5
|
+
- pure function
|
|
6
|
+
|
|
7
|
+
## language
|
|
8
|
+
|
|
9
|
+
[English](https://github.com/lmssee/js-tools/blob/main/README.md) [中文](https://github.com/lmssee/js-tools/blob/main/自述文件.md)
|
|
10
|
+
|
|
11
|
+
## install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install a-js-tools --save
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## pure function
|
|
18
|
+
|
|
19
|
+
- `typeOf` Verify data type
|
|
20
|
+
- `lmDebounce` Anti shake function
|
|
21
|
+
- `lmThrottle` Throttling function
|
|
22
|
+
- `getRandomInt` get random int number
|
|
23
|
+
- `getRandomFloat` get random float number
|
|
24
|
+
|
|
25
|
+
If you have any questions, you can directly [submit question](https://github.com/lmssee/js-tools/issues/new)
|
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pureFunction = require('./src/pureFunction.cjs');
|
|
4
|
+
var data = require('./src/data.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.debounce = pureFunction.debounce;
|
|
9
|
+
exports.getRandomFloat = pureFunction.getRandomFloat;
|
|
10
|
+
exports.getRandomInt = pureFunction.getRandomInt;
|
|
11
|
+
exports.throttle = pureFunction.throttle;
|
|
12
|
+
exports.typeOf = pureFunction.typeOf;
|
|
13
|
+
exports.isTTY = data.isTTY;
|
|
14
|
+
exports.t = data.t;
|
package/cjs/src/data.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 获取数据的类型
|
|
5
|
+
*
|
|
6
|
+
* @param {*} o 任意数据
|
|
7
|
+
* @return {*} 返回是一个字符串 {@link String},包含于 @see {@link TypeOf}
|
|
8
|
+
*/
|
|
9
|
+
function typeOf(o) {
|
|
10
|
+
return Reflect.apply(Object.prototype.toString, o, [])
|
|
11
|
+
.replace(/^.*\s(.*)]$/, '$1')
|
|
12
|
+
.toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 防抖
|
|
16
|
+
*
|
|
17
|
+
* 这种设计有一种不好的地方就是倘若最后一次尚未执行,不好清理
|
|
18
|
+
* @param {*} callback
|
|
19
|
+
* @param {number} delay 缺省 300 ms
|
|
20
|
+
* @return {*} 返回的是一个函数
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
function debounce(callback, delay = 200) {
|
|
24
|
+
// 强制转换非数值
|
|
25
|
+
if (typeof delay != 'number' || isNaN(delay))
|
|
26
|
+
delay = 200;
|
|
27
|
+
let timeout;
|
|
28
|
+
return ((...args) => {
|
|
29
|
+
clearTimeout(timeout);
|
|
30
|
+
timeout = setTimeout(() => Reflect.apply(callback, null, args), Math.max(delay, 0));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 节流函数
|
|
35
|
+
* @param callback
|
|
36
|
+
* @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
|
|
37
|
+
* @returns 返回的是一个函数
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
function throttle(callback, delay = 200) {
|
|
41
|
+
// 强制转换非数值
|
|
42
|
+
if (typeof delay != 'number' || isNaN(delay))
|
|
43
|
+
delay = 200;
|
|
44
|
+
/** 延迟控制插销 */
|
|
45
|
+
let inThrottle = true;
|
|
46
|
+
return ((...args) => {
|
|
47
|
+
if (!inThrottle)
|
|
48
|
+
return;
|
|
49
|
+
Reflect.apply(callback, null, args);
|
|
50
|
+
inThrottle = false;
|
|
51
|
+
setTimeout(() => (inThrottle = true), Math.max(delay, 0));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** 响应的 */
|
|
55
|
+
// function responsive(target: any) {
|
|
56
|
+
// const handle = {
|
|
57
|
+
// get(target: any, key: any, receiver: any) {
|
|
58
|
+
// console.log(`捕获到 key: ${key}`);
|
|
59
|
+
// return Reflect.get(target, key, receiver);
|
|
60
|
+
// },
|
|
61
|
+
// set(target: any, key: any, value: any, receiver: any) {
|
|
62
|
+
// console.log(`设置值 ${value} 到属性 ${key}`);
|
|
63
|
+
// return Reflect.set(target, key, value, receiver);
|
|
64
|
+
// },
|
|
65
|
+
// };
|
|
66
|
+
// return new Proxy(target, handle);
|
|
67
|
+
// }
|
|
68
|
+
/**
|
|
69
|
+
* 监听
|
|
70
|
+
*/
|
|
71
|
+
// function Listener(vm: any, expOrFn: any, cb: any) {
|
|
72
|
+
// // @ts-ignore
|
|
73
|
+
// (this.vm = vm),
|
|
74
|
+
// (this.expOrFn = expOrFn),
|
|
75
|
+
// (this.cb = cb),
|
|
76
|
+
// Reflect.apply(this.cb, this.vm, [this.evaluate()]);
|
|
77
|
+
// }
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* 获取一个随机整数
|
|
81
|
+
*
|
|
82
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
83
|
+
*
|
|
84
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
|
|
85
|
+
*
|
|
86
|
+
* @export
|
|
87
|
+
* @param {number} max 最大值
|
|
88
|
+
* @param {number} [min] 最小值
|
|
89
|
+
* @return {*} {number}
|
|
90
|
+
*/
|
|
91
|
+
function getRandomInt(max = 1, min = 0) {
|
|
92
|
+
let _min = Math.ceil(Number(min)), _max = Math.floor(Number(max));
|
|
93
|
+
_min > _max && ([_max, _min] = [_min, _max]);
|
|
94
|
+
return Math.floor(Math.random() * (_max - _min + 1) + _min);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* 获取一个随机浮点数数
|
|
99
|
+
*
|
|
100
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
101
|
+
*
|
|
102
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
|
|
103
|
+
*
|
|
104
|
+
* @export
|
|
105
|
+
* @param {number} max 最大值,缺省 1
|
|
106
|
+
* @param {number} [min] 最小值,缺省 0
|
|
107
|
+
* @return {*} {number}
|
|
108
|
+
*/
|
|
109
|
+
function getRandomFloat(max = 1, min = 0) {
|
|
110
|
+
if (max == min)
|
|
111
|
+
max++;
|
|
112
|
+
min > max && ([max, min] = [min, max]);
|
|
113
|
+
return Math.random() * (max - min) + min;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.debounce = debounce;
|
|
117
|
+
exports.getRandomFloat = getRandomFloat;
|
|
118
|
+
exports.getRandomInt = getRandomInt;
|
|
119
|
+
exports.throttle = throttle;
|
|
120
|
+
exports.typeOf = typeOf;
|
package/mjs/index.mjs
ADDED
package/mjs/src/data.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取数据的类型
|
|
3
|
+
*
|
|
4
|
+
* @param {*} o 任意数据
|
|
5
|
+
* @return {*} 返回是一个字符串 {@link String},包含于 @see {@link TypeOf}
|
|
6
|
+
*/
|
|
7
|
+
function typeOf(o) {
|
|
8
|
+
return Reflect.apply(Object.prototype.toString, o, [])
|
|
9
|
+
.replace(/^.*\s(.*)]$/, '$1')
|
|
10
|
+
.toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 防抖
|
|
14
|
+
*
|
|
15
|
+
* 这种设计有一种不好的地方就是倘若最后一次尚未执行,不好清理
|
|
16
|
+
* @param {*} callback
|
|
17
|
+
* @param {number} delay 缺省 300 ms
|
|
18
|
+
* @return {*} 返回的是一个函数
|
|
19
|
+
*/
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
function debounce(callback, delay = 200) {
|
|
22
|
+
// 强制转换非数值
|
|
23
|
+
if (typeof delay != 'number' || isNaN(delay))
|
|
24
|
+
delay = 200;
|
|
25
|
+
let timeout;
|
|
26
|
+
return ((...args) => {
|
|
27
|
+
clearTimeout(timeout);
|
|
28
|
+
timeout = setTimeout(() => Reflect.apply(callback, null, args), Math.max(delay, 0));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 节流函数
|
|
33
|
+
* @param callback
|
|
34
|
+
* @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
|
|
35
|
+
* @returns 返回的是一个函数
|
|
36
|
+
*/
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
function throttle(callback, delay = 200) {
|
|
39
|
+
// 强制转换非数值
|
|
40
|
+
if (typeof delay != 'number' || isNaN(delay))
|
|
41
|
+
delay = 200;
|
|
42
|
+
/** 延迟控制插销 */
|
|
43
|
+
let inThrottle = true;
|
|
44
|
+
return ((...args) => {
|
|
45
|
+
if (!inThrottle)
|
|
46
|
+
return;
|
|
47
|
+
Reflect.apply(callback, null, args);
|
|
48
|
+
inThrottle = false;
|
|
49
|
+
setTimeout(() => (inThrottle = true), Math.max(delay, 0));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** 响应的 */
|
|
53
|
+
// function responsive(target: any) {
|
|
54
|
+
// const handle = {
|
|
55
|
+
// get(target: any, key: any, receiver: any) {
|
|
56
|
+
// console.log(`捕获到 key: ${key}`);
|
|
57
|
+
// return Reflect.get(target, key, receiver);
|
|
58
|
+
// },
|
|
59
|
+
// set(target: any, key: any, value: any, receiver: any) {
|
|
60
|
+
// console.log(`设置值 ${value} 到属性 ${key}`);
|
|
61
|
+
// return Reflect.set(target, key, value, receiver);
|
|
62
|
+
// },
|
|
63
|
+
// };
|
|
64
|
+
// return new Proxy(target, handle);
|
|
65
|
+
// }
|
|
66
|
+
/**
|
|
67
|
+
* 监听
|
|
68
|
+
*/
|
|
69
|
+
// function Listener(vm: any, expOrFn: any, cb: any) {
|
|
70
|
+
// // @ts-ignore
|
|
71
|
+
// (this.vm = vm),
|
|
72
|
+
// (this.expOrFn = expOrFn),
|
|
73
|
+
// (this.cb = cb),
|
|
74
|
+
// Reflect.apply(this.cb, this.vm, [this.evaluate()]);
|
|
75
|
+
// }
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* 获取一个随机整数
|
|
79
|
+
*
|
|
80
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
81
|
+
*
|
|
82
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
|
|
83
|
+
*
|
|
84
|
+
* @export
|
|
85
|
+
* @param {number} max 最大值
|
|
86
|
+
* @param {number} [min] 最小值
|
|
87
|
+
* @return {*} {number}
|
|
88
|
+
*/
|
|
89
|
+
function getRandomInt(max = 1, min = 0) {
|
|
90
|
+
let _min = Math.ceil(Number(min)), _max = Math.floor(Number(max));
|
|
91
|
+
_min > _max && ([_max, _min] = [_min, _max]);
|
|
92
|
+
return Math.floor(Math.random() * (_max - _min + 1) + _min);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* 获取一个随机浮点数数
|
|
97
|
+
*
|
|
98
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
99
|
+
*
|
|
100
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
|
|
101
|
+
*
|
|
102
|
+
* @export
|
|
103
|
+
* @param {number} max 最大值,缺省 1
|
|
104
|
+
* @param {number} [min] 最小值,缺省 0
|
|
105
|
+
* @return {*} {number}
|
|
106
|
+
*/
|
|
107
|
+
function getRandomFloat(max = 1, min = 0) {
|
|
108
|
+
if (max == min)
|
|
109
|
+
max++;
|
|
110
|
+
min > max && ([max, min] = [min, max]);
|
|
111
|
+
return Math.random() * (max - min) + min;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { debounce, getRandomFloat, getRandomInt, throttle, typeOf };
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"name": "a-js-tools",
|
|
5
|
+
"main": "cjs/index.cjs",
|
|
6
|
+
"module": "mjs/index.mjs",
|
|
7
|
+
"typings": "types/index.d.ts",
|
|
8
|
+
"description": "some function",
|
|
9
|
+
"files": [
|
|
10
|
+
"cjs/",
|
|
11
|
+
"mjs/",
|
|
12
|
+
"types/"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
"import": "./mjs/index.mjs",
|
|
16
|
+
"require": "./cjs/index.cjs",
|
|
17
|
+
"types": "./types/index.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"b": "rollup --config rollup.config.js && tsc -p tsconfig.types.json",
|
|
21
|
+
"build": "npx ixxx rm dist run b",
|
|
22
|
+
"clean": "npx ixxx up -d r node_modules package-lock.json run npm install run build",
|
|
23
|
+
"prettier": "npx prettier . --write",
|
|
24
|
+
"test": "npx ixxx rm test/out && rollup --config rollup.config.test.js && node test/out/test/index.mjs",
|
|
25
|
+
"versionPatch": "npm version patch --force --no-git-tag-version --allow-same-version=true",
|
|
26
|
+
"up": "npx ixxx pkg -u && npm run versionPatch && npm run build && cd dist && npm publish && cd ../"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/lmssee/js-tools.git"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"js-tools",
|
|
34
|
+
"a-js-tools"
|
|
35
|
+
],
|
|
36
|
+
"author": "lmssee <lmssee@outlook.com> (https://lmssee.github.io)",
|
|
37
|
+
"homepage": "https://lmssee.github.io/js-tools",
|
|
38
|
+
"license": "ISC",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/lmssee/js-tools/issues",
|
|
41
|
+
"email": "lmssee@outlook.com"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org/"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"tslib": "^2.6.3"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@eslint/js": "^9.6.0",
|
|
52
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
53
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
54
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
55
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
56
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
57
|
+
"@types/node": "^20.14.9",
|
|
58
|
+
"eslint": "^8.57.0",
|
|
59
|
+
"eslint-config-prettier": "^9.1.0",
|
|
60
|
+
"globals": "^15.7.0",
|
|
61
|
+
"prettier": "^3.3.2",
|
|
62
|
+
"rollup-plugin-cleanup": "^3.2.1",
|
|
63
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
64
|
+
"ts-node": "^10.9.2",
|
|
65
|
+
"typescript": "^5.5.3",
|
|
66
|
+
"typescript-eslint": "^7.15.0"
|
|
67
|
+
}
|
|
68
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** 数据类型
|
|
2
|
+
*
|
|
3
|
+
* {@link typeOf} 检测出来的数据类型
|
|
4
|
+
*
|
|
5
|
+
* - number 数组类型 {@link Number}
|
|
6
|
+
* - function 函数(一种特殊的对象) {@link Function}
|
|
7
|
+
* - string 字符串 {@link String}
|
|
8
|
+
* - array 数组(一种有序的对象) {@link Array}
|
|
9
|
+
* - boolean 布尔值 {@link Boolean} ,仅有 true 和 false 两种能值
|
|
10
|
+
* - undefined 值未定义或未赋值 {@link undefined}
|
|
11
|
+
* - object 对象 {@link Object}、{@link Proxy}
|
|
12
|
+
* - null 指向一个特殊的空对象 null
|
|
13
|
+
* - regexp 正则 {@link RegExp}
|
|
14
|
+
* - set 值的集合 {@link Set}
|
|
15
|
+
* - map 保存键值对,且有序的 {@link Map}
|
|
16
|
+
* - date 时间 {@link Date}
|
|
17
|
+
* - bigint 内置对象,它提供了一种方法来表示大于 2^53 - 1 的整数 {@link BigInt}
|
|
18
|
+
* - bigint64array 64 位有符号整数组成的数组 {@link BigInt64Array}
|
|
19
|
+
* - biguint64array 64 位无符号整数组成的数组 {@link BigInt64Array}
|
|
20
|
+
* - symbol
|
|
21
|
+
* - error 错误类型 {@link Error}、 {@link URIError}、{@link TypeError}、{@link SyntaxError}、${@link ReferenceError}、{@link RangeError}、{@link EvalError}、{@link AggregateError}
|
|
22
|
+
* - int8array 二进制补码 8 位有符号整数的数组 {@link Int8Array }
|
|
23
|
+
* - uint8array 8 位无符号整型数组 {@link Uint8Array}
|
|
24
|
+
* - int16array 二进制补码 16 位有符号整数的数组 {@link Int16Array}
|
|
25
|
+
* - uint16array 16 位无符号整数 {@link Uint16Array}
|
|
26
|
+
* - int32array二进制补码 32 位有符号整数的数组 {@link Int32Array}
|
|
27
|
+
* - uint32array 32 位无符号整型数组 {@link Uint32Array}
|
|
28
|
+
* - float32array 32 位的浮点数型数组 {@link Float32Array}
|
|
29
|
+
* - float64array 64 位的浮点数型数组 {@link Float64Array}
|
|
30
|
+
* - uint8clampedarray 8 位无符号整型固定数组 {@link Uint8ClampedArray}
|
|
31
|
+
* - sharedarraybuffer 可以用来在共享内存上创建视图的二进制数据缓冲区,目前,浏览器不支持 {@link SharedArrayBuffer}
|
|
32
|
+
* - promise 异步操作最终的完成(或失败)以及其结果值 {@link Promise}
|
|
33
|
+
* - window 全局对象 {@link Window}、{@link globalThis}
|
|
34
|
+
* - dataview 从二进制 ArrayBuffer 对象中读写多种数值类型的底层接口 {@link DataView}
|
|
35
|
+
* - atomics 命名空间对象包含对 SharedArrayBuffer 和 ArrayBuffer 对象执行原子操作的静态方法 {@link Atomics}
|
|
36
|
+
* - arraybuffer 通用的原始二进制数据缓冲区 {@link ArrayBuffer}
|
|
37
|
+
*
|
|
38
|
+
* _NaN 即便意思非数字的值,但依旧是 {@link Number} 类型_
|
|
39
|
+
*/
|
|
40
|
+
export type TypeOf = 'number' | 'function' | 'string' | 'boolean' | 'object' | 'undefined' | 'null' | 'array' | 'date' | 'set' | 'map' | 'symbol' | 'bigint' | 'bigint64array' | 'biguint64array' | 'regexp' | 'int8array' | 'uint8array' | 'uint16array' | 'float32array' | 'float64array' | 'uint32array' | 'error' | 'uint8clampedarray' | 'sharedarraybuffer' | 'promise' | 'window' | 'dataview' | 'atomics' | 'arraybuffer';
|
|
41
|
+
/**
|
|
42
|
+
* 获取数据的类型
|
|
43
|
+
*
|
|
44
|
+
* @param {*} o 任意数据
|
|
45
|
+
* @return {*} 返回是一个字符串 {@link String},包含于 @see {@link TypeOf}
|
|
46
|
+
*/
|
|
47
|
+
export declare function typeOf(o: unknown): TypeOf;
|
|
48
|
+
/**
|
|
49
|
+
* 防抖
|
|
50
|
+
*
|
|
51
|
+
* 这种设计有一种不好的地方就是倘若最后一次尚未执行,不好清理
|
|
52
|
+
* @param {*} callback
|
|
53
|
+
* @param {number} delay 缺省 300 ms
|
|
54
|
+
* @return {*} 返回的是一个函数
|
|
55
|
+
*/
|
|
56
|
+
export declare function debounce<T extends (...args: any[]) => void>(callback: T, delay?: number): T;
|
|
57
|
+
/**
|
|
58
|
+
* 节流函数
|
|
59
|
+
* @param callback
|
|
60
|
+
* @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
|
|
61
|
+
* @returns 返回的是一个函数
|
|
62
|
+
*/
|
|
63
|
+
export declare function throttle<T extends (...args: any[]) => void>(callback: T, delay?: number): T;
|
|
64
|
+
/** 响应的 */
|
|
65
|
+
/**
|
|
66
|
+
* 监听
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* 获取一个随机整数
|
|
71
|
+
*
|
|
72
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
73
|
+
*
|
|
74
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
|
|
75
|
+
*
|
|
76
|
+
* @export
|
|
77
|
+
* @param {number} max 最大值
|
|
78
|
+
* @param {number} [min] 最小值
|
|
79
|
+
* @return {*} {number}
|
|
80
|
+
*/
|
|
81
|
+
export declare function getRandomInt(max?: number, min?: number): number;
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* 获取一个随机浮点数数
|
|
85
|
+
*
|
|
86
|
+
* 可传入两个参数,获取两参数之间的任意数
|
|
87
|
+
*
|
|
88
|
+
* 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
|
|
89
|
+
*
|
|
90
|
+
* @export
|
|
91
|
+
* @param {number} max 最大值,缺省 1
|
|
92
|
+
* @param {number} [min] 最小值,缺省 0
|
|
93
|
+
* @return {*} {number}
|
|
94
|
+
*/
|
|
95
|
+
export declare function getRandomFloat(max?: number, min?: number): number;
|