a-js-tools 2.0.1 → 2.0.3

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 (60) hide show
  1. package/README.md +5 -8
  2. package/{cjs/array/difference.js → array/difference.cjs.js} +1 -4
  3. package/{es/src/array → array}/difference.d.ts +1 -4
  4. package/{es/array/difference.js → array/difference.es.js} +1 -4
  5. package/{cjs/array/index.js → array/index.cjs.js} +13 -34
  6. package/{es/src/array → array}/index.d.ts +9 -30
  7. package/{es/array/index.js → array/index.es.js} +13 -34
  8. package/{cjs/array/intersection.js → array/intersection.cjs.js} +1 -6
  9. package/{es/src/array → array}/intersection.d.ts +1 -6
  10. package/{es/array/intersection.js → array/intersection.es.js} +1 -6
  11. package/{cjs/array/symmetricDifference.js → array/symmetricDifference.cjs.js} +2 -8
  12. package/{es/src/array → array}/symmetricDifference.d.ts +1 -7
  13. package/{es/array/symmetricDifference.js → array/symmetricDifference.es.js} +2 -8
  14. package/{cjs/className.js → className.cjs.js} +0 -4
  15. package/{es/src/className.d.ts → className.d.ts} +0 -4
  16. package/{es/className.js → className.es.js} +0 -4
  17. package/createBezier.cjs.js +136 -0
  18. package/createBezier.d.ts +65 -0
  19. package/createBezier.es.js +134 -0
  20. package/{cjs/getRandomNumber.js → getRandomNumber.cjs.js} +3 -9
  21. package/{es/src/getRandomNumber.d.ts → getRandomNumber.d.ts} +2 -4
  22. package/{es/getRandomNumber.js → getRandomNumber.es.js} +3 -9
  23. package/{cjs/getRandomString.js → getRandomString.cjs.js} +21 -21
  24. package/{es/src/getRandomString.d.ts → getRandomString.d.ts} +11 -8
  25. package/{es/getRandomString.js → getRandomString.es.js} +21 -21
  26. package/{cjs/index.js → index.cjs.js} +18 -16
  27. package/{es/src/index.d.ts → index.d.ts} +1 -0
  28. package/index.es.js +15 -0
  29. package/{cjs/isNode.js → isNode.cjs.js} +0 -4
  30. package/{es/src/isNode.d.ts → isNode.d.ts} +0 -4
  31. package/{es/isNode.js → isNode.es.js} +0 -4
  32. package/{cjs/object/createConstructor.js → object/createConstructor.cjs.js} +2 -5
  33. package/{es/src/object → object}/createConstructor.d.ts +2 -8
  34. package/{es/object/createConstructor.js → object/createConstructor.es.js} +2 -5
  35. package/package.json +80 -51
  36. package/{cjs/performance.js → performance.cjs.js} +8 -16
  37. package/{es/src/performance.d.ts → performance.d.ts} +4 -15
  38. package/{es/performance.js → performance.es.js} +5 -13
  39. package/{cjs/regexp/autoEscapedRegExp.js → regexp/autoEscapedRegExp.cjs.js} +3 -7
  40. package/{es/src/regexp → regexp}/autoEscapedRegExp.d.ts +1 -5
  41. package/{es/regexp/autoEscapedRegExp.js → regexp/autoEscapedRegExp.es.js} +3 -7
  42. package/regexp/escapeRegExp.cjs.js +22 -0
  43. package/regexp/escapeRegExp.d.ts +16 -0
  44. package/regexp/escapeRegExp.es.js +20 -0
  45. package/{cjs/regexp/parse.js → regexp/parse.cjs.js} +0 -2
  46. package/{es/src/regexp → regexp}/parse.d.ts +0 -2
  47. package/{es/regexp/parse.js → regexp/parse.es.js} +0 -2
  48. package/{es/src/regexp → regexp}/types.d.ts +0 -5
  49. package/{cjs/sleep.js → sleep.cjs.js} +3 -6
  50. package/{es/src/sleep.d.ts → sleep.d.ts} +0 -3
  51. package/{es/sleep.js → sleep.es.js} +2 -5
  52. package/cjs/regexp/escapeRegExp.js +0 -24
  53. package/es/index.js +0 -14
  54. package/es/regexp/escapeRegExp.js +0 -22
  55. package/es/src/regexp/escapeRegExp.d.ts +0 -18
  56. /package/{cjs/array/union.js → array/union.cjs.js} +0 -0
  57. /package/{es/src/array → array}/union.d.ts +0 -0
  58. /package/{es/array/union.js → array/union.es.js} +0 -0
  59. /package/{es/src/object → object}/index.d.ts +0 -0
  60. /package/{es/src/regexp → regexp}/index.d.ts +0 -0
@@ -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,9 +1,7 @@
1
1
  import { isUndefined } from 'a-type-of-js';
2
2
 
3
3
  /**
4
- *
5
4
  * 判断当前环境是否为 node 环境
6
- *
7
5
  */
8
6
  function isNode() {
9
7
  return !isUndefined((globalThis &&
@@ -13,9 +11,7 @@ function isNode() {
13
11
  undefined);
14
12
  }
15
13
  /**
16
- *
17
14
  * 是否为浏览器环境
18
- *
19
15
  */
20
16
  function isBrowser() {
21
17
  return !isNode();
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- *
5
- * 构建一个 Constructor 构造函数
4
+ * # 构建一个 Constructor 构造函数
6
5
  *
7
6
  * 接收一个构造函数,然后返回 TS 能识别的构造函数自身
8
7
  *
@@ -12,7 +11,7 @@
12
11
  *
13
12
  * @param constructor - 传入一个构造函数
14
13
  * @returns 返回传入的构造函数
15
- *
14
+ * @example
16
15
  * ```ts
17
16
  * import { createConstructor } from "a-js-tools";
18
17
  *
@@ -33,9 +32,7 @@
33
32
  * const tomConstructor = createConstructor(_tom);
34
33
  *
35
34
  * const b = new tomConstructor(); // 这时就不会显示错误
36
- *
37
35
  * ```
38
- *
39
36
  */
40
37
  function createConstructor(constructor) {
41
38
  constructor.prototype.apply = Function.apply;
@@ -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,6 +1,5 @@
1
1
  /**
2
- *
3
- * 构建一个 Constructor 构造函数
2
+ * # 构建一个 Constructor 构造函数
4
3
  *
5
4
  * 接收一个构造函数,然后返回 TS 能识别的构造函数自身
6
5
  *
@@ -10,7 +9,7 @@
10
9
  *
11
10
  * @param constructor - 传入一个构造函数
12
11
  * @returns 返回传入的构造函数
13
- *
12
+ * @example
14
13
  * ```ts
15
14
  * import { createConstructor } from "a-js-tools";
16
15
  *
@@ -31,9 +30,7 @@
31
30
  * const tomConstructor = createConstructor(_tom);
32
31
  *
33
32
  * const b = new tomConstructor(); // 这时就不会显示错误
34
- *
35
33
  * ```
36
- *
37
34
  */
38
35
  function createConstructor(constructor) {
39
36
  constructor.prototype.apply = Function.apply;
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
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/src/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,
@@ -20,71 +20,102 @@
20
20
  "node": ">=18.0.0"
21
21
  },
22
22
  "files": [
23
- "es",
24
- "cjs",
25
23
  "LICENSE",
26
- "README.md"
24
+ "README.md",
25
+ "array",
26
+ "className.cjs.js",
27
+ "className.d.ts",
28
+ "className.es.js",
29
+ "createBezier.cjs.js",
30
+ "createBezier.d.ts",
31
+ "createBezier.es.js",
32
+ "getRandomNumber.cjs.js",
33
+ "getRandomNumber.d.ts",
34
+ "getRandomNumber.es.js",
35
+ "getRandomString.cjs.js",
36
+ "getRandomString.d.ts",
37
+ "getRandomString.es.js",
38
+ "index.cjs.js",
39
+ "index.es.js",
40
+ "index.d.ts",
41
+ "isNode.cjs.js",
42
+ "isNode.d.ts",
43
+ "isNode.es.js",
44
+ "object",
45
+ "performance.cjs.js",
46
+ "performance.d.ts",
47
+ "performance.es.js",
48
+ "regexp",
49
+ "sleep.cjs.js",
50
+ "sleep.d.ts",
51
+ "sleep.es.js"
27
52
  ],
28
53
  "exports": {
29
54
  ".": {
30
- "import": "./es/index.js",
31
- "default": "./es/index.js",
32
- "require": "./cjs/index.js",
33
- "types": "./es/src/index.d.ts"
55
+ "import": "./index.es.js",
56
+ "default": "./index.es.js",
57
+ "require": "./index.es.js",
58
+ "types": "./index.d.ts"
34
59
  },
35
60
  "./array": {
36
- "default": "./es/array/index.js",
37
- "import": "./es/array/index.js",
38
- "require": "./cjs/array/index.js",
39
- "types": "./es/src/array/index.d.ts"
61
+ "default": "./array/index.es.js",
62
+ "import": "./array/index.es.js",
63
+ "require": "./array/index.cjs.js",
64
+ "types": "./array/index.d.ts"
40
65
  },
41
66
  "./className": {
42
- "default": "./es/className.js",
43
- "import": "./es/className.js",
44
- "require": "./cjs/className.js",
45
- "types": "./es/src/className.d.ts"
67
+ "default": "./className.es.js",
68
+ "import": "./className.es.js",
69
+ "require": "./className.cjs.js",
70
+ "types": "./className.d.ts"
71
+ },
72
+ "./createBezier": {
73
+ "default": "./createBezier.es.js",
74
+ "import": "./createBezier.es.js",
75
+ "require": "./createBezier.cjs.js",
76
+ "types": "./createBezier.d.ts"
46
77
  },
47
78
  "./getRandomNumber": {
48
- "default": "./es/getRandomNumber.js",
49
- "import": "./es/getRandomNumber.js",
50
- "require": "./cjs/getRandomNumber.js",
51
- "types": "./es/src/getRandomNumber.d.ts"
79
+ "default": "./getRandomNumber.es.js",
80
+ "import": "./getRandomNumber.es.js",
81
+ "require": "./getRandomNumber.cjs.js",
82
+ "types": "./getRandomNumber.d.ts"
52
83
  },
53
84
  "./getRandomString": {
54
- "default": "./es/getRandomString.js",
55
- "import": "./es/getRandomString.js",
56
- "require": "./cjs/getRandomString.js",
57
- "types": "./es/src/getRandomString.d.ts"
85
+ "default": "./getRandomString.es.js",
86
+ "import": "./getRandomString.es.js",
87
+ "require": "./getRandomString.cjs.js",
88
+ "types": "./getRandomString.d.ts"
58
89
  },
59
90
  "./isNode": {
60
- "default": "./es/isNode.js",
61
- "import": "./es/isNode.js",
62
- "require": "./cjs/isNode.js",
63
- "types": "./es/src/isNode.d.ts"
91
+ "default": "./isNode.es.js",
92
+ "import": "./isNode.es.js",
93
+ "require": "./isNode.cjs.js",
94
+ "types": "./isNode.d.ts"
64
95
  },
65
96
  "./object": {
66
- "default": "./es/object/index.js",
67
- "import": "./es/object/index.js",
68
- "require": "./cjs/object/index.js",
69
- "types": "./es/src/object/index.d.ts"
97
+ "default": "./object/index.es.js",
98
+ "import": "./object/index.es.js",
99
+ "require": "./object/index.cjs.js",
100
+ "types": "./object/index.d.ts"
70
101
  },
71
102
  "./performance": {
72
- "default": "./es/performance.js",
73
- "import": "./es/performance.js",
74
- "require": "./cjs/performance.js",
75
- "types": "./es/src/performance.d.ts"
103
+ "default": "./performance.es.js",
104
+ "import": "./performance.es.js",
105
+ "require": "./performance.cjs.js",
106
+ "types": "./performance.d.ts"
76
107
  },
77
108
  "./regexp": {
78
- "default": "./es/regexp/index.js",
79
- "import": "./es/regexp/index.js",
80
- "require": "./cjs/regexp/index.js",
81
- "types": "./es/src/regexp/index.d.ts"
109
+ "default": "./regexp/index.es.js",
110
+ "import": "./regexp/index.es.js",
111
+ "require": "./regexp/index.cjs.js",
112
+ "types": "./regexp/index.d.ts"
82
113
  },
83
114
  "./sleep": {
84
- "default": "./es/sleep.js",
85
- "import": "./es/sleep.js",
86
- "require": "./cjs/sleep.js",
87
- "types": "./es/src/sleep.d.ts"
115
+ "default": "./sleep.es.js",
116
+ "import": "./sleep.es.js",
117
+ "require": "./sleep.cjs.js",
118
+ "types": "./sleep.d.ts"
88
119
  }
89
120
  },
90
121
  "repository": {
@@ -93,11 +124,9 @@
93
124
  },
94
125
  "keywords": [
95
126
  "a-js-tools",
96
- "Mr.MudBean",
97
- "earthnut",
98
- "js tools"
127
+ "js 工具"
99
128
  ],
100
- "homepage": "https://earthnut.dev/npm/a-js-tools",
129
+ "homepage": "https://lmssee.com/npm/a-js-tools",
101
130
  "bugs": {
102
131
  "url": "https://github.com/MrMudBean/a-js-tools/issues",
103
132
  "email": "Mr.MudBean@outlook.com"
@@ -1,18 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var aTypeOfJs = require('a-type-of-js');
4
- var isFunction = require('a-type-of-js/isFunction');
5
- var isNumber = require('a-type-of-js/isNumber');
6
4
 
7
5
  /**
8
6
  * 防抖和节流
9
- *
10
- * @packageDocumentation
11
- * @module @a-js-tools/performance
12
- * @license MIT
13
7
  */
14
8
  /**
15
- *
16
9
  * 防抖
17
10
  *
18
11
  * @param callback 回调函数
@@ -23,16 +16,15 @@ var isNumber = require('a-type-of-js/isNumber');
23
16
  * ```ts
24
17
  * const debounce = (callback: Function, delay = 300) => {
25
18
  * let timer: any = null
26
- * return (...args: any[]) => {
27
- * clearTimeout(timer)
28
- * }
29
- * }
30
19
  *
20
+ * return (...args: any[]) => clearTimeout(timer)
21
+ * }
22
+ * ```
31
23
  */
32
24
  function debounce(callback, options = 200) {
33
- if (!isFunction.isFunction(callback))
25
+ if (!aTypeOfJs.isFunction(callback))
34
26
  throw new TypeError('callback must be a function');
35
- if (isNumber.isNumber(options))
27
+ if (aTypeOfJs.isNumber(options))
36
28
  options = {
37
29
  delay: options,
38
30
  this: null,
@@ -68,16 +60,16 @@ function debounce(callback, options = 200) {
68
60
  return result;
69
61
  }
70
62
  /**
71
- * 节流
63
+ * 节流
72
64
  *
73
65
  * @param callback 回调函数
74
66
  * @param options 延迟时间(毫秒),默认 200 (ms) 或设置 this
75
67
  * @returns 返回的闭包函数
76
68
  */
77
69
  function throttle(callback, options = 200) {
78
- if (!isFunction.isFunction(callback))
70
+ if (!aTypeOfJs.isFunction(callback))
79
71
  throw new TypeError('callback must be a function');
80
- if (isNumber.isNumber(options))
72
+ if (aTypeOfJs.isNumber(options))
81
73
  options = {
82
74
  delay: options,
83
75
  this: null,
@@ -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,16 +1,9 @@
1
- import { isUndefined, isNull } from 'a-type-of-js';
2
- import { isFunction } from 'a-type-of-js/isFunction';
3
- import { isNumber } from 'a-type-of-js/isNumber';
1
+ import { isFunction, isNumber, isUndefined, isNull } from 'a-type-of-js';
4
2
 
5
3
  /**
6
4
  * 防抖和节流
7
- *
8
- * @packageDocumentation
9
- * @module @a-js-tools/performance
10
- * @license MIT
11
5
  */
12
6
  /**
13
- *
14
7
  * 防抖
15
8
  *
16
9
  * @param callback 回调函数
@@ -21,11 +14,10 @@ import { isNumber } from 'a-type-of-js/isNumber';
21
14
  * ```ts
22
15
  * const debounce = (callback: Function, delay = 300) => {
23
16
  * let timer: any = null
24
- * return (...args: any[]) => {
25
- * clearTimeout(timer)
26
- * }
27
- * }
28
17
  *
18
+ * return (...args: any[]) => clearTimeout(timer)
19
+ * }
20
+ * ```
29
21
  */
30
22
  function debounce(callback, options = 200) {
31
23
  if (!isFunction(callback))
@@ -66,7 +58,7 @@ function debounce(callback, options = 200) {
66
58
  return result;
67
59
  }
68
60
  /**
69
- * 节流
61
+ * 节流
70
62
  *
71
63
  * @param callback 回调函数
72
64
  * @param options 延迟时间(毫秒),默认 200 (ms) 或设置 this
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var aTypeOfJs = require('a-type-of-js');
4
- var escapeRegExp = require('./escapeRegExp.js');
5
- var parse = require('./parse.js');
4
+ var escapeRegExp = require('./escapeRegExp.cjs.js');
5
+ var parse = require('./parse.cjs.js');
6
6
 
7
7
  /**
8
- *
9
- * ## 适用于简单的文本字符串自动转化为简单模式正则表达式
8
+ * ## 适用于简单的文本字符串自动转化为简单模式正则表达式
10
9
  *
11
10
  * *若字符串包含且需保留字符类、组、反向引用、量词等时,该方法可能不适用*
12
11
  *
@@ -14,7 +13,6 @@ var parse = require('./parse.js');
14
13
  * @param options 转化选项。 为文本字符串时,默认为正则表达式的标志,还可指定是否匹配开头或结尾
15
14
  * @returns 正则表达式
16
15
  * @example
17
- *
18
16
  * ```ts
19
17
  * import { autoEscapedRegExp } from 'a-regexp';
20
18
  *
@@ -30,9 +28,7 @@ var parse = require('./parse.js');
30
28
  * autoEscapedRegExp('a-zA-Z0-9', 'g'); // => /a-zA-Z0-9/g
31
29
  * autoEscapedRegExp('[a-zA-Z0-9]'); // => /\[a-zA-Z0-9\]/
32
30
  * autoEscapedRegExp('^[a-zA-Z0-9]+$'); // => /\^\[a-zA-Z0-9\]\$/
33
- *
34
31
  * ```
35
- *
36
32
  */
37
33
  function autoEscapedRegExp(pattern, options) {
38
34
  if (!aTypeOfJs.isString(pattern))
@@ -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;
@@ -1,10 +1,9 @@
1
1
  import { isString, isUndefined } from 'a-type-of-js';
2
- import { escapeRegExp } from './escapeRegExp.js';
3
- import { parse } from './parse.js';
2
+ import { escapeRegExp } from './escapeRegExp.es.js';
3
+ import { parse } from './parse.es.js';
4
4
 
5
5
  /**
6
- *
7
- * ## 适用于简单的文本字符串自动转化为简单模式正则表达式
6
+ * ## 适用于简单的文本字符串自动转化为简单模式正则表达式
8
7
  *
9
8
  * *若字符串包含且需保留字符类、组、反向引用、量词等时,该方法可能不适用*
10
9
  *
@@ -12,7 +11,6 @@ import { parse } from './parse.js';
12
11
  * @param options 转化选项。 为文本字符串时,默认为正则表达式的标志,还可指定是否匹配开头或结尾
13
12
  * @returns 正则表达式
14
13
  * @example
15
- *
16
14
  * ```ts
17
15
  * import { autoEscapedRegExp } from 'a-regexp';
18
16
  *
@@ -28,9 +26,7 @@ import { parse } from './parse.js';
28
26
  * autoEscapedRegExp('a-zA-Z0-9', 'g'); // => /a-zA-Z0-9/g
29
27
  * autoEscapedRegExp('[a-zA-Z0-9]'); // => /\[a-zA-Z0-9\]/
30
28
  * autoEscapedRegExp('^[a-zA-Z0-9]+$'); // => /\^\[a-zA-Z0-9\]\$/
31
- *
32
29
  * ```
33
- *
34
30
  */
35
31
  function autoEscapedRegExp(pattern, options) {
36
32
  if (!isString(pattern))
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * # 将一个字符串转化为符合正则要求的字符串
5
+ *
6
+ * @param str 需要转义的字符串
7
+ * @requires escapeRegExp 转化后字符串
8
+ * @example
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
+ function escapeRegExp(str) {
19
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
20
+ }
21
+
22
+ exports.escapeRegExp = escapeRegExp;
@@ -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;
@@ -0,0 +1,20 @@
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
+ function escapeRegExp(str) {
17
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
18
+ }
19
+
20
+ export { escapeRegExp };
@@ -3,9 +3,7 @@
3
3
  var aTypeOfJs = require('a-type-of-js');
4
4
 
5
5
  /**
6
- *
7
6
  * 解析 options
8
- *
9
7
  */
10
8
  function parse(options) {
11
9
  // 处理 options
@@ -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,9 +1,7 @@
1
1
  import { isString, isNull } from 'a-type-of-js';
2
2
 
3
3
  /**
4
- *
5
4
  * 解析 options
6
- *
7
5
  */
8
6
  function parse(options) {
9
7
  // 处理 options
@@ -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;