tools-for-js 1.2.7 → 1.2.9

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 CHANGED
@@ -53,3 +53,5 @@ import { API } from 'tools-for-js'
53
53
  | 根据 key 获取对象值 | getValByKey |
54
54
  | 数组随机打乱 | shuffleArray |
55
55
  | 将路径中的反斜杠字符 \ 替换为斜杠 / | replacePath |
56
+ | 切割/获取文件名 | splitToFileName |
57
+ | 数组反转 | invertSelection |
package/lib/index.js CHANGED
@@ -117,6 +117,12 @@ Object.defineProperty(exports, "getValueFromArray", {
117
117
  return _array.getValueFromArray;
118
118
  }
119
119
  });
120
+ Object.defineProperty(exports, "invertSelection", {
121
+ enumerable: true,
122
+ get: function get() {
123
+ return _array.invertSelection;
124
+ }
125
+ });
120
126
  Object.defineProperty(exports, "isEmpty", {
121
127
  enumerable: true,
122
128
  get: function get() {
@@ -177,6 +183,12 @@ Object.defineProperty(exports, "splitString", {
177
183
  return _string.splitString;
178
184
  }
179
185
  });
186
+ Object.defineProperty(exports, "splitToFileName", {
187
+ enumerable: true,
188
+ get: function get() {
189
+ return _string.splitToFileName;
190
+ }
191
+ });
180
192
  Object.defineProperty(exports, "summation", {
181
193
  enumerable: true,
182
194
  get: function get() {
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.randomNumEnum = exports.getValueFromArray = exports.getPagination = exports.deWeightArray = exports.checkKeyEmpty = exports.arrayToTree = exports.arrExchange = exports.arrEleMove = void 0;
6
+ exports.getValueFromArray = exports.getPagination = exports.deWeightArray = exports.checkKeyEmpty = exports.arrayToTree = exports.arrExchange = exports.arrEleMove = void 0;
7
+ exports.invertSelection = invertSelection;
8
+ exports.randomNumEnum = void 0;
7
9
  exports.shuffleArray = shuffleArray;
8
10
  exports.treeLastChildSum = exports.sortByKeyAndTime = void 0;
9
11
  var _calculate = require("./calculate");
@@ -271,4 +273,19 @@ function shuffleArray(arr) {
271
273
  array[j] = _ref4[1];
272
274
  }
273
275
  return array;
276
+ }
277
+
278
+ /*******
279
+ * @description: 数组反转
280
+ * @author: 琴时
281
+ * @param {Array} list
282
+ * @param {*} elem
283
+ * @param {*} key
284
+ * @return {Array}
285
+ */
286
+ function invertSelection(list, elem) {
287
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'all';
288
+ return list.filter(function (item) {
289
+ return item === key === (elem === key);
290
+ });
274
291
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getStrLength = exports.encode = exports.decode = exports.checkPwdStrength = void 0;
7
7
  exports.replacePath = replacePath;
8
8
  exports.splitString = splitString;
9
+ exports.splitToFileName = splitToFileName;
9
10
  var _utf8_encode = function _utf8_encode(string) {
10
11
  string = string.replace(/\r\n/g, '\n');
11
12
  var utftext = '';
@@ -192,4 +193,17 @@ function splitString(str, num) {
192
193
  */
193
194
  function replacePath(path) {
194
195
  return path.replace(/\\/g, '/');
196
+ }
197
+
198
+ /*******
199
+ * @description: 切割/获取文件名
200
+ * @author: 琴时
201
+ * @param {*} path
202
+ * @return {*}
203
+ */
204
+ function splitToFileName(path) {
205
+ path = replacePath(path || '');
206
+ var lastIndex = path.lastIndexOf('/');
207
+ if (lastIndex === -1) return path;
208
+ return path.substring(lastIndex + 1);
195
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools-for-js",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "基于babel构建的javascript工具库",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {