a-js-tools 0.6.0 → 0.6.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/cjs/src/array/index.cjs +135 -0
- package/mjs/src/array/index.mjs +135 -0
- package/package.json +1 -1
- package/types/src/array/index.d.ts +135 -0
package/cjs/src/array/index.cjs
CHANGED
|
@@ -5,10 +5,145 @@ var union = require('./union.cjs');
|
|
|
5
5
|
var difference = require('./difference.cjs');
|
|
6
6
|
var symmetricDifference = require('./symmetricDifference.cjs');
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* 数组的一些方法
|
|
11
|
+
*
|
|
12
|
+
* - union 两个数组的并集(排除共有项)
|
|
13
|
+
* - intersection 两个数组的交集(共有项)
|
|
14
|
+
* - difference 两个数组的差集 (A - B)
|
|
15
|
+
* - symmetricDifference 对称差集 ( A △ B)
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
8
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
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
|
+
*/
|
|
11
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
|
+
*/
|
|
12
147
|
symmetricDifference: symmetricDifference.symmetricDifference,
|
|
13
148
|
};
|
|
14
149
|
|
package/mjs/src/array/index.mjs
CHANGED
|
@@ -3,10 +3,145 @@ import { union } from './union.mjs';
|
|
|
3
3
|
import { difference } from './difference.mjs';
|
|
4
4
|
import { symmetricDifference } from './symmetricDifference.mjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* 数组的一些方法
|
|
9
|
+
*
|
|
10
|
+
* - union 两个数组的并集(排除共有项)
|
|
11
|
+
* - intersection 两个数组的交集(共有项)
|
|
12
|
+
* - difference 两个数组的差集 (A - B)
|
|
13
|
+
* - symmetricDifference 对称差集 ( A △ B)
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
6
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
|
+
*/
|
|
7
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
|
+
*/
|
|
8
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
145
|
symmetricDifference,
|
|
11
146
|
};
|
|
12
147
|
|
package/package.json
CHANGED
|
@@ -3,9 +3,144 @@ import { union } from './union';
|
|
|
3
3
|
import { difference } from './difference';
|
|
4
4
|
import { symmetricDifference } from './symmetricDifference';
|
|
5
5
|
export { union, intersection, difference, symmetricDifference };
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* 数组的一些方法
|
|
9
|
+
*
|
|
10
|
+
* - union 两个数组的并集(排除共有项)
|
|
11
|
+
* - intersection 两个数组的交集(共有项)
|
|
12
|
+
* - difference 两个数组的差集 (A - B)
|
|
13
|
+
* - symmetricDifference 对称差集 ( A △ B)
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
6
16
|
export declare 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
|
+
*/
|
|
7
58
|
union: typeof 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
|
+
*/
|
|
8
80
|
intersection: typeof 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
|
+
*/
|
|
9
112
|
difference: typeof 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
|
+
*/
|
|
10
145
|
symmetricDifference: typeof symmetricDifference;
|
|
11
146
|
};
|