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.
Files changed (52) hide show
  1. package/README.md +0 -4
  2. package/cjs/array/difference.js +1 -4
  3. package/cjs/array/index.js +9 -30
  4. package/cjs/array/intersection.js +1 -6
  5. package/cjs/array/symmetricDifference.js +1 -7
  6. package/cjs/className.js +0 -4
  7. package/cjs/getRandomNumber.js +3 -9
  8. package/cjs/getRandomString.js +19 -19
  9. package/cjs/index.js +4 -4
  10. package/cjs/isNode.js +0 -4
  11. package/cjs/object/createConstructor.js +2 -5
  12. package/cjs/performance.js +8 -16
  13. package/cjs/regexp/autoEscapedRegExp.js +1 -5
  14. package/cjs/regexp/escapeRegExp.js +6 -8
  15. package/cjs/regexp/parse.js +0 -2
  16. package/cjs/sleep.js +3 -6
  17. package/es/array/difference.js +1 -4
  18. package/es/array/index.js +9 -30
  19. package/es/array/intersection.js +1 -6
  20. package/es/array/symmetricDifference.js +1 -7
  21. package/es/className.js +0 -4
  22. package/es/getRandomNumber.js +3 -9
  23. package/es/getRandomString.js +19 -19
  24. package/es/index.js +2 -2
  25. package/es/isNode.js +0 -4
  26. package/es/object/createConstructor.js +2 -5
  27. package/es/performance.js +5 -13
  28. package/es/regexp/autoEscapedRegExp.js +1 -5
  29. package/es/regexp/escapeRegExp.js +6 -8
  30. package/es/regexp/parse.js +0 -2
  31. package/es/sleep.js +2 -5
  32. package/es/{src → types}/array/difference.d.ts +1 -4
  33. package/es/{src → types}/array/index.d.ts +9 -30
  34. package/es/{src → types}/array/intersection.d.ts +1 -6
  35. package/es/{src → types}/array/symmetricDifference.d.ts +1 -7
  36. package/es/{src → types}/className.d.ts +0 -4
  37. package/es/{src → types}/getRandomNumber.d.ts +2 -4
  38. package/es/{src → types}/getRandomString.d.ts +11 -8
  39. package/es/{src → types}/isNode.d.ts +0 -4
  40. package/es/{src → types}/object/createConstructor.d.ts +2 -8
  41. package/es/{src → types}/performance.d.ts +4 -15
  42. package/es/{src → types}/regexp/autoEscapedRegExp.d.ts +1 -5
  43. package/es/types/regexp/escapeRegExp.d.ts +16 -0
  44. package/es/{src → types}/regexp/parse.d.ts +0 -2
  45. package/es/{src → types}/regexp/types.d.ts +0 -5
  46. package/es/{src → types}/sleep.d.ts +0 -3
  47. package/package.json +16 -24
  48. package/es/src/regexp/escapeRegExp.d.ts +0 -18
  49. /package/es/{src → types}/array/union.d.ts +0 -0
  50. /package/es/{src → types}/index.d.ts +0 -0
  51. /package/es/{src → types}/object/index.d.ts +0 -0
  52. /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
- * @param options - 字符串长度
50
- * @returns - 随机字符串
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,12 +1,8 @@
1
1
  /**
2
- *
3
2
  * 判断当前环境是否为 node 环境
4
- *
5
3
  */
6
4
  export declare function isNode(): boolean;
7
5
  /**
8
- *
9
6
  * 是否为浏览器环境
10
- *
11
7
  */
12
8
  export declare function isBrowser(): boolean;
@@ -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,7 +1,5 @@
1
1
  import { autoEscapedRegExpOptions } from './types';
2
2
  /**
3
- *
4
3
  * 解析 options
5
- *
6
4
  */
7
5
  export declare function parse(options: string | autoEscapedRegExpOptions): autoEscapedRegExpOptions;
@@ -1,14 +1,9 @@
1
1
  export interface autoEscapedRegExpOptions {
2
2
  /**
3
- *
4
- *
5
- *
6
3
  */
7
4
  flags?: string;
8
5
  /**
9
- *
10
6
  * 匹配开头
11
- *
12
7
  */
13
8
  start?: boolean;
14
9
  end?: boolean;
@@ -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.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.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://earthnut.dev"
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/src/array/index.d.ts"
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/src/className.d.ts"
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/src/getRandomNumber.d.ts"
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/src/getRandomString.d.ts"
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/src/isNode.d.ts"
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/src/object/index.d.ts"
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/src/performance.d.ts"
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/src/regexp/index.d.ts"
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/src/sleep.d.ts"
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
- "Mr.MudBean",
103
- "earthnut",
104
- "js tools"
96
+ "js 工具"
105
97
  ],
106
- "homepage": "https://earthnut.dev/npm/a-js-tools",
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