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.
- package/README.md +5 -8
- package/{cjs/array/difference.js → array/difference.cjs.js} +1 -4
- package/{es/src/array → array}/difference.d.ts +1 -4
- package/{es/array/difference.js → array/difference.es.js} +1 -4
- package/{cjs/array/index.js → array/index.cjs.js} +13 -34
- package/{es/src/array → array}/index.d.ts +9 -30
- package/{es/array/index.js → array/index.es.js} +13 -34
- package/{cjs/array/intersection.js → array/intersection.cjs.js} +1 -6
- package/{es/src/array → array}/intersection.d.ts +1 -6
- package/{es/array/intersection.js → array/intersection.es.js} +1 -6
- package/{cjs/array/symmetricDifference.js → array/symmetricDifference.cjs.js} +2 -8
- package/{es/src/array → array}/symmetricDifference.d.ts +1 -7
- package/{es/array/symmetricDifference.js → array/symmetricDifference.es.js} +2 -8
- package/{cjs/className.js → className.cjs.js} +0 -4
- package/{es/src/className.d.ts → className.d.ts} +0 -4
- package/{es/className.js → className.es.js} +0 -4
- package/createBezier.cjs.js +136 -0
- package/createBezier.d.ts +65 -0
- package/createBezier.es.js +134 -0
- package/{cjs/getRandomNumber.js → getRandomNumber.cjs.js} +3 -9
- package/{es/src/getRandomNumber.d.ts → getRandomNumber.d.ts} +2 -4
- package/{es/getRandomNumber.js → getRandomNumber.es.js} +3 -9
- package/{cjs/getRandomString.js → getRandomString.cjs.js} +21 -21
- package/{es/src/getRandomString.d.ts → getRandomString.d.ts} +11 -8
- package/{es/getRandomString.js → getRandomString.es.js} +21 -21
- package/{cjs/index.js → index.cjs.js} +18 -16
- package/{es/src/index.d.ts → index.d.ts} +1 -0
- package/index.es.js +15 -0
- package/{cjs/isNode.js → isNode.cjs.js} +0 -4
- package/{es/src/isNode.d.ts → isNode.d.ts} +0 -4
- package/{es/isNode.js → isNode.es.js} +0 -4
- package/{cjs/object/createConstructor.js → object/createConstructor.cjs.js} +2 -5
- package/{es/src/object → object}/createConstructor.d.ts +2 -8
- package/{es/object/createConstructor.js → object/createConstructor.es.js} +2 -5
- package/package.json +80 -51
- package/{cjs/performance.js → performance.cjs.js} +8 -16
- package/{es/src/performance.d.ts → performance.d.ts} +4 -15
- package/{es/performance.js → performance.es.js} +5 -13
- package/{cjs/regexp/autoEscapedRegExp.js → regexp/autoEscapedRegExp.cjs.js} +3 -7
- package/{es/src/regexp → regexp}/autoEscapedRegExp.d.ts +1 -5
- package/{es/regexp/autoEscapedRegExp.js → regexp/autoEscapedRegExp.es.js} +3 -7
- package/regexp/escapeRegExp.cjs.js +22 -0
- package/regexp/escapeRegExp.d.ts +16 -0
- package/regexp/escapeRegExp.es.js +20 -0
- package/{cjs/regexp/parse.js → regexp/parse.cjs.js} +0 -2
- package/{es/src/regexp → regexp}/parse.d.ts +0 -2
- package/{es/regexp/parse.js → regexp/parse.es.js} +0 -2
- package/{es/src/regexp → regexp}/types.d.ts +0 -5
- package/{cjs/sleep.js → sleep.cjs.js} +3 -6
- package/{es/src/sleep.d.ts → sleep.d.ts} +0 -3
- package/{es/sleep.js → sleep.es.js} +2 -5
- package/cjs/regexp/escapeRegExp.js +0 -24
- package/es/index.js +0 -14
- package/es/regexp/escapeRegExp.js +0 -22
- package/es/src/regexp/escapeRegExp.d.ts +0 -18
- /package/{cjs/array/union.js → array/union.cjs.js} +0 -0
- /package/{es/src/array → array}/union.d.ts +0 -0
- /package/{es/array/union.js → array/union.es.js} +0 -0
- /package/{es/src/object → object}/index.d.ts +0 -0
- /package/{es/src/regexp → regexp}/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -11,16 +11,17 @@ npm install --save a-js-tools
|
|
|
11
11
|
|
|
12
12
|
## 纯函数
|
|
13
13
|
|
|
14
|
+
- `autoEscapedRegExp` 生成简单的正则表达式
|
|
15
|
+
- `createBezier` 构建简单的贝尔赛曲线
|
|
14
16
|
- `debounce` 防抖函数
|
|
15
|
-
- `
|
|
16
|
-
- `getRandomInt` 获取随机的整数
|
|
17
|
+
- `escapeRegExp` 转义字符串为简单的正则表达式
|
|
17
18
|
- `getRandomFloat` 获取随机的浮点数
|
|
19
|
+
- `getRandomInt` 获取随机的整数
|
|
18
20
|
- `getRandomString` 获取随机字符串
|
|
19
|
-
- `escapeRegExp` 转义字符串为简单的正则表达式
|
|
20
|
-
- `autoEscapedRegExp` 生成简单的正则表达式
|
|
21
21
|
- `isBrowser` 是否为浏览器环境
|
|
22
22
|
- `isNode` 是否为 Node 环境
|
|
23
23
|
- `sleep` 你的线程太累了,让它丫的睡一会吧
|
|
24
|
+
- `throttle` 节流函数
|
|
24
25
|
|
|
25
26
|
## class 名称转化
|
|
26
27
|
|
|
@@ -34,7 +35,3 @@ npm install --save a-js-tools
|
|
|
34
35
|
- `difference` 方法,计算两个数组的差集(以第一个数组为基准)
|
|
35
36
|
- `symmetricDifference` 方法,计算两个数组的对称差集(在两个数组都不共有的元素)
|
|
36
37
|
- `enArr` 对象,包含上面的方法
|
|
37
|
-
|
|
38
|
-
## 查看文档
|
|
39
|
-
|
|
40
|
-
查看 [https://earthnut.dev/npm/a-js-tools](https://earthnut.dev/npm/a-js-tools)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var aTypeOfJs = require('a-type-of-js');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* 求给出的两个数组的差值(A - B)
|
|
6
|
+
* ## 求给出的两个数组的差值(A - B)
|
|
7
7
|
*
|
|
8
8
|
* @param a - 第一个数组
|
|
9
9
|
* @param b - 第二个数组
|
|
@@ -11,13 +11,11 @@ var aTypeOfJs = require('a-type-of-js');
|
|
|
11
11
|
* @description 当两个参数有一个不是数组时将抛出
|
|
12
12
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
13
13
|
* @example
|
|
14
|
-
*
|
|
15
14
|
* ```ts
|
|
16
15
|
* import { difference} from 'a-js-tools';
|
|
17
16
|
*
|
|
18
17
|
* const log = console.log;
|
|
19
18
|
*
|
|
20
|
-
*
|
|
21
19
|
* log(difference([], [1, 2, 3])); // []
|
|
22
20
|
*
|
|
23
21
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -31,7 +29,6 @@ var aTypeOfJs = require('a-type-of-js');
|
|
|
31
29
|
* log(difference([1, 2, 3], null));
|
|
32
30
|
* log(difference([1, 2, 3], true));
|
|
33
31
|
* ```
|
|
34
|
-
*
|
|
35
32
|
*/
|
|
36
33
|
function difference(a, b) {
|
|
37
34
|
if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 求给出的两个数组的差值(A - B)
|
|
2
|
+
* ## 求给出的两个数组的差值(A - B)
|
|
3
3
|
*
|
|
4
4
|
* @param a - 第一个数组
|
|
5
5
|
* @param b - 第二个数组
|
|
@@ -7,13 +7,11 @@
|
|
|
7
7
|
* @description 当两个参数有一个不是数组时将抛出
|
|
8
8
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
9
9
|
* @example
|
|
10
|
-
*
|
|
11
10
|
* ```ts
|
|
12
11
|
* import { difference} from 'a-js-tools';
|
|
13
12
|
*
|
|
14
13
|
* const log = console.log;
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
15
|
* log(difference([], [1, 2, 3])); // []
|
|
18
16
|
*
|
|
19
17
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -27,6 +25,5 @@
|
|
|
27
25
|
* log(difference([1, 2, 3], null));
|
|
28
26
|
* log(difference([1, 2, 3], true));
|
|
29
27
|
* ```
|
|
30
|
-
*
|
|
31
28
|
*/
|
|
32
29
|
export declare function difference<T>(a: T[], b: T[]): T[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isArray, isEmptyArray } from 'a-type-of-js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* 求给出的两个数组的差值(A - B)
|
|
4
|
+
* ## 求给出的两个数组的差值(A - B)
|
|
5
5
|
*
|
|
6
6
|
* @param a - 第一个数组
|
|
7
7
|
* @param b - 第二个数组
|
|
@@ -9,13 +9,11 @@ import { isArray, isEmptyArray } from 'a-type-of-js';
|
|
|
9
9
|
* @description 当两个参数有一个不是数组时将抛出
|
|
10
10
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
11
11
|
* @example
|
|
12
|
-
*
|
|
13
12
|
* ```ts
|
|
14
13
|
* import { difference} from 'a-js-tools';
|
|
15
14
|
*
|
|
16
15
|
* const log = console.log;
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
17
|
* log(difference([], [1, 2, 3])); // []
|
|
20
18
|
*
|
|
21
19
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -29,7 +27,6 @@ import { isArray, isEmptyArray } from 'a-type-of-js';
|
|
|
29
27
|
* log(difference([1, 2, 3], null));
|
|
30
28
|
* log(difference([1, 2, 3], true));
|
|
31
29
|
* ```
|
|
32
|
-
*
|
|
33
30
|
*/
|
|
34
31
|
function difference(a, b) {
|
|
35
32
|
if (!isArray(a) || !isArray(b)) {
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var intersection = require('./intersection.js');
|
|
4
|
-
var union = require('./union.js');
|
|
5
|
-
var difference = require('./difference.js');
|
|
6
|
-
var symmetricDifference = require('./symmetricDifference.js');
|
|
3
|
+
var intersection = require('./intersection.cjs.js');
|
|
4
|
+
var union = require('./union.cjs.js');
|
|
5
|
+
var difference = require('./difference.cjs.js');
|
|
6
|
+
var symmetricDifference = require('./symmetricDifference.cjs.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
+
* ## 数组的一些方法
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
14
|
-
* - difference 两个数组的差集 (A - B)
|
|
15
|
-
* - symmetricDifference 对称差集 ( A △ B)
|
|
16
|
-
*
|
|
11
|
+
* - `union` 两个数组的并集(排除共有项)
|
|
12
|
+
* - `intersection` 两个数组的交集(共有项)
|
|
13
|
+
* - `difference` 两个数组的差集 (A - B)
|
|
14
|
+
* - `symmetricDifference` 对称差集 ( A △ B)
|
|
17
15
|
*/
|
|
18
16
|
const enArr = {
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
21
|
-
* 数组的并集
|
|
22
|
-
*
|
|
18
|
+
* ### 数组的并集
|
|
23
19
|
* <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
|
|
24
20
|
* @param arrays - 多个数组
|
|
25
21
|
* @returns 联合后的数组
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
22
|
* @example
|
|
29
23
|
*
|
|
30
24
|
* ```ts
|
|
@@ -55,33 +49,27 @@ const enArr = {
|
|
|
55
49
|
* // [1, 2, 3, 4, 6]
|
|
56
50
|
* log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
|
|
57
51
|
* ```
|
|
58
|
-
*
|
|
59
52
|
*/
|
|
60
53
|
union: union.union,
|
|
61
54
|
/**
|
|
62
|
-
*
|
|
63
|
-
* 两个数组的交集
|
|
55
|
+
* ### 两个数组的交集
|
|
64
56
|
*
|
|
65
57
|
* @param a 数组 1️⃣
|
|
66
58
|
* @param b 数组 2️⃣
|
|
67
59
|
* @returns 返回两个数组的交集
|
|
68
60
|
* @example
|
|
69
|
-
*
|
|
70
61
|
* ```ts
|
|
71
62
|
* import { intersection } from 'a-js-tools';
|
|
72
63
|
*
|
|
73
64
|
* const log = console.log;
|
|
74
65
|
*
|
|
75
|
-
*
|
|
76
66
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
77
67
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
78
|
-
*
|
|
79
68
|
* ```
|
|
80
|
-
*
|
|
81
69
|
*/
|
|
82
70
|
intersection: intersection.intersection,
|
|
83
71
|
/**
|
|
84
|
-
*
|
|
72
|
+
* ### 求给出的两个数组的差值(A - B)
|
|
85
73
|
*
|
|
86
74
|
* @param a - 第一个数组
|
|
87
75
|
* @param b - 第二个数组
|
|
@@ -89,13 +77,11 @@ const enArr = {
|
|
|
89
77
|
* @description 当两个参数有一个不是数组时将抛出
|
|
90
78
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
91
79
|
* @example
|
|
92
|
-
*
|
|
93
80
|
* ```ts
|
|
94
81
|
* import { difference} from 'a-js-tools';
|
|
95
82
|
*
|
|
96
83
|
* const log = console.log;
|
|
97
84
|
*
|
|
98
|
-
*
|
|
99
85
|
* log(difference([], [1, 2, 3])); // []
|
|
100
86
|
*
|
|
101
87
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -109,19 +95,15 @@ const enArr = {
|
|
|
109
95
|
* log(difference([1, 2, 3], null));
|
|
110
96
|
* log(difference([1, 2, 3], true));
|
|
111
97
|
* ```
|
|
112
|
-
*
|
|
113
98
|
*/
|
|
114
99
|
difference: difference.difference,
|
|
115
100
|
/**
|
|
116
|
-
*
|
|
117
|
-
* 对称差集 ( A △ B)
|
|
101
|
+
* ### 对称差集 ( A △ B)
|
|
118
102
|
*
|
|
119
103
|
* @param a - 数组 a
|
|
120
104
|
* @param b - 数组 b
|
|
121
105
|
* @returns - 返回一个全新的数组
|
|
122
|
-
*
|
|
123
106
|
* @example
|
|
124
|
-
*
|
|
125
107
|
* ```ts
|
|
126
108
|
* import { symmetricDifference } from 'a-js-tools';
|
|
127
109
|
*
|
|
@@ -133,16 +115,13 @@ const enArr = {
|
|
|
133
115
|
*
|
|
134
116
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
135
117
|
*
|
|
136
|
-
*
|
|
137
118
|
* /// TypeError
|
|
138
119
|
* log(symmetricDifference(1, []));
|
|
139
120
|
* log(symmetricDifference(undefined, []));
|
|
140
121
|
* log(symmetricDifference(null, []));
|
|
141
122
|
* log(symmetricDifference('a', []));
|
|
142
123
|
* log(symmetricDifference(true, []));
|
|
143
|
-
*
|
|
144
124
|
* ```
|
|
145
|
-
*
|
|
146
125
|
*/
|
|
147
126
|
symmetricDifference: symmetricDifference.symmetricDifference,
|
|
148
127
|
};
|
|
@@ -4,25 +4,19 @@ import { difference } from './difference';
|
|
|
4
4
|
import { symmetricDifference } from './symmetricDifference';
|
|
5
5
|
export { union, intersection, difference, symmetricDifference };
|
|
6
6
|
/**
|
|
7
|
+
* ## 数组的一些方法
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* - difference 两个数组的差集 (A - B)
|
|
13
|
-
* - symmetricDifference 对称差集 ( A △ B)
|
|
14
|
-
*
|
|
9
|
+
* - `union` 两个数组的并集(排除共有项)
|
|
10
|
+
* - `intersection` 两个数组的交集(共有项)
|
|
11
|
+
* - `difference` 两个数组的差集 (A - B)
|
|
12
|
+
* - `symmetricDifference` 对称差集 ( A △ B)
|
|
15
13
|
*/
|
|
16
14
|
export declare const enArr: {
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
* 数组的并集
|
|
20
|
-
*
|
|
16
|
+
* ### 数组的并集
|
|
21
17
|
* <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
|
|
22
18
|
* @param arrays - 多个数组
|
|
23
19
|
* @returns 联合后的数组
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
20
|
* @example
|
|
27
21
|
*
|
|
28
22
|
* ```ts
|
|
@@ -53,33 +47,27 @@ export declare const enArr: {
|
|
|
53
47
|
* // [1, 2, 3, 4, 6]
|
|
54
48
|
* log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
|
|
55
49
|
* ```
|
|
56
|
-
*
|
|
57
50
|
*/
|
|
58
51
|
union: typeof union;
|
|
59
52
|
/**
|
|
60
|
-
*
|
|
61
|
-
* 两个数组的交集
|
|
53
|
+
* ### 两个数组的交集
|
|
62
54
|
*
|
|
63
55
|
* @param a 数组 1️⃣
|
|
64
56
|
* @param b 数组 2️⃣
|
|
65
57
|
* @returns 返回两个数组的交集
|
|
66
58
|
* @example
|
|
67
|
-
*
|
|
68
59
|
* ```ts
|
|
69
60
|
* import { intersection } from 'a-js-tools';
|
|
70
61
|
*
|
|
71
62
|
* const log = console.log;
|
|
72
63
|
*
|
|
73
|
-
*
|
|
74
64
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
75
65
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
76
|
-
*
|
|
77
66
|
* ```
|
|
78
|
-
*
|
|
79
67
|
*/
|
|
80
68
|
intersection: typeof intersection;
|
|
81
69
|
/**
|
|
82
|
-
*
|
|
70
|
+
* ### 求给出的两个数组的差值(A - B)
|
|
83
71
|
*
|
|
84
72
|
* @param a - 第一个数组
|
|
85
73
|
* @param b - 第二个数组
|
|
@@ -87,13 +75,11 @@ export declare const enArr: {
|
|
|
87
75
|
* @description 当两个参数有一个不是数组时将抛出
|
|
88
76
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
89
77
|
* @example
|
|
90
|
-
*
|
|
91
78
|
* ```ts
|
|
92
79
|
* import { difference} from 'a-js-tools';
|
|
93
80
|
*
|
|
94
81
|
* const log = console.log;
|
|
95
82
|
*
|
|
96
|
-
*
|
|
97
83
|
* log(difference([], [1, 2, 3])); // []
|
|
98
84
|
*
|
|
99
85
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -107,19 +93,15 @@ export declare const enArr: {
|
|
|
107
93
|
* log(difference([1, 2, 3], null));
|
|
108
94
|
* log(difference([1, 2, 3], true));
|
|
109
95
|
* ```
|
|
110
|
-
*
|
|
111
96
|
*/
|
|
112
97
|
difference: typeof difference;
|
|
113
98
|
/**
|
|
114
|
-
*
|
|
115
|
-
* 对称差集 ( A △ B)
|
|
99
|
+
* ### 对称差集 ( A △ B)
|
|
116
100
|
*
|
|
117
101
|
* @param a - 数组 a
|
|
118
102
|
* @param b - 数组 b
|
|
119
103
|
* @returns - 返回一个全新的数组
|
|
120
|
-
*
|
|
121
104
|
* @example
|
|
122
|
-
*
|
|
123
105
|
* ```ts
|
|
124
106
|
* import { symmetricDifference } from 'a-js-tools';
|
|
125
107
|
*
|
|
@@ -131,16 +113,13 @@ export declare const enArr: {
|
|
|
131
113
|
*
|
|
132
114
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
133
115
|
*
|
|
134
|
-
*
|
|
135
116
|
* /// TypeError
|
|
136
117
|
* log(symmetricDifference(1, []));
|
|
137
118
|
* log(symmetricDifference(undefined, []));
|
|
138
119
|
* log(symmetricDifference(null, []));
|
|
139
120
|
* log(symmetricDifference('a', []));
|
|
140
121
|
* log(symmetricDifference(true, []));
|
|
141
|
-
*
|
|
142
122
|
* ```
|
|
143
|
-
*
|
|
144
123
|
*/
|
|
145
124
|
symmetricDifference: typeof symmetricDifference;
|
|
146
125
|
};
|
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
import { intersection } from './intersection.js';
|
|
2
|
-
import { union } from './union.js';
|
|
3
|
-
import { difference } from './difference.js';
|
|
4
|
-
import { symmetricDifference } from './symmetricDifference.js';
|
|
1
|
+
import { intersection } from './intersection.es.js';
|
|
2
|
+
import { union } from './union.es.js';
|
|
3
|
+
import { difference } from './difference.es.js';
|
|
4
|
+
import { symmetricDifference } from './symmetricDifference.es.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
+
* ## 数组的一些方法
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* - difference 两个数组的差集 (A - B)
|
|
13
|
-
* - symmetricDifference 对称差集 ( A △ B)
|
|
14
|
-
*
|
|
9
|
+
* - `union` 两个数组的并集(排除共有项)
|
|
10
|
+
* - `intersection` 两个数组的交集(共有项)
|
|
11
|
+
* - `difference` 两个数组的差集 (A - B)
|
|
12
|
+
* - `symmetricDifference` 对称差集 ( A △ B)
|
|
15
13
|
*/
|
|
16
14
|
const enArr = {
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
* 数组的并集
|
|
20
|
-
*
|
|
16
|
+
* ### 数组的并集
|
|
21
17
|
* <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
|
|
22
18
|
* @param arrays - 多个数组
|
|
23
19
|
* @returns 联合后的数组
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
20
|
* @example
|
|
27
21
|
*
|
|
28
22
|
* ```ts
|
|
@@ -53,33 +47,27 @@ const enArr = {
|
|
|
53
47
|
* // [1, 2, 3, 4, 6]
|
|
54
48
|
* log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
|
|
55
49
|
* ```
|
|
56
|
-
*
|
|
57
50
|
*/
|
|
58
51
|
union,
|
|
59
52
|
/**
|
|
60
|
-
*
|
|
61
|
-
* 两个数组的交集
|
|
53
|
+
* ### 两个数组的交集
|
|
62
54
|
*
|
|
63
55
|
* @param a 数组 1️⃣
|
|
64
56
|
* @param b 数组 2️⃣
|
|
65
57
|
* @returns 返回两个数组的交集
|
|
66
58
|
* @example
|
|
67
|
-
*
|
|
68
59
|
* ```ts
|
|
69
60
|
* import { intersection } from 'a-js-tools';
|
|
70
61
|
*
|
|
71
62
|
* const log = console.log;
|
|
72
63
|
*
|
|
73
|
-
*
|
|
74
64
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
75
65
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
76
|
-
*
|
|
77
66
|
* ```
|
|
78
|
-
*
|
|
79
67
|
*/
|
|
80
68
|
intersection,
|
|
81
69
|
/**
|
|
82
|
-
*
|
|
70
|
+
* ### 求给出的两个数组的差值(A - B)
|
|
83
71
|
*
|
|
84
72
|
* @param a - 第一个数组
|
|
85
73
|
* @param b - 第二个数组
|
|
@@ -87,13 +75,11 @@ const enArr = {
|
|
|
87
75
|
* @description 当两个参数有一个不是数组时将抛出
|
|
88
76
|
* @returns 返回第一个参数相对第二个参数的差值
|
|
89
77
|
* @example
|
|
90
|
-
*
|
|
91
78
|
* ```ts
|
|
92
79
|
* import { difference} from 'a-js-tools';
|
|
93
80
|
*
|
|
94
81
|
* const log = console.log;
|
|
95
82
|
*
|
|
96
|
-
*
|
|
97
83
|
* log(difference([], [1, 2, 3])); // []
|
|
98
84
|
*
|
|
99
85
|
* log([1, 2, 3], []); //[1, 2, 3]
|
|
@@ -107,19 +93,15 @@ const enArr = {
|
|
|
107
93
|
* log(difference([1, 2, 3], null));
|
|
108
94
|
* log(difference([1, 2, 3], true));
|
|
109
95
|
* ```
|
|
110
|
-
*
|
|
111
96
|
*/
|
|
112
97
|
difference,
|
|
113
98
|
/**
|
|
114
|
-
*
|
|
115
|
-
* 对称差集 ( A △ B)
|
|
99
|
+
* ### 对称差集 ( A △ B)
|
|
116
100
|
*
|
|
117
101
|
* @param a - 数组 a
|
|
118
102
|
* @param b - 数组 b
|
|
119
103
|
* @returns - 返回一个全新的数组
|
|
120
|
-
*
|
|
121
104
|
* @example
|
|
122
|
-
*
|
|
123
105
|
* ```ts
|
|
124
106
|
* import { symmetricDifference } from 'a-js-tools';
|
|
125
107
|
*
|
|
@@ -131,16 +113,13 @@ const enArr = {
|
|
|
131
113
|
*
|
|
132
114
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
133
115
|
*
|
|
134
|
-
*
|
|
135
116
|
* /// TypeError
|
|
136
117
|
* log(symmetricDifference(1, []));
|
|
137
118
|
* log(symmetricDifference(undefined, []));
|
|
138
119
|
* log(symmetricDifference(null, []));
|
|
139
120
|
* log(symmetricDifference('a', []));
|
|
140
121
|
* log(symmetricDifference(true, []));
|
|
141
|
-
*
|
|
142
122
|
* ```
|
|
143
|
-
*
|
|
144
123
|
*/
|
|
145
124
|
symmetricDifference,
|
|
146
125
|
};
|
|
@@ -3,25 +3,20 @@
|
|
|
3
3
|
var aTypeOfJs = require('a-type-of-js');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* 两个数组的交集
|
|
6
|
+
* ## 两个数组的交集
|
|
8
7
|
*
|
|
9
8
|
* @param a 数组 1️⃣
|
|
10
9
|
* @param b 数组 2️⃣
|
|
11
10
|
* @returns 返回两个数组的交集
|
|
12
11
|
* @example
|
|
13
|
-
*
|
|
14
12
|
* ```ts
|
|
15
13
|
* import { intersection } from 'a-js-tools';
|
|
16
14
|
*
|
|
17
15
|
* const log = console.log;
|
|
18
16
|
*
|
|
19
|
-
*
|
|
20
17
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
21
18
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
22
|
-
*
|
|
23
19
|
* ```
|
|
24
|
-
*
|
|
25
20
|
*/
|
|
26
21
|
function intersection(a, b) {
|
|
27
22
|
if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b)) {
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 两个数组的交集
|
|
2
|
+
* ## 两个数组的交集
|
|
4
3
|
*
|
|
5
4
|
* @param a 数组 1️⃣
|
|
6
5
|
* @param b 数组 2️⃣
|
|
7
6
|
* @returns 返回两个数组的交集
|
|
8
7
|
* @example
|
|
9
|
-
*
|
|
10
8
|
* ```ts
|
|
11
9
|
* import { intersection } from 'a-js-tools';
|
|
12
10
|
*
|
|
13
11
|
* const log = console.log;
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
13
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
17
14
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
18
|
-
*
|
|
19
15
|
* ```
|
|
20
|
-
*
|
|
21
16
|
*/
|
|
22
17
|
export declare function intersection<T>(a: T[], b: T[]): T[];
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { isArray, isEmptyArray } from 'a-type-of-js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* 两个数组的交集
|
|
4
|
+
* ## 两个数组的交集
|
|
6
5
|
*
|
|
7
6
|
* @param a 数组 1️⃣
|
|
8
7
|
* @param b 数组 2️⃣
|
|
9
8
|
* @returns 返回两个数组的交集
|
|
10
9
|
* @example
|
|
11
|
-
*
|
|
12
10
|
* ```ts
|
|
13
11
|
* import { intersection } from 'a-js-tools';
|
|
14
12
|
*
|
|
15
13
|
* const log = console.log;
|
|
16
14
|
*
|
|
17
|
-
*
|
|
18
15
|
* log(intersection([1, 2, 3, 4], [2, 3])); // [2, 3]
|
|
19
16
|
* log(intersection([1, 3, 5, 7], [2, 3, 4])); // [3]
|
|
20
|
-
*
|
|
21
17
|
* ```
|
|
22
|
-
*
|
|
23
18
|
*/
|
|
24
19
|
function intersection(a, b) {
|
|
25
20
|
if (!isArray(a) || !isArray(b)) {
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var aTypeOfJs = require('a-type-of-js');
|
|
4
|
-
var difference = require('./difference.js');
|
|
4
|
+
var difference = require('./difference.cjs.js');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* 对称差集 ( A △ B)
|
|
7
|
+
* ## 对称差集 ( A △ B)
|
|
9
8
|
*
|
|
10
9
|
* @param a - 数组 a
|
|
11
10
|
* @param b - 数组 b
|
|
12
11
|
* @returns - 返回一个全新的数组
|
|
13
|
-
*
|
|
14
12
|
* @example
|
|
15
|
-
*
|
|
16
13
|
* ```ts
|
|
17
14
|
* import { symmetricDifference } from 'a-js-tools';
|
|
18
15
|
*
|
|
@@ -24,16 +21,13 @@ var difference = require('./difference.js');
|
|
|
24
21
|
*
|
|
25
22
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
26
23
|
*
|
|
27
|
-
*
|
|
28
24
|
* /// TypeError
|
|
29
25
|
* log(symmetricDifference(1, []));
|
|
30
26
|
* log(symmetricDifference(undefined, []));
|
|
31
27
|
* log(symmetricDifference(null, []));
|
|
32
28
|
* log(symmetricDifference('a', []));
|
|
33
29
|
* log(symmetricDifference(true, []));
|
|
34
|
-
*
|
|
35
30
|
* ```
|
|
36
|
-
*
|
|
37
31
|
*/
|
|
38
32
|
function symmetricDifference(a, b) {
|
|
39
33
|
if (!aTypeOfJs.isArray(a) || !aTypeOfJs.isArray(b)) {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 对称差集 ( A △ B)
|
|
2
|
+
* ## 对称差集 ( A △ B)
|
|
4
3
|
*
|
|
5
4
|
* @param a - 数组 a
|
|
6
5
|
* @param b - 数组 b
|
|
7
6
|
* @returns - 返回一个全新的数组
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
|
-
*
|
|
11
8
|
* ```ts
|
|
12
9
|
* import { symmetricDifference } from 'a-js-tools';
|
|
13
10
|
*
|
|
@@ -19,15 +16,12 @@
|
|
|
19
16
|
*
|
|
20
17
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
21
18
|
*
|
|
22
|
-
*
|
|
23
19
|
* /// TypeError
|
|
24
20
|
* log(symmetricDifference(1, []));
|
|
25
21
|
* log(symmetricDifference(undefined, []));
|
|
26
22
|
* log(symmetricDifference(null, []));
|
|
27
23
|
* log(symmetricDifference('a', []));
|
|
28
24
|
* log(symmetricDifference(true, []));
|
|
29
|
-
*
|
|
30
25
|
* ```
|
|
31
|
-
*
|
|
32
26
|
*/
|
|
33
27
|
export declare function symmetricDifference<T>(a: T[], b: T[]): T[];
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { isArray, isEmptyArray } from 'a-type-of-js';
|
|
2
|
-
import { difference } from './difference.js';
|
|
2
|
+
import { difference } from './difference.es.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* 对称差集 ( A △ B)
|
|
5
|
+
* ## 对称差集 ( A △ B)
|
|
7
6
|
*
|
|
8
7
|
* @param a - 数组 a
|
|
9
8
|
* @param b - 数组 b
|
|
10
9
|
* @returns - 返回一个全新的数组
|
|
11
|
-
*
|
|
12
10
|
* @example
|
|
13
|
-
*
|
|
14
11
|
* ```ts
|
|
15
12
|
* import { symmetricDifference } from 'a-js-tools';
|
|
16
13
|
*
|
|
@@ -22,16 +19,13 @@ import { difference } from './difference.js';
|
|
|
22
19
|
*
|
|
23
20
|
* log(symmetricDifference([1, 2, 3], [1, 2, 3])); // []
|
|
24
21
|
*
|
|
25
|
-
*
|
|
26
22
|
* /// TypeError
|
|
27
23
|
* log(symmetricDifference(1, []));
|
|
28
24
|
* log(symmetricDifference(undefined, []));
|
|
29
25
|
* log(symmetricDifference(null, []));
|
|
30
26
|
* log(symmetricDifference('a', []));
|
|
31
27
|
* log(symmetricDifference(true, []));
|
|
32
|
-
*
|
|
33
28
|
* ```
|
|
34
|
-
*
|
|
35
29
|
*/
|
|
36
30
|
function symmetricDifference(a, b) {
|
|
37
31
|
if (!isArray(a) || !isArray(b)) {
|