a-js-tools 2.0.0 → 2.0.2
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/README.md +0 -4
- package/cjs/array/difference.js +1 -4
- package/cjs/array/index.js +9 -30
- package/cjs/array/intersection.js +1 -6
- package/cjs/array/symmetricDifference.js +1 -7
- package/cjs/className.js +0 -4
- package/cjs/getRandomNumber.js +3 -9
- package/cjs/getRandomString.js +19 -19
- package/cjs/index.js +4 -4
- package/cjs/isNode.js +0 -4
- package/cjs/object/createConstructor.js +2 -5
- package/cjs/performance.js +8 -16
- package/cjs/regexp/autoEscapedRegExp.js +1 -5
- package/cjs/regexp/escapeRegExp.js +6 -8
- package/cjs/regexp/parse.js +0 -2
- package/cjs/sleep.js +3 -6
- package/es/array/difference.js +1 -4
- package/es/array/index.js +9 -30
- package/es/array/intersection.js +1 -6
- package/es/array/symmetricDifference.js +1 -7
- package/es/className.js +0 -4
- package/es/getRandomNumber.js +3 -9
- package/es/getRandomString.js +19 -19
- package/es/index.js +2 -2
- package/es/isNode.js +0 -4
- package/es/object/createConstructor.js +2 -5
- package/es/performance.js +5 -13
- package/es/regexp/autoEscapedRegExp.js +1 -5
- package/es/regexp/escapeRegExp.js +6 -8
- package/es/regexp/parse.js +0 -2
- package/es/sleep.js +2 -5
- package/es/{src → types}/array/difference.d.ts +1 -4
- package/es/{src → types}/array/index.d.ts +9 -30
- package/es/{src → types}/array/intersection.d.ts +1 -6
- package/es/{src → types}/array/symmetricDifference.d.ts +1 -7
- package/es/{src → types}/className.d.ts +0 -4
- package/es/{src → types}/getRandomNumber.d.ts +2 -4
- package/es/{src → types}/getRandomString.d.ts +11 -8
- package/es/{src → types}/isNode.d.ts +0 -4
- package/es/{src → types}/object/createConstructor.d.ts +2 -8
- package/es/{src → types}/performance.d.ts +4 -15
- package/es/{src → types}/regexp/autoEscapedRegExp.d.ts +1 -5
- package/es/types/regexp/escapeRegExp.d.ts +16 -0
- package/es/{src → types}/regexp/parse.d.ts +0 -2
- package/es/{src → types}/regexp/types.d.ts +0 -5
- package/es/{src → types}/sleep.d.ts +0 -3
- package/package.json +16 -24
- package/es/src/regexp/escapeRegExp.d.ts +0 -18
- /package/es/{src → types}/array/union.d.ts +0 -0
- /package/es/{src → types}/index.d.ts +0 -0
- /package/es/{src → types}/object/index.d.ts +0 -0
- /package/es/{src → types}/regexp/index.d.ts +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 获取一个随机的整数类型
|
|
2
|
+
* ## 获取一个随机的整数类型
|
|
4
3
|
*
|
|
5
4
|
* 您可以传入两个参数并获取它们之间的任意数字,返回值<span style="color:#ff0;">*会包含端值*</span>
|
|
6
5
|
*
|
|
@@ -12,8 +11,7 @@
|
|
|
12
11
|
*/
|
|
13
12
|
export declare function getRandomInt(max?: number, min?: number): number;
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
* 获取任意的浮点数
|
|
14
|
+
* ## 获取任意的浮点数
|
|
17
15
|
*
|
|
18
16
|
* 您可以传入两个参数并获取它们之间的任意数字
|
|
19
17
|
*
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 随机字符串 生成器
|
|
4
|
-
*
|
|
2
|
+
* 随机字符串生成器
|
|
5
3
|
*/
|
|
6
4
|
export type RandomStringOptions = {
|
|
7
5
|
/**
|
|
@@ -43,12 +41,17 @@ export type RandomStringOptions = {
|
|
|
43
41
|
type?: 'string' | 'uuid';
|
|
44
42
|
};
|
|
45
43
|
/**
|
|
44
|
+
* 获取简单的随机字符串
|
|
46
45
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
46
|
+
* @param options - 字符串生成参数
|
|
47
|
+
* @returns - 随机字符串
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { getRandomString } from 'a-js-tools';
|
|
52
51
|
*
|
|
52
|
+
* // 获取简单的随机字符串
|
|
53
|
+
* // 'abcdefg'
|
|
54
|
+
* // getRandomString(7);
|
|
55
|
+
* ```
|
|
53
56
|
*/
|
|
54
57
|
export declare function getRandomString(options?: RandomStringOptions | number): string;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
2
|
* 构建构建的构建函数
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
3
|
*/
|
|
7
4
|
export interface CreateConstructor<T, Args extends unknown[] = unknown[]> {
|
|
8
5
|
new (...args: Args): T;
|
|
9
6
|
}
|
|
10
7
|
/**
|
|
11
|
-
*
|
|
12
|
-
* 构建一个 Constructor 构造函数
|
|
8
|
+
* # 构建一个 Constructor 构造函数
|
|
13
9
|
*
|
|
14
10
|
* 接收一个构造函数,然后返回 TS 能识别的构造函数自身
|
|
15
11
|
*
|
|
@@ -19,7 +15,7 @@ export interface CreateConstructor<T, Args extends unknown[] = unknown[]> {
|
|
|
19
15
|
*
|
|
20
16
|
* @param constructor - 传入一个构造函数
|
|
21
17
|
* @returns 返回传入的构造函数
|
|
22
|
-
*
|
|
18
|
+
* @example
|
|
23
19
|
* ```ts
|
|
24
20
|
* import { createConstructor } from "a-js-tools";
|
|
25
21
|
*
|
|
@@ -40,9 +36,7 @@ export interface CreateConstructor<T, Args extends unknown[] = unknown[]> {
|
|
|
40
36
|
* const tomConstructor = createConstructor(_tom);
|
|
41
37
|
*
|
|
42
38
|
* const b = new tomConstructor(); // 这时就不会显示错误
|
|
43
|
-
*
|
|
44
39
|
* ```
|
|
45
|
-
*
|
|
46
40
|
*/
|
|
47
41
|
export declare function createConstructor<T, Args extends unknown[] = unknown[]>(constructor: (...argumentList: Args) => T): CreateConstructor<T, Args>;
|
|
48
42
|
/** 对象的 assign 用法 */
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 防抖和节流
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
* @module @a-js-tools/performance
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
1
|
type Callback = (...args: any[]) => void;
|
|
9
2
|
/**
|
|
10
|
-
*
|
|
11
3
|
* 节流和防抖返回值类型
|
|
12
|
-
*
|
|
13
4
|
*/
|
|
14
5
|
export interface DebounceAndThrottleReturnType<F extends Callback> {
|
|
15
6
|
(...args: Parameters<F>): void;
|
|
@@ -21,7 +12,6 @@ export type debounce_throttle_options = {
|
|
|
21
12
|
this?: null | unknown;
|
|
22
13
|
} | number;
|
|
23
14
|
/**
|
|
24
|
-
*
|
|
25
15
|
* 防抖
|
|
26
16
|
*
|
|
27
17
|
* @param callback 回调函数
|
|
@@ -32,15 +22,14 @@ export type debounce_throttle_options = {
|
|
|
32
22
|
* ```ts
|
|
33
23
|
* const debounce = (callback: Function, delay = 300) => {
|
|
34
24
|
* let timer: any = null
|
|
35
|
-
* return (...args: any[]) => {
|
|
36
|
-
* clearTimeout(timer)
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
25
|
*
|
|
26
|
+
* return (...args: any[]) => clearTimeout(timer)
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
40
29
|
*/
|
|
41
30
|
export declare function debounce<F extends Callback>(callback: F, options?: debounce_throttle_options): DebounceAndThrottleReturnType<F>;
|
|
42
31
|
/**
|
|
43
|
-
*
|
|
32
|
+
* 节流
|
|
44
33
|
*
|
|
45
34
|
* @param callback 回调函数
|
|
46
35
|
* @param options 延迟时间(毫秒),默认 200 (ms) 或设置 this
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { autoEscapedRegExpOptions } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* ## 适用于简单的文本字符串自动转化为简单模式正则表达式
|
|
3
|
+
* ## 适用于简单的文本字符串自动转化为简单模式正则表达式
|
|
5
4
|
*
|
|
6
5
|
* *若字符串包含且需保留字符类、组、反向引用、量词等时,该方法可能不适用*
|
|
7
6
|
*
|
|
@@ -9,7 +8,6 @@ import { autoEscapedRegExpOptions } from './types';
|
|
|
9
8
|
* @param options 转化选项。 为文本字符串时,默认为正则表达式的标志,还可指定是否匹配开头或结尾
|
|
10
9
|
* @returns 正则表达式
|
|
11
10
|
* @example
|
|
12
|
-
*
|
|
13
11
|
* ```ts
|
|
14
12
|
* import { autoEscapedRegExp } from 'a-regexp';
|
|
15
13
|
*
|
|
@@ -25,8 +23,6 @@ import { autoEscapedRegExpOptions } from './types';
|
|
|
25
23
|
* autoEscapedRegExp('a-zA-Z0-9', 'g'); // => /a-zA-Z0-9/g
|
|
26
24
|
* autoEscapedRegExp('[a-zA-Z0-9]'); // => /\[a-zA-Z0-9\]/
|
|
27
25
|
* autoEscapedRegExp('^[a-zA-Z0-9]+$'); // => /\^\[a-zA-Z0-9\]\$/
|
|
28
|
-
*
|
|
29
26
|
* ```
|
|
30
|
-
*
|
|
31
27
|
*/
|
|
32
28
|
export declare function autoEscapedRegExp(pattern: string, options?: string | autoEscapedRegExpOptions): RegExp;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # 将一个字符串转化为符合正则要求的字符串
|
|
3
|
+
*
|
|
4
|
+
* @param str 需要转义的字符串
|
|
5
|
+
* @requires escapeRegExp 转化后字符串
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { escapeRegExp } from 'a-js-tools';
|
|
9
|
+
*
|
|
10
|
+
* escapeRegExp('a.b.c'); // 'a\\.b\\.c'
|
|
11
|
+
* escapeRegExp('a\\.b\\.c'); // 'a\\\\.b\\\\.c'
|
|
12
|
+
* escapeRegExp('[a-z]'); // '\\[a-z\\]'
|
|
13
|
+
* escapeRegExp('^abc$'); // '\\^abc\\$'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function escapeRegExp(str: string): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
2
|
* ## 线程休息
|
|
4
3
|
*
|
|
5
4
|
* 但从调用到执行完毕总是与期望的时间并不相吻合,除非执行是线型的(也不保证时间的严格性)
|
|
@@ -19,8 +18,6 @@
|
|
|
19
18
|
* console.log(Date.now()); // 1748058118471
|
|
20
19
|
* await sleep(1000);
|
|
21
20
|
* console.log(Date.now()); // 1748058119473
|
|
22
|
-
*
|
|
23
21
|
* ```
|
|
24
|
-
*
|
|
25
22
|
*/
|
|
26
23
|
export declare function sleep(delay?: number): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"name": "a-js-tools",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"a-type-of-js": "^2.0.
|
|
7
|
+
"a-type-of-js": "^2.0.1"
|
|
8
8
|
},
|
|
9
9
|
"main": "cjs/index.js",
|
|
10
10
|
"module": "es/index.js",
|
|
11
|
-
"types": "es/index.d.ts",
|
|
11
|
+
"types": "es/types/index.d.ts",
|
|
12
12
|
"author": {
|
|
13
13
|
"name": "泥豆君",
|
|
14
14
|
"email": "Mr.MudBean@outlook.com",
|
|
15
|
-
"url": "https://
|
|
15
|
+
"url": "https://lmssee.com"
|
|
16
16
|
},
|
|
17
17
|
"description": "一点点 🤏 js 函数",
|
|
18
18
|
"sideEffects": false,
|
|
@@ -30,67 +30,61 @@
|
|
|
30
30
|
"import": "./es/index.js",
|
|
31
31
|
"default": "./es/index.js",
|
|
32
32
|
"require": "./cjs/index.js",
|
|
33
|
-
"types": "./es/index.d.ts"
|
|
33
|
+
"types": "./es/types/index.d.ts"
|
|
34
34
|
},
|
|
35
35
|
"./array": {
|
|
36
36
|
"default": "./es/array/index.js",
|
|
37
37
|
"import": "./es/array/index.js",
|
|
38
38
|
"require": "./cjs/array/index.js",
|
|
39
|
-
"types": "./es/
|
|
39
|
+
"types": "./es/types/array/index.d.ts"
|
|
40
40
|
},
|
|
41
41
|
"./className": {
|
|
42
42
|
"default": "./es/className.js",
|
|
43
43
|
"import": "./es/className.js",
|
|
44
44
|
"require": "./cjs/className.js",
|
|
45
|
-
"types": "./es/
|
|
45
|
+
"types": "./es/types/className.d.ts"
|
|
46
46
|
},
|
|
47
47
|
"./getRandomNumber": {
|
|
48
48
|
"default": "./es/getRandomNumber.js",
|
|
49
49
|
"import": "./es/getRandomNumber.js",
|
|
50
50
|
"require": "./cjs/getRandomNumber.js",
|
|
51
|
-
"types": "./es/
|
|
51
|
+
"types": "./es/types/getRandomNumber.d.ts"
|
|
52
52
|
},
|
|
53
53
|
"./getRandomString": {
|
|
54
54
|
"default": "./es/getRandomString.js",
|
|
55
55
|
"import": "./es/getRandomString.js",
|
|
56
56
|
"require": "./cjs/getRandomString.js",
|
|
57
|
-
"types": "./es/
|
|
58
|
-
},
|
|
59
|
-
"./index": {
|
|
60
|
-
"default": "./es/index.js",
|
|
61
|
-
"import": "./es/index.js",
|
|
62
|
-
"require": "./cjs/index.js",
|
|
63
|
-
"types": "./es/src/index.d.ts"
|
|
57
|
+
"types": "./es/types/getRandomString.d.ts"
|
|
64
58
|
},
|
|
65
59
|
"./isNode": {
|
|
66
60
|
"default": "./es/isNode.js",
|
|
67
61
|
"import": "./es/isNode.js",
|
|
68
62
|
"require": "./cjs/isNode.js",
|
|
69
|
-
"types": "./es/
|
|
63
|
+
"types": "./es/types/isNode.d.ts"
|
|
70
64
|
},
|
|
71
65
|
"./object": {
|
|
72
66
|
"default": "./es/object/index.js",
|
|
73
67
|
"import": "./es/object/index.js",
|
|
74
68
|
"require": "./cjs/object/index.js",
|
|
75
|
-
"types": "./es/
|
|
69
|
+
"types": "./es/types/object/index.d.ts"
|
|
76
70
|
},
|
|
77
71
|
"./performance": {
|
|
78
72
|
"default": "./es/performance.js",
|
|
79
73
|
"import": "./es/performance.js",
|
|
80
74
|
"require": "./cjs/performance.js",
|
|
81
|
-
"types": "./es/
|
|
75
|
+
"types": "./es/types/performance.d.ts"
|
|
82
76
|
},
|
|
83
77
|
"./regexp": {
|
|
84
78
|
"default": "./es/regexp/index.js",
|
|
85
79
|
"import": "./es/regexp/index.js",
|
|
86
80
|
"require": "./cjs/regexp/index.js",
|
|
87
|
-
"types": "./es/
|
|
81
|
+
"types": "./es/types/regexp/index.d.ts"
|
|
88
82
|
},
|
|
89
83
|
"./sleep": {
|
|
90
84
|
"default": "./es/sleep.js",
|
|
91
85
|
"import": "./es/sleep.js",
|
|
92
86
|
"require": "./cjs/sleep.js",
|
|
93
|
-
"types": "./es/
|
|
87
|
+
"types": "./es/types/sleep.d.ts"
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
90
|
"repository": {
|
|
@@ -99,11 +93,9 @@
|
|
|
99
93
|
},
|
|
100
94
|
"keywords": [
|
|
101
95
|
"a-js-tools",
|
|
102
|
-
"
|
|
103
|
-
"earthnut",
|
|
104
|
-
"js tools"
|
|
96
|
+
"js 工具"
|
|
105
97
|
],
|
|
106
|
-
"homepage": "https://
|
|
98
|
+
"homepage": "https://lmssee.com/npm/a-js-tools",
|
|
107
99
|
"bugs": {
|
|
108
100
|
"url": "https://github.com/MrMudBean/a-js-tools/issues",
|
|
109
101
|
"email": "Mr.MudBean@outlook.com"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* 将一个字符串转化为符合正则要求的字符串
|
|
4
|
-
*
|
|
5
|
-
* @param str 需要转义的字符串
|
|
6
|
-
* @requires escapeRegExp 转化后字符串
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { escapeRegExp } from 'a-js-tools';
|
|
11
|
-
*
|
|
12
|
-
* escapeRegExp('a.b.c'); // 'a\\.b\\.c'
|
|
13
|
-
* escapeRegExp('a\\.b\\.c'); // 'a\\\\.b\\\\.c'
|
|
14
|
-
* escapeRegExp('[a-z]'); // '\\[a-z\\]'
|
|
15
|
-
* escapeRegExp('^abc$'); // '\\^abc\\$'
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function escapeRegExp(str: string): string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|