tools-for-js 1.2.9 → 1.3.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/README.md +2 -1
- package/lib/index.js +6 -0
- package/lib/utils/array.js +16 -3
- package/lib/utils/string.js +21 -1
- package/package.json +4 -1
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -99,6 +99,12 @@ Object.defineProperty(exports, "getPagination", {
|
|
|
99
99
|
return _array.getPagination;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
+
Object.defineProperty(exports, "getRandomColor", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function get() {
|
|
105
|
+
return _string.getRandomColor;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
102
108
|
Object.defineProperty(exports, "getStrLength", {
|
|
103
109
|
enumerable: true,
|
|
104
110
|
get: function get() {
|
package/lib/utils/array.js
CHANGED
|
@@ -276,15 +276,28 @@ function shuffleArray(arr) {
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
/*******
|
|
279
|
-
* @description:
|
|
279
|
+
* @description: 数组反选: 选中元素与未选中元素反转
|
|
280
280
|
* @author: 琴时
|
|
281
281
|
* @param {Array} list
|
|
282
|
-
* @param {*} elem
|
|
283
|
-
* @param {*} key
|
|
282
|
+
* @param {*} elem [选中的元素]
|
|
283
|
+
* @param {*} key [反转目标元素]
|
|
284
284
|
* @return {Array}
|
|
285
|
+
* @example
|
|
286
|
+
* invertSelection([1, 2], 'all', 'all') => ['all']
|
|
287
|
+
* invertSelection(['all'], 1, 'all') => [1]
|
|
288
|
+
* invertSelection([1, 2, 3], 3, 'all') => [1, 2]
|
|
289
|
+
* invertSelection([1, 2], 3, 'all') => [1, 2, 3]
|
|
285
290
|
*/
|
|
286
291
|
function invertSelection(list, elem) {
|
|
287
292
|
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'all';
|
|
293
|
+
if (list.includes(elem)) {
|
|
294
|
+
list = list.filter(function (item) {
|
|
295
|
+
return item !== elem;
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
list.push(elem);
|
|
299
|
+
}
|
|
300
|
+
// element=key 时,直接返回[key],否则将key从list中删除
|
|
288
301
|
return list.filter(function (item) {
|
|
289
302
|
return item === key === (elem === key);
|
|
290
303
|
});
|
package/lib/utils/string.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.encode = exports.decode = exports.checkPwdStrength = void 0;
|
|
7
|
+
exports.getRandomColor = getRandomColor;
|
|
8
|
+
exports.getStrLength = void 0;
|
|
7
9
|
exports.replacePath = replacePath;
|
|
8
10
|
exports.splitString = splitString;
|
|
9
11
|
exports.splitToFileName = splitToFileName;
|
|
@@ -206,4 +208,22 @@ function splitToFileName(path) {
|
|
|
206
208
|
var lastIndex = path.lastIndexOf('/');
|
|
207
209
|
if (lastIndex === -1) return path;
|
|
208
210
|
return path.substring(lastIndex + 1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/*******
|
|
214
|
+
* @description: 生成随机颜色
|
|
215
|
+
* @author: 琴时
|
|
216
|
+
* @param {Array} defaultList [跳过颜色(可选参数),默认为空数组]
|
|
217
|
+
* @return {String}
|
|
218
|
+
*/
|
|
219
|
+
function getRandomColor() {
|
|
220
|
+
var defaultList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
221
|
+
var letters = '0123456789ABCDEF';
|
|
222
|
+
var color = '#';
|
|
223
|
+
for (var i = 0; i < 6; i++) {
|
|
224
|
+
color += letters[Math.floor(Math.random() * 16)];
|
|
225
|
+
}
|
|
226
|
+
//如果生成的颜色和默认颜色重复了,则重新生成
|
|
227
|
+
if (defaultList.includes(color)) getRandomColor(defaultList);
|
|
228
|
+
return color;
|
|
209
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools-for-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "基于babel构建的javascript工具库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"dayjs": "^1.11.11"
|
|
37
|
+
},
|
|
38
|
+
"volta": {
|
|
39
|
+
"node": "20.12.2"
|
|
37
40
|
}
|
|
38
41
|
}
|