a-js-tools 1.0.12 → 1.0.13-beta.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.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.12",
3
+ "version": "1.0.13-beta.1",
4
4
  "name": "a-js-tools",
5
5
  "description": "一点点 🤏 js 函数",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "a-type-of-js": "^1.0.7"
9
9
  },
10
- "main": "index.cjs",
11
- "module": "index.mjs",
10
+ "main": "index.cjs.js",
11
+ "module": "index.mjs.js",
12
12
  "types": "index.d.ts",
13
13
  "files": [
14
14
  "index.mjs",
@@ -17,8 +17,8 @@
17
17
  "src"
18
18
  ],
19
19
  "exports": {
20
- "import": "./index.mjs",
21
- "require": "./index.cjs",
20
+ "import": "./index.mjs.js",
21
+ "require": "./index.cjs.js",
22
22
  "types": "./index.d.ts"
23
23
  },
24
24
  "repository": {
package/index.cjs DELETED
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var createConstructor = require('./src/object/createConstructor.cjs');
4
- var getRandomNumber = require('./src/getRandomNumber.cjs');
5
- var className = require('./src/className.cjs');
6
- var getRandomString = require('./src/getRandomString.cjs');
7
- var performance = require('./src/performance.cjs');
8
- var escapeRegExp = require('./src/regexp/escapeRegExp.cjs');
9
- var autoEscapedRegExp = require('./src/regexp/autoEscapedRegExp.cjs');
10
- var isNode = require('./src/isNode.cjs');
11
- var index = require('./src/array/index.cjs');
12
- var sleep = require('./src/sleep.cjs');
13
- var intersection = require('./src/array/intersection.cjs');
14
- var union = require('./src/array/union.cjs');
15
- var difference = require('./src/array/difference.cjs');
16
- var symmetricDifference = require('./src/array/symmetricDifference.cjs');
17
-
18
-
19
-
20
- exports.createConstructor = createConstructor.createConstructor;
21
- exports.getRandomFloat = getRandomNumber.getRandomFloat;
22
- exports.getRandomInt = getRandomNumber.getRandomInt;
23
- exports.toLowerCamelCase = className.toLowerCamelCase;
24
- exports.toSplitCase = className.toSplitCase;
25
- exports.getRandomString = getRandomString.getRandomString;
26
- exports.debounce = performance.debounce;
27
- exports.throttle = performance.throttle;
28
- exports.escapeRegExp = escapeRegExp.escapeRegExp;
29
- exports.autoEscapedRegExp = autoEscapedRegExp.autoEscapedRegExp;
30
- exports.isBrowser = isNode.isBrowser;
31
- exports.isNode = isNode.isNode;
32
- exports.enArr = index.enArr;
33
- exports.sleep = sleep.sleep;
34
- exports.intersection = intersection.intersection;
35
- exports.union = union.union;
36
- exports.difference = difference.difference;
37
- exports.symmetricDifference = symmetricDifference.symmetricDifference;
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';
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
-
5
- /**
6
- * 求给出的两个数组的差值(A - B)
7
- *
8
- * @param a - 第一个数组
9
- * @param b - 第二个数组
10
- * @throws {TypeError} 当两个参数有一个不是
11
- * @description 当两个参数有一个不是数组时将抛出
12
- * @returns 返回第一个参数相对第二个参数的差值
13
- * @example
14
- *
15
- * ```ts
16
- * import { difference} from 'a-js-tools';
17
- *
18
- * const log = console.log;
19
- *
20
- *
21
- * log(difference([], [1, 2, 3])); // []
22
- *
23
- * log([1, 2, 3], []); //[1, 2, 3]
24
- *
25
- * log([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5]); //[6, 7]
26
- *
27
- * // 将抛出 TypeError
28
- * log(difference([1, 2, 3], 'a'));
29
- * log(difference([1, 2, 3], 1));
30
- * log(difference([1, 2, 3], undefined));
31
- * log(difference([1, 2, 3], null));
32
- * log(difference([1, 2, 3], true));
33
- * ```
34
- *
35
- */
36
- function difference(a, b) {
37
- if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b))
38
- throw new TypeError('参数需为数组');
39
- if (aTypeOfJs.isEmptyArray(a) || aTypeOfJs.isEmptyArray(b))
40
- return a;
41
- /** 获取两个数组中长度较小的 */
42
- // 参数有顺序要求
43
- // const [shorter, longer] = a.length > b.length ? [b, a] : [a, b];
44
- // const shorterSet = new Set(shorter);
45
- const bSet = new Set(b);
46
- return a.filter(i => !bSet.has(i));
47
- }
48
-
49
- exports.difference = difference;
@@ -1,47 +0,0 @@
1
- import { isArray, isEmptyArray } from 'a-type-of-js';
2
-
3
- /**
4
- * 求给出的两个数组的差值(A - B)
5
- *
6
- * @param a - 第一个数组
7
- * @param b - 第二个数组
8
- * @throws {TypeError} 当两个参数有一个不是
9
- * @description 当两个参数有一个不是数组时将抛出
10
- * @returns 返回第一个参数相对第二个参数的差值
11
- * @example
12
- *
13
- * ```ts
14
- * import { difference} from 'a-js-tools';
15
- *
16
- * const log = console.log;
17
- *
18
- *
19
- * log(difference([], [1, 2, 3])); // []
20
- *
21
- * log([1, 2, 3], []); //[1, 2, 3]
22
- *
23
- * log([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5]); //[6, 7]
24
- *
25
- * // 将抛出 TypeError
26
- * log(difference([1, 2, 3], 'a'));
27
- * log(difference([1, 2, 3], 1));
28
- * log(difference([1, 2, 3], undefined));
29
- * log(difference([1, 2, 3], null));
30
- * log(difference([1, 2, 3], true));
31
- * ```
32
- *
33
- */
34
- function difference(a, b) {
35
- if (!isArray(a) || !isArray(b))
36
- throw new TypeError('参数需为数组');
37
- if (isEmptyArray(a) || isEmptyArray(b))
38
- return a;
39
- /** 获取两个数组中长度较小的 */
40
- // 参数有顺序要求
41
- // const [shorter, longer] = a.length > b.length ? [b, a] : [a, b];
42
- // const shorterSet = new Set(shorter);
43
- const bSet = new Set(b);
44
- return a.filter(i => !bSet.has(i));
45
- }
46
-
47
- export { difference };
@@ -1,154 +0,0 @@
1
- 'use strict';
2
-
3
- var intersection = require('./intersection.cjs');
4
- var union = require('./union.cjs');
5
- var difference = require('./difference.cjs');
6
- var symmetricDifference = require('./symmetricDifference.cjs');
7
-
8
- /**
9
- *
10
- * 数组的一些方法
11
- *
12
- * - union 两个数组的并集(排除共有项)
13
- * - intersection 两个数组的交集(共有项)
14
- * - difference 两个数组的差集 (A - B)
15
- * - symmetricDifference 对称差集 ( A △ B)
16
- *
17
- */
18
- const enArr = {
19
- /**
20
- *
21
- * 数组的并集
22
- *
23
- * <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
24
- * @param arrays - 多个数组
25
- * @returns 联合后的数组
26
- *
27
- *
28
- * @example
29
- *
30
- * ```ts
31
- * import { union } from 'a-js-tools';
32
- *
33
- * const log = console.log;
34
- *
35
- * // []
36
- * log(union());
37
- *
38
- * // [1, 2, 3]
39
- * log(union([1, 2, 3]));
40
- *
41
- * // TypeError
42
- * log(union([1, 2, 3], 'i'));
43
- * log(union([1, 2, 3], undefined));
44
- * log(union([1, 2, 3], null));
45
- * log(union([1, 2, 3], 4));
46
- * log(union([1, 2, 3], {}));
47
- * log(union([1, 2, 3], false));
48
- *
49
- * // [1, 2, 3, 4, 6]
50
- * log(union([1, 2, 3], [2, 4, 6]));
51
- *
52
- * // [1, 2, 3, 4, 6]
53
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3]));
54
- *
55
- * // [1, 2, 3, 4, 6]
56
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
57
- * ```
58
- *
59
- */
60
- union: union.union,
61
- /**
62
- *
63
- * 两个数组的交集
64
- *
65
- * @param a 数组 1️⃣
66
- * @param b 数组 2️⃣
67
- * @returns 返回两个数组的交集
68
- * @example
69
- *
70
- * ```ts
71
- * import { intersection } from 'a-js-tools';
72
- *
73
- * const log = console.log;
74
- *
75
- *
76
- * log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
77
- * log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
78
- *
79
- * ```
80
- *
81
- */
82
- intersection: intersection.intersection,
83
- /**
84
- * 求给出的两个数组的差值(A - B)
85
- *
86
- * @param a - 第一个数组
87
- * @param b - 第二个数组
88
- * @throws {TypeError} 当两个参数有一个不是
89
- * @description 当两个参数有一个不是数组时将抛出
90
- * @returns 返回第一个参数相对第二个参数的差值
91
- * @example
92
- *
93
- * ```ts
94
- * import { difference} from 'a-js-tools';
95
- *
96
- * const log = console.log;
97
- *
98
- *
99
- * log(difference([], [1, 2, 3])); // []
100
- *
101
- * log([1, 2, 3], []); //[1, 2, 3]
102
- *
103
- * log([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5]); //[6, 7]
104
- *
105
- * // 将抛出 TypeError
106
- * log(difference([1, 2, 3], 'a'));
107
- * log(difference([1, 2, 3], 1));
108
- * log(difference([1, 2, 3], undefined));
109
- * log(difference([1, 2, 3], null));
110
- * log(difference([1, 2, 3], true));
111
- * ```
112
- *
113
- */
114
- difference: difference.difference,
115
- /**
116
- *
117
- * 对称差集 ( A △ B)
118
- *
119
- * @param a - 数组 a
120
- * @param b - 数组 b
121
- * @returns - 返回一个全新的数组
122
- *
123
- * @example
124
- *
125
- * ```ts
126
- * import { symmetricDifference } from 'a-js-tools';
127
- *
128
- * const log = console.log;
129
- *
130
- * log(symmetricDifference([1, 2], [2, 3])); // [1, 3]
131
- *
132
- * log(symmetricDifference([1, 2, 3], [1, 2, 4])); // [3, 4]
133
- *
134
- * log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
135
- *
136
- *
137
- * /// TypeError
138
- * log(symmetricDifference(1, []));
139
- * log(symmetricDifference(undefined, []));
140
- * log(symmetricDifference(null, []));
141
- * log(symmetricDifference('a', []));
142
- * log(symmetricDifference(true, []));
143
- *
144
- * ```
145
- *
146
- */
147
- symmetricDifference: symmetricDifference.symmetricDifference,
148
- };
149
-
150
- exports.intersection = intersection.intersection;
151
- exports.union = union.union;
152
- exports.difference = difference.difference;
153
- exports.symmetricDifference = symmetricDifference.symmetricDifference;
154
- exports.enArr = enArr;
@@ -1,148 +0,0 @@
1
- import { intersection } from './intersection.mjs';
2
- import { union } from './union.mjs';
3
- import { difference } from './difference.mjs';
4
- import { symmetricDifference } from './symmetricDifference.mjs';
5
-
6
- /**
7
- *
8
- * 数组的一些方法
9
- *
10
- * - union 两个数组的并集(排除共有项)
11
- * - intersection 两个数组的交集(共有项)
12
- * - difference 两个数组的差集 (A - B)
13
- * - symmetricDifference 对称差集 ( A △ B)
14
- *
15
- */
16
- const enArr = {
17
- /**
18
- *
19
- * 数组的并集
20
- *
21
- * <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
22
- * @param arrays - 多个数组
23
- * @returns 联合后的数组
24
- *
25
- *
26
- * @example
27
- *
28
- * ```ts
29
- * import { union } from 'a-js-tools';
30
- *
31
- * const log = console.log;
32
- *
33
- * // []
34
- * log(union());
35
- *
36
- * // [1, 2, 3]
37
- * log(union([1, 2, 3]));
38
- *
39
- * // TypeError
40
- * log(union([1, 2, 3], 'i'));
41
- * log(union([1, 2, 3], undefined));
42
- * log(union([1, 2, 3], null));
43
- * log(union([1, 2, 3], 4));
44
- * log(union([1, 2, 3], {}));
45
- * log(union([1, 2, 3], false));
46
- *
47
- * // [1, 2, 3, 4, 6]
48
- * log(union([1, 2, 3], [2, 4, 6]));
49
- *
50
- * // [1, 2, 3, 4, 6]
51
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3]));
52
- *
53
- * // [1, 2, 3, 4, 6]
54
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
55
- * ```
56
- *
57
- */
58
- union,
59
- /**
60
- *
61
- * 两个数组的交集
62
- *
63
- * @param a 数组 1️⃣
64
- * @param b 数组 2️⃣
65
- * @returns 返回两个数组的交集
66
- * @example
67
- *
68
- * ```ts
69
- * import { intersection } from 'a-js-tools';
70
- *
71
- * const log = console.log;
72
- *
73
- *
74
- * log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
75
- * log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
76
- *
77
- * ```
78
- *
79
- */
80
- intersection,
81
- /**
82
- * 求给出的两个数组的差值(A - B)
83
- *
84
- * @param a - 第一个数组
85
- * @param b - 第二个数组
86
- * @throws {TypeError} 当两个参数有一个不是
87
- * @description 当两个参数有一个不是数组时将抛出
88
- * @returns 返回第一个参数相对第二个参数的差值
89
- * @example
90
- *
91
- * ```ts
92
- * import { difference} from 'a-js-tools';
93
- *
94
- * const log = console.log;
95
- *
96
- *
97
- * log(difference([], [1, 2, 3])); // []
98
- *
99
- * log([1, 2, 3], []); //[1, 2, 3]
100
- *
101
- * log([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5]); //[6, 7]
102
- *
103
- * // 将抛出 TypeError
104
- * log(difference([1, 2, 3], 'a'));
105
- * log(difference([1, 2, 3], 1));
106
- * log(difference([1, 2, 3], undefined));
107
- * log(difference([1, 2, 3], null));
108
- * log(difference([1, 2, 3], true));
109
- * ```
110
- *
111
- */
112
- difference,
113
- /**
114
- *
115
- * 对称差集 ( A △ B)
116
- *
117
- * @param a - 数组 a
118
- * @param b - 数组 b
119
- * @returns - 返回一个全新的数组
120
- *
121
- * @example
122
- *
123
- * ```ts
124
- * import { symmetricDifference } from 'a-js-tools';
125
- *
126
- * const log = console.log;
127
- *
128
- * log(symmetricDifference([1, 2], [2, 3])); // [1, 3]
129
- *
130
- * log(symmetricDifference([1, 2, 3], [1, 2, 4])); // [3, 4]
131
- *
132
- * log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
133
- *
134
- *
135
- * /// TypeError
136
- * log(symmetricDifference(1, []));
137
- * log(symmetricDifference(undefined, []));
138
- * log(symmetricDifference(null, []));
139
- * log(symmetricDifference('a', []));
140
- * log(symmetricDifference(true, []));
141
- *
142
- * ```
143
- *
144
- */
145
- symmetricDifference,
146
- };
147
-
148
- export { difference, enArr, intersection, symmetricDifference, union };
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
-
5
- /**
6
- *
7
- * 两个数组的交集
8
- *
9
- * @param a 数组 1️⃣
10
- * @param b 数组 2️⃣
11
- * @returns 返回两个数组的交集
12
- * @example
13
- *
14
- * ```ts
15
- * import { intersection } from 'a-js-tools';
16
- *
17
- * const log = console.log;
18
- *
19
- *
20
- * log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
21
- * log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
22
- *
23
- * ```
24
- *
25
- */
26
- function intersection(a, b) {
27
- if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b))
28
- throw new TypeError('参数必须是数组类型数据');
29
- // 任意数组为空,则返回空数组
30
- if (aTypeOfJs.isEmptyArray(a) || aTypeOfJs.isEmptyArray(b))
31
- return [];
32
- /**
33
- * 在实际运算中, new Set() 的 开销为 O(n) ,filter 的开销也为 O(n)
34
- *
35
- * 但是以较短的数组创建 Set ,可以节省内存开销
36
- */
37
- const [shorter, longer] = a.length <= b.length ? [a, b] : [b, a];
38
- // 提前创建工具 Set
39
- const shortSet = new Set(shorter);
40
- return longer.filter(item => shortSet.has(item));
41
- }
42
-
43
- exports.intersection = intersection;
@@ -1,41 +0,0 @@
1
- import { isArray, isEmptyArray } from 'a-type-of-js';
2
-
3
- /**
4
- *
5
- * 两个数组的交集
6
- *
7
- * @param a 数组 1️⃣
8
- * @param b 数组 2️⃣
9
- * @returns 返回两个数组的交集
10
- * @example
11
- *
12
- * ```ts
13
- * import { intersection } from 'a-js-tools';
14
- *
15
- * const log = console.log;
16
- *
17
- *
18
- * log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
19
- * log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
20
- *
21
- * ```
22
- *
23
- */
24
- function intersection(a, b) {
25
- if (!isArray(a) || !isArray(b))
26
- throw new TypeError('参数必须是数组类型数据');
27
- // 任意数组为空,则返回空数组
28
- if (isEmptyArray(a) || isEmptyArray(b))
29
- return [];
30
- /**
31
- * 在实际运算中, new Set() 的 开销为 O(n) ,filter 的开销也为 O(n)
32
- *
33
- * 但是以较短的数组创建 Set ,可以节省内存开销
34
- */
35
- const [shorter, longer] = a.length <= b.length ? [a, b] : [b, a];
36
- // 提前创建工具 Set
37
- const shortSet = new Set(shorter);
38
- return longer.filter(item => shortSet.has(item));
39
- }
40
-
41
- export { intersection };
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
- var difference = require('./difference.cjs');
5
-
6
- /**
7
- *
8
- * 对称差集 ( A △ B)
9
- *
10
- * @param a - 数组 a
11
- * @param b - 数组 b
12
- * @returns - 返回一个全新的数组
13
- *
14
- * @example
15
- *
16
- * ```ts
17
- * import { symmetricDifference } from 'a-js-tools';
18
- *
19
- * const log = console.log;
20
- *
21
- * log(symmetricDifference([1, 2], [2, 3])); // [1, 3]
22
- *
23
- * log(symmetricDifference([1, 2, 3], [1, 2, 4])); // [3, 4]
24
- *
25
- * log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
26
- *
27
- *
28
- * /// TypeError
29
- * log(symmetricDifference(1, []));
30
- * log(symmetricDifference(undefined, []));
31
- * log(symmetricDifference(null, []));
32
- * log(symmetricDifference('a', []));
33
- * log(symmetricDifference(true, []));
34
- *
35
- * ```
36
- *
37
- */
38
- function symmetricDifference(a, b) {
39
- if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b))
40
- throw new TypeError('参数必须是数组');
41
- if (aTypeOfJs.isEmptyArray(a))
42
- return [...b];
43
- if (aTypeOfJs.isEmptyArray(b))
44
- return [...a];
45
- return [...difference.difference(a, b), ...difference.difference(b, a)];
46
- }
47
-
48
- exports.symmetricDifference = symmetricDifference;
@@ -1,46 +0,0 @@
1
- import { isArray, isEmptyArray } from 'a-type-of-js';
2
- import { difference } from './difference.mjs';
3
-
4
- /**
5
- *
6
- * 对称差集 ( A △ B)
7
- *
8
- * @param a - 数组 a
9
- * @param b - 数组 b
10
- * @returns - 返回一个全新的数组
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * import { symmetricDifference } from 'a-js-tools';
16
- *
17
- * const log = console.log;
18
- *
19
- * log(symmetricDifference([1, 2], [2, 3])); // [1, 3]
20
- *
21
- * log(symmetricDifference([1, 2, 3], [1, 2, 4])); // [3, 4]
22
- *
23
- * log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
24
- *
25
- *
26
- * /// TypeError
27
- * log(symmetricDifference(1, []));
28
- * log(symmetricDifference(undefined, []));
29
- * log(symmetricDifference(null, []));
30
- * log(symmetricDifference('a', []));
31
- * log(symmetricDifference(true, []));
32
- *
33
- * ```
34
- *
35
- */
36
- function symmetricDifference(a, b) {
37
- if (!isArray(a) || !isArray(b))
38
- throw new TypeError('参数必须是数组');
39
- if (isEmptyArray(a))
40
- return [...b];
41
- if (isEmptyArray(b))
42
- return [...a];
43
- return [...difference(a, b), ...difference(b, a)];
44
- }
45
-
46
- export { symmetricDifference };