a-js-tools 2.0.0-alpha.0 → 2.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.
Files changed (58) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +4 -4
  3. package/{src/array/difference.cjs → cjs/array/difference.js} +4 -2
  4. package/{src/array/index.cjs → cjs/array/index.js} +4 -4
  5. package/{src/array/intersection.cjs → cjs/array/intersection.js} +4 -2
  6. package/{src/array/symmetricDifference.cjs → cjs/array/symmetricDifference.js} +1 -1
  7. package/{src/className.cjs → cjs/className.js} +3 -3
  8. package/{src/getRandomNumber.cjs → cjs/getRandomNumber.js} +5 -5
  9. package/{src/getRandomString.cjs → cjs/getRandomString.js} +32 -24
  10. package/{index.cjs → cjs/index.js} +17 -16
  11. package/{src/isNode.cjs → cjs/isNode.js} +5 -1
  12. package/{src/object/createConstructor.cjs → cjs/object/createConstructor.js} +14 -0
  13. package/{src/performance.cjs → cjs/performance.js} +34 -32
  14. package/{src/regexp/autoEscapedRegExp.cjs → cjs/regexp/autoEscapedRegExp.js} +4 -6
  15. package/{src/regexp/parse.cjs → cjs/regexp/parse.js} +3 -6
  16. package/{src/sleep.cjs → cjs/sleep.js} +2 -2
  17. package/{src/array/difference.mjs → es/array/difference.js} +4 -2
  18. package/{src/array/index.mjs → es/array/index.js} +4 -4
  19. package/{src/array/intersection.mjs → es/array/intersection.js} +4 -2
  20. package/{src/array/symmetricDifference.mjs → es/array/symmetricDifference.js} +1 -1
  21. package/{src/className.mjs → es/className.js} +3 -3
  22. package/{src/getRandomNumber.mjs → es/getRandomNumber.js} +5 -5
  23. package/{src/getRandomString.mjs → es/getRandomString.js} +32 -24
  24. package/es/index.js +14 -0
  25. package/{src/isNode.mjs → es/isNode.js} +5 -1
  26. package/{src/object/createConstructor.mjs → es/object/createConstructor.js} +14 -1
  27. package/{src/performance.mjs → es/performance.js} +35 -33
  28. package/{src/regexp/autoEscapedRegExp.mjs → es/regexp/autoEscapedRegExp.js} +4 -6
  29. package/{src/regexp/parse.mjs → es/regexp/parse.js} +3 -6
  30. package/{src/sleep.mjs → es/sleep.js} +1 -1
  31. package/{src → es/src}/getRandomNumber.d.ts +1 -1
  32. package/es/src/index.d.ts +11 -0
  33. package/{src → es/src}/object/createConstructor.d.ts +2 -0
  34. package/es/src/object/index.d.ts +2 -0
  35. package/es/src/performance.d.ts +50 -0
  36. package/package.json +86 -26
  37. package/index.d.ts +0 -10
  38. package/index.mjs +0 -14
  39. package/src/index.d.ts +0 -3
  40. package/src/performance.d.ts +0 -52
  41. /package/{src/array/union.cjs → cjs/array/union.js} +0 -0
  42. /package/{src/regexp/escapeRegExp.cjs → cjs/regexp/escapeRegExp.js} +0 -0
  43. /package/{src/array/union.mjs → es/array/union.js} +0 -0
  44. /package/{src/regexp/escapeRegExp.mjs → es/regexp/escapeRegExp.js} +0 -0
  45. /package/{src → es/src}/array/difference.d.ts +0 -0
  46. /package/{src → es/src}/array/index.d.ts +0 -0
  47. /package/{src → es/src}/array/intersection.d.ts +0 -0
  48. /package/{src → es/src}/array/symmetricDifference.d.ts +0 -0
  49. /package/{src → es/src}/array/union.d.ts +0 -0
  50. /package/{src → es/src}/className.d.ts +0 -0
  51. /package/{src → es/src}/getRandomString.d.ts +0 -0
  52. /package/{src → es/src}/isNode.d.ts +0 -0
  53. /package/{src → es/src}/regexp/autoEscapedRegExp.d.ts +0 -0
  54. /package/{src → es/src}/regexp/escapeRegExp.d.ts +0 -0
  55. /package/{src → es/src}/regexp/index.d.ts +0 -0
  56. /package/{src → es/src}/regexp/parse.d.ts +0 -0
  57. /package/{src → es/src}/regexp/types.d.ts +0 -0
  58. /package/{src → es/src}/sleep.d.ts +0 -0
@@ -1,5 +1,6 @@
1
1
  import { isPlainObject, isNumber, isNaN, isUndefined } from 'a-type-of-js';
2
- import { isBrowser } from './isNode.mjs';
2
+ import { ObjectAssign } from './object/createConstructor.js';
3
+ import { getRandomInt } from './getRandomNumber.js';
3
4
 
4
5
  /**
5
6
  * 获取随机字符串
@@ -36,9 +37,8 @@ function getRandomString(options) {
36
37
  (isPlainObject(options) &&
37
38
  (!isNumber(options.length) ||
38
39
  options.length < 1 ||
39
- !Number.isInteger(options.length)))) {
40
+ !Number.isInteger(options.length))))
40
41
  throw new TypeError('参数类型错误 ❌ (getRandomString)');
41
- }
42
42
  const initOptions = {
43
43
  length: 32,
44
44
  chars: 'abcdefghijklmnopqrstuvwxyz',
@@ -50,40 +50,43 @@ function getRandomString(options) {
50
50
  includeSpecial: false,
51
51
  };
52
52
  /// 生成 UUID
53
- if (initOptions.type === 'uuid') {
53
+ if (initOptions.type === 'uuid')
54
54
  return crypto.randomUUID();
55
- }
56
- if (isNumber(options) && Number.isInteger(options) && options > 0) {
57
- // 验证输入参数
58
- Object.assign(initOptions, { length: options });
59
- }
55
+ // 验证输入参数
56
+ if (isNumber(options) && Number.isInteger(options) && options > 0)
57
+ ObjectAssign(initOptions, { length: options });
60
58
  if (isPlainObject(options)) {
61
- Object.assign(initOptions, options);
59
+ ObjectAssign(initOptions, options);
62
60
  initOptions.length = initOptions.length < 1 ? 32 : initOptions.length;
63
61
  }
64
62
  /** 生成随机字符串 */
65
63
  const templateCharsArr = initOptions.chars.split('');
66
64
  // 添加大写字母
67
- if (initOptions.includeUppercaseLetters) {
65
+ if (initOptions.includeUppercaseLetters)
68
66
  interleaveString(templateCharsArr, initOptions.chars.toUpperCase());
69
- }
70
67
  // 添加数字
71
- if (initOptions.includeNumbers) {
68
+ if (initOptions.includeNumbers)
72
69
  interleaveString(templateCharsArr, initOptions.chars2);
73
- }
74
70
  // 添加特殊字符
75
- if (initOptions.includeSpecial) {
71
+ if (initOptions.includeSpecial)
76
72
  interleaveString(templateCharsArr, initOptions.chars3);
77
- }
78
- // 使用密码学安全的随机数生成器
79
- const bytes = isBrowser() && window.crypto
80
- ? window.crypto.getRandomValues(new Uint8Array(initOptions.length))
81
- : global.crypto.getRandomValues(new Uint8Array(initOptions.length));
73
+ /** 结果字符串 */
82
74
  let result = '';
83
- /** 获取最后的 chars 数据 */
84
- const chars = templateCharsArr.join('');
85
- // 循环遍历
86
- bytes.forEach(byte => (result += chars.charAt(byte % chars.length)));
75
+ /** 混淆后的字符串 */
76
+ const str = templateCharsArr.join('');
77
+ /** 混淆后字符长度 */
78
+ const strLen = str.length;
79
+ if (globalThis && globalThis.crypto && globalThis.crypto.getRandomValues) {
80
+ // 使用密码学安全的随机数生成器
81
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
82
+ /** 获取最后的 chars 数据 */
83
+ // 循环遍历
84
+ bytes.forEach(byte => (result += str[byte % strLen]));
85
+ }
86
+ else {
87
+ for (let i = 0; i < initOptions.length; i++)
88
+ result += str[getRandomInt(strLen - 1)];
89
+ }
87
90
  /**
88
91
  *
89
92
  * 字符串交叉函数
@@ -110,6 +113,11 @@ function getRandomString(options) {
110
113
  }
111
114
  }
112
115
  }
116
+ /// 结果字符串不包含字符
117
+ if (!/[a-zA-Z]/.test(result))
118
+ return String.fromCharCode(getRandomInt(97, 122)).concat(result.slice(1));
119
+ while (!/^[a-zA-Z]$/.test(result[0]))
120
+ result = result.slice(1) + result[0];
113
121
  return result;
114
122
  }
115
123
 
package/es/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export { toLowerCamelCase, toSplitCase } from './className.js';
2
+ export { ObjectAssign, createConstructor } from './object/createConstructor.js';
3
+ export { getRandomFloat, getRandomInt } from './getRandomNumber.js';
4
+ export { getRandomString } from './getRandomString.js';
5
+ export { debounce, throttle } from './performance.js';
6
+ export { escapeRegExp } from './regexp/escapeRegExp.js';
7
+ export { autoEscapedRegExp } from './regexp/autoEscapedRegExp.js';
8
+ export { isBrowser, isNode } from './isNode.js';
9
+ export { enArr } from './array/index.js';
10
+ export { sleep } from './sleep.js';
11
+ export { intersection } from './array/intersection.js';
12
+ export { union } from './array/union.js';
13
+ export { difference } from './array/difference.js';
14
+ export { symmetricDifference } from './array/symmetricDifference.js';
@@ -6,7 +6,11 @@ import { isUndefined } from 'a-type-of-js';
6
6
  *
7
7
  */
8
8
  function isNode() {
9
- return !isUndefined(globalThis?.process?.versions?.node);
9
+ return !isUndefined((globalThis &&
10
+ globalThis.process &&
11
+ globalThis.process.versions &&
12
+ globalThis.process.versions.node) ||
13
+ undefined);
10
14
  }
11
15
  /**
12
16
  *
@@ -36,7 +36,20 @@
36
36
  *
37
37
  */
38
38
  function createConstructor(constructor) {
39
+ constructor.prototype.apply = Function.apply;
40
+ constructor.prototype.bind = Function.bind;
41
+ constructor.prototype.call = Function.call;
42
+ constructor.prototype.length = Function.length;
43
+ // constructor.prototype.arguments = Function.arguments;
44
+ constructor.prototype.name = Function.name;
45
+ constructor.prototype.toString = Function.toString;
39
46
  return constructor;
40
47
  }
48
+ /** 对象的 assign 用法 */
49
+ function ObjectAssign(target, bar) {
50
+ const keys = Object.keys(bar);
51
+ keys.forEach(key => (target[key] = bar[key]));
52
+ return target;
53
+ }
41
54
 
42
- export { createConstructor };
55
+ export { ObjectAssign, createConstructor };
@@ -1,4 +1,6 @@
1
- import { isFunction, isPlainObject, isUndefined, isNull } from 'a-type-of-js';
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';
2
4
 
3
5
  /**
4
6
  * 防抖和节流
@@ -11,7 +13,8 @@ import { isFunction, isPlainObject, isUndefined, isNull } from 'a-type-of-js';
11
13
  *
12
14
  * 防抖
13
15
  *
14
- * @param options 使用参数
16
+ * @param callback 回调函数
17
+ * @param options 延迟时间(毫秒),默认 200 (ms) 或包含 this 的配置
15
18
  * @returns 返回的闭包函数
16
19
  * @example
17
20
  *
@@ -24,19 +27,17 @@ import { isFunction, isPlainObject, isUndefined, isNull } from 'a-type-of-js';
24
27
  * }
25
28
  *
26
29
  */
27
- function debounce(options) {
28
- if (isFunction(options)) {
30
+ function debounce(callback, options = 200) {
31
+ if (!isFunction(callback))
32
+ throw new TypeError('callback must be a function');
33
+ if (isNumber(options))
29
34
  options = {
30
- callback: options,
31
- delay: 200,
35
+ delay: options,
32
36
  this: null,
33
37
  };
34
- }
35
- if (!isPlainObject(options) || !isFunction(options.callback))
36
- throw new TypeError('参数类型有误');
37
- if (isUndefined(options.delay))
38
- options.delay = 200;
39
- if (!isFinite(options.delay) || options.delay < 0)
38
+ if (isUndefined(options.delay) ||
39
+ !isFinite(options.delay) ||
40
+ options.delay < 0)
40
41
  // 强制转换非数值
41
42
  options.delay = 200;
42
43
  /** 定时器返回的 id */
@@ -51,60 +52,61 @@ function debounce(options) {
51
52
  clear();
52
53
  timeoutId = setTimeout(() => {
53
54
  try {
54
- Reflect.apply(options.callback, options.this ?? null, args);
55
+ const _this = options && options.this ? options.this : null;
56
+ // 由于 Reflect.apply 并不能在 ES5 中使用,所以我们并不能保证能执行成功
57
+ callback.apply(_this, args);
58
+ // Reflect.apply(callback, options?.this ?? null, args);
55
59
  }
56
60
  catch (error) {
57
61
  console.log('Debounce callback throw an error', error);
58
62
  }
59
- }, Math.max(options.delay ?? 5, 5));
60
- };
61
- result.cancel = () => {
62
- clear();
63
+ }, Math.max(options.delay || 5, 5));
63
64
  };
65
+ result.cancel = () => clear();
64
66
  return result;
65
67
  }
66
68
  /**
67
69
  * 节流
68
70
  *
69
- * @param options 使用的参数值
71
+ * @param callback 回调函数
72
+ * @param options 延迟时间(毫秒),默认 200 (ms) 或设置 this
70
73
  * @returns 返回的闭包函数
71
74
  */
72
- function throttle(options) {
73
- if (isFunction(options)) {
75
+ function throttle(callback, options = 200) {
76
+ if (!isFunction(callback))
77
+ throw new TypeError('callback must be a function');
78
+ if (isNumber(options))
74
79
  options = {
75
- callback: options,
76
- delay: 200,
80
+ delay: options,
77
81
  this: null,
78
82
  };
79
- }
80
- if (!isPlainObject(options) || !isFunction(options.callback))
81
- throw new TypeError('参数类型有误');
82
- if (isUndefined(options.delay))
83
- options.delay = 200;
84
- if (!isFinite(options.delay) || options.delay < 0)
83
+ if (isUndefined(options.delay) ||
84
+ !isFinite(options.delay) ||
85
+ options.delay < 0)
85
86
  // 强制转换非数值
86
87
  options.delay = 200;
87
88
  /** 延迟控制插销 */
88
89
  let inThrottle = false;
89
90
  /** 延迟控制 */
90
91
  let timeoutId = null;
92
+ const delay = options && options.delay ? options.delay : 5;
91
93
  const throttled = (...args) => {
92
94
  if (inThrottle)
93
95
  return;
94
96
  try {
95
- Reflect.apply(options.callback, options.this ?? null, args);
97
+ const _this = options && options.this ? options.this : null;
98
+ callback.apply(_this, args);
96
99
  }
97
100
  catch (error) {
98
- console.error('Throttle callback throw an error', error);
101
+ console.error('Throttle 执行回调抛出问题', error);
99
102
  }
100
103
  inThrottle = true;
101
- if (!isNull(timeoutId)) {
104
+ if (!isNull(timeoutId))
102
105
  clearTimeout(timeoutId);
103
- }
104
106
  timeoutId = setTimeout(() => {
105
107
  inThrottle = false;
106
108
  timeoutId = null;
107
- }, Math.max(options.delay ?? 5, 5));
109
+ }, Math.max(delay, 5));
108
110
  };
109
111
  throttled.cancel = () => {
110
112
  if (!isNull(timeoutId)) {
@@ -1,6 +1,6 @@
1
1
  import { isString, isUndefined } from 'a-type-of-js';
2
- import { escapeRegExp } from './escapeRegExp.mjs';
3
- import { parse } from './parse.mjs';
2
+ import { escapeRegExp } from './escapeRegExp.js';
3
+ import { parse } from './parse.js';
4
4
 
5
5
  /**
6
6
  *
@@ -33,14 +33,12 @@ import { parse } from './parse.mjs';
33
33
  *
34
34
  */
35
35
  function autoEscapedRegExp(pattern, options) {
36
- if (!isString(pattern)) {
36
+ if (!isString(pattern))
37
37
  throw new TypeError('pattern must be a 字符串');
38
- }
39
38
  pattern = escapeRegExp(pattern);
40
39
  /** 简单转化 */
41
- if (isUndefined(options)) {
40
+ if (isUndefined(options))
42
41
  return new RegExp(pattern);
43
- }
44
42
  options = parse(options);
45
43
  return new RegExp(`${options.start ? '^' : ''}${pattern}${options.end ? '$' : ''}`, options.flags);
46
44
  }
@@ -13,19 +13,16 @@ function parse(options) {
13
13
  };
14
14
  }
15
15
  // 处理 flags
16
- if (!isString(options.flags)) {
16
+ if (!isString(options.flags))
17
17
  options.flags = '';
18
- }
19
18
  else {
20
19
  // 需求是保留字符串中的某一部分,使用
21
20
  const regexp = /[migsuy]/g;
22
21
  const matchResult = options.flags.match(regexp);
23
- if (isNull(matchResult)) {
22
+ if (isNull(matchResult))
24
23
  options.flags = '';
25
- }
26
- else {
24
+ else
27
25
  options.flags = [...new Set(matchResult)].join('');
28
- }
29
26
  }
30
27
  return options;
31
28
  }
@@ -1,4 +1,4 @@
1
- import { isZero } from 'a-type-of-js';
1
+ import { isZero } from 'a-type-of-js/isNumber';
2
2
 
3
3
  /**
4
4
  *
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * 获取一个随机的整数类型
4
4
  *
5
- * 您可以传入两个参数并获取它们之间的任意数字
5
+ * 您可以传入两个参数并获取它们之间的任意数字,返回值<span style="color:#ff0;">*会包含端值*</span>
6
6
  *
7
7
  * 如果只传递一个参数,则如果提供的值为负数,则得到一个小于(或大于)该数字的整数
8
8
  *
@@ -0,0 +1,11 @@
1
+ export { toLowerCamelCase, toSplitCase } from './className';
2
+ export type { CreateConstructor } from './object/createConstructor';
3
+ export { createConstructor, ObjectAssign } from './object/createConstructor';
4
+ export { getRandomFloat, getRandomInt } from './getRandomNumber';
5
+ export { getRandomString } from './getRandomString';
6
+ export { throttle, debounce } from './performance';
7
+ export type { DebounceAndThrottleReturnType, debounce_throttle_options, } from './performance';
8
+ export { escapeRegExp, autoEscapedRegExp } from './regexp';
9
+ export { isBrowser, isNode } from './isNode';
10
+ export { intersection, enArr, union, difference, symmetricDifference, } from './array';
11
+ export { sleep } from './sleep';
@@ -45,3 +45,5 @@ export interface CreateConstructor<T, Args extends unknown[] = unknown[]> {
45
45
  *
46
46
  */
47
47
  export declare function createConstructor<T, Args extends unknown[] = unknown[]>(constructor: (...argumentList: Args) => T): CreateConstructor<T, Args>;
48
+ /** 对象的 assign 用法 */
49
+ export declare function ObjectAssign(target: Record<string, unknown>, bar: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ export type { CreateConstructor } from './createConstructor';
2
+ export { createConstructor } from './createConstructor';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 防抖和节流
3
+ *
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/performance
6
+ * @license MIT
7
+ */
8
+ type Callback = (...args: any[]) => void;
9
+ /**
10
+ *
11
+ * 节流和防抖返回值类型
12
+ *
13
+ */
14
+ export interface DebounceAndThrottleReturnType<F extends Callback> {
15
+ (...args: Parameters<F>): void;
16
+ cancel(): void;
17
+ }
18
+ /** 第二参数 */
19
+ export type debounce_throttle_options = {
20
+ delay?: number;
21
+ this?: null | unknown;
22
+ } | number;
23
+ /**
24
+ *
25
+ * 防抖
26
+ *
27
+ * @param callback 回调函数
28
+ * @param options 延迟时间(毫秒),默认 200 (ms) 或包含 this 的配置
29
+ * @returns 返回的闭包函数
30
+ * @example
31
+ *
32
+ * ```ts
33
+ * const debounce = (callback: Function, delay = 300) => {
34
+ * let timer: any = null
35
+ * return (...args: any[]) => {
36
+ * clearTimeout(timer)
37
+ * }
38
+ * }
39
+ *
40
+ */
41
+ export declare function debounce<F extends Callback>(callback: F, options?: debounce_throttle_options): DebounceAndThrottleReturnType<F>;
42
+ /**
43
+ * 节流
44
+ *
45
+ * @param callback 回调函数
46
+ * @param options 延迟时间(毫秒),默认 200 (ms) 或设置 this
47
+ * @returns 返回的闭包函数
48
+ */
49
+ export declare function throttle<F extends Callback>(callback: F, options?: debounce_throttle_options): DebounceAndThrottleReturnType<F>;
50
+ export {};
package/package.json CHANGED
@@ -1,51 +1,111 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.1",
4
4
  "name": "a-js-tools",
5
- "description": "一点点 🤏 js 函数",
6
5
  "license": "MIT",
7
6
  "dependencies": {
8
- "a-type-of-js": "^1.0.2"
7
+ "a-type-of-js": "^2.0.0"
8
+ },
9
+ "main": "cjs/index.js",
10
+ "module": "es/index.js",
11
+ "types": "es/src/index.d.ts",
12
+ "author": {
13
+ "name": "泥豆君",
14
+ "email": "Mr.MudBean@outlook.com",
15
+ "url": "https://earthnut.dev"
16
+ },
17
+ "description": "一点点 🤏 js 函数",
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=18.0.0"
9
21
  },
10
- "main": "index.cjs",
11
- "module": "index.mjs",
12
- "types": "index.d.ts",
13
22
  "files": [
14
- "index.mjs",
15
- "index.cjs",
16
- "index.d.ts",
17
- "src"
23
+ "es",
24
+ "cjs",
25
+ "LICENSE",
26
+ "README.md"
18
27
  ],
19
28
  "exports": {
20
- "import": "./index.mjs",
21
- "require": "./index.cjs",
22
- "types": "./index.d.ts"
29
+ ".": {
30
+ "import": "./es/index.js",
31
+ "default": "./es/index.js",
32
+ "require": "./cjs/index.js",
33
+ "types": "./es/src/index.d.ts"
34
+ },
35
+ "./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"
40
+ },
41
+ "./className": {
42
+ "default": "./es/className.js",
43
+ "import": "./es/className.js",
44
+ "require": "./cjs/className.js",
45
+ "types": "./es/src/className.d.ts"
46
+ },
47
+ "./getRandomNumber": {
48
+ "default": "./es/getRandomNumber.js",
49
+ "import": "./es/getRandomNumber.js",
50
+ "require": "./cjs/getRandomNumber.js",
51
+ "types": "./es/src/getRandomNumber.d.ts"
52
+ },
53
+ "./getRandomString": {
54
+ "default": "./es/getRandomString.js",
55
+ "import": "./es/getRandomString.js",
56
+ "require": "./cjs/getRandomString.js",
57
+ "types": "./es/src/getRandomString.d.ts"
58
+ },
59
+ "./isNode": {
60
+ "default": "./es/isNode.js",
61
+ "import": "./es/isNode.js",
62
+ "require": "./cjs/isNode.js",
63
+ "types": "./es/src/isNode.d.ts"
64
+ },
65
+ "./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"
70
+ },
71
+ "./performance": {
72
+ "default": "./es/performance.js",
73
+ "import": "./es/performance.js",
74
+ "require": "./cjs/performance.js",
75
+ "types": "./es/src/performance.d.ts"
76
+ },
77
+ "./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"
82
+ },
83
+ "./sleep": {
84
+ "default": "./es/sleep.js",
85
+ "import": "./es/sleep.js",
86
+ "require": "./cjs/sleep.js",
87
+ "types": "./es/src/sleep.d.ts"
88
+ }
23
89
  },
24
90
  "repository": {
25
91
  "type": "git",
26
- "url": "git+https://github.com/earthnutDev/a-js-tools.git"
92
+ "url": "git+https://github.com/MrMudBean/a-js-tools.git"
27
93
  },
28
94
  "keywords": [
29
95
  "a-js-tools",
30
- "earthnut"
96
+ "Mr.MudBean",
97
+ "earthnut",
98
+ "js tools"
31
99
  ],
32
- "author": {
33
- "name": "花生亻",
34
- "email": "earthnut.dev@outlook.com",
35
- "url": "https://earthnut.dev/about"
36
- },
37
- "homepage": "https://earthnut.dev/a-js-tools",
100
+ "homepage": "https://earthnut.dev/npm/a-js-tools",
38
101
  "bugs": {
39
- "url": "https://github.com/earthnutDev/a-js-tools/issues",
40
- "email": "earthnut.dev@outlook.com"
102
+ "url": "https://github.com/MrMudBean/a-js-tools/issues",
103
+ "email": "Mr.MudBean@outlook.com"
41
104
  },
42
105
  "publishConfig": {
43
106
  "access": "public",
44
107
  "registry": "https://registry.npmjs.org/"
45
108
  },
46
- "engines": {
47
- "node": ">=15.0.0"
48
- },
49
109
  "browserslist": [
50
110
  "last 2 versions not ie <= 11"
51
111
  ]
package/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { CreateConstructor, createConstructor } from 'src/object/createConstructor';
2
- export { toLowerCamelCase, toSplitCase, getRandomFloat, getRandomInt, getRandomString, } from './src/index';
3
- export { throttle, debounce } from './src/performance';
4
- export type { DebounceAndThrottleReturnType, debounce_throttle_options, } from './src/performance';
5
- export { escapeRegExp, autoEscapedRegExp } from './src/regexp';
6
- export { isBrowser, isNode } from './src/isNode';
7
- export { intersection, enArr, union, difference, symmetricDifference, } from './src/array/';
8
- export { createConstructor };
9
- export type { CreateConstructor };
10
- export { sleep } from './src/sleep';
package/index.mjs DELETED
@@ -1,14 +0,0 @@
1
- export { createConstructor } from './src/object/createConstructor.mjs';
2
- export { getRandomFloat, getRandomInt } from './src/getRandomNumber.mjs';
3
- export { toLowerCamelCase, toSplitCase } from './src/className.mjs';
4
- export { getRandomString } from './src/getRandomString.mjs';
5
- export { debounce, throttle } from './src/performance.mjs';
6
- export { escapeRegExp } from './src/regexp/escapeRegExp.mjs';
7
- export { autoEscapedRegExp } from './src/regexp/autoEscapedRegExp.mjs';
8
- export { isBrowser, isNode } from './src/isNode.mjs';
9
- export { enArr } from './src/array/index.mjs';
10
- export { sleep } from './src/sleep.mjs';
11
- export { intersection } from './src/array/intersection.mjs';
12
- export { union } from './src/array/union.mjs';
13
- export { difference } from './src/array/difference.mjs';
14
- export { symmetricDifference } from './src/array/symmetricDifference.mjs';
package/src/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { getRandomInt, getRandomFloat } from './getRandomNumber';
2
- export { toLowerCamelCase, toSplitCase } from './className';
3
- export { getRandomString } from './getRandomString';
@@ -1,52 +0,0 @@
1
- /**
2
- * 防抖和节流
3
- *
4
- * @packageDocumentation
5
- * @module @a-js-tools/performance
6
- * @license MIT
7
- */
8
- type Callback = (...args: unknown[]) => void;
9
- /**
10
- *
11
- * 节流和防抖返回值类型
12
- *
13
- */
14
- export interface DebounceAndThrottleReturnType<F extends Callback> {
15
- (...args: Parameters<F>): void;
16
- cancel(): void;
17
- }
18
- /** 参数类型 */
19
- export type debounce_throttle_options<T extends (...args: unknown[]) => void> = T | {
20
- /** 回调函数 */
21
- callback: T;
22
- /** 使用的延迟时间,缺省值为 200ms */
23
- delay?: number;
24
- /** 使用的 this */
25
- this?: null | unknown;
26
- };
27
- /**
28
- *
29
- * 防抖
30
- *
31
- * @param options 使用参数
32
- * @returns 返回的闭包函数
33
- * @example
34
- *
35
- * ```ts
36
- * const debounce = (callback: Function, delay = 300) => {
37
- * let timer: any = null
38
- * return (...args: any[]) => {
39
- * clearTimeout(timer)
40
- * }
41
- * }
42
- *
43
- */
44
- export declare function debounce<F extends (...args: unknown[]) => void>(options: debounce_throttle_options<F>): DebounceAndThrottleReturnType<F>;
45
- /**
46
- * 节流
47
- *
48
- * @param options 使用的参数值
49
- * @returns 返回的闭包函数
50
- */
51
- export declare function throttle<F extends (...args: unknown[]) => void>(options: debounce_throttle_options<F>): DebounceAndThrottleReturnType<F>;
52
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes