tools-for-js 1.2.6 → 1.2.8

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
@@ -52,3 +52,5 @@ import { API } from 'tools-for-js'
52
52
  | 根据 key 值排序,相同时则根据时间 timeKey 值排序 | sortByKeyAndTime |
53
53
  | 根据 key 获取对象值 | getValByKey |
54
54
  | 数组随机打乱 | shuffleArray |
55
+ | 将路径中的反斜杠字符 \ 替换为斜杠 / | replacePath |
56
+ | 切割/获取文件名 | splitToFileName |
package/lib/index.js CHANGED
@@ -153,6 +153,12 @@ Object.defineProperty(exports, "objectToQs", {
153
153
  return _object.objectToQs;
154
154
  }
155
155
  });
156
+ Object.defineProperty(exports, "replacePath", {
157
+ enumerable: true,
158
+ get: function get() {
159
+ return _string.replacePath;
160
+ }
161
+ });
156
162
  Object.defineProperty(exports, "shuffleArray", {
157
163
  enumerable: true,
158
164
  get: function get() {
@@ -171,6 +177,12 @@ Object.defineProperty(exports, "splitString", {
171
177
  return _string.splitString;
172
178
  }
173
179
  });
180
+ Object.defineProperty(exports, "splitToFileName", {
181
+ enumerable: true,
182
+ get: function get() {
183
+ return _string.splitToFileName;
184
+ }
185
+ });
174
186
  Object.defineProperty(exports, "summation", {
175
187
  enumerable: true,
176
188
  get: function get() {
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getStrLength = exports.encode = exports.decode = exports.checkPwdStrength = void 0;
7
+ exports.replacePath = replacePath;
7
8
  exports.splitString = splitString;
9
+ exports.splitToFileName = splitToFileName;
8
10
  var _utf8_encode = function _utf8_encode(string) {
9
11
  string = string.replace(/\r\n/g, '\n');
10
12
  var utftext = '';
@@ -181,4 +183,27 @@ function splitString(str, num) {
181
183
  }
182
184
  }
183
185
  return array;
186
+ }
187
+
188
+ /*******
189
+ * @description: 将路径中的反斜杠字符 \ 替换为斜杠 /
190
+ * @author: 琴时
191
+ * @param {*} path
192
+ * @return {*}
193
+ */
194
+ function replacePath(path) {
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);
184
209
  }
package/lib/utils/time.js CHANGED
@@ -11,7 +11,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
11
11
  // ES 2015
12
12
 
13
13
  _dayjs["default"].locale('zh-cn'); // 全局使用
14
- _dayjs["default"].extend(_relativeTime["default"]);
15
14
 
16
15
  /*******
17
16
  * @description: 生成时间格式化
@@ -150,6 +149,7 @@ var countDown = exports.countDown = function countDown(params) {
150
149
  * @return {String}
151
150
  */
152
151
  var transformDate = exports.transformDate = function transformDate(date, diff) {
152
+ _dayjs["default"].extend(_relativeTime["default"]);
153
153
  var transDay = (0, _dayjs["default"])(date).fromNow().replace(/\s+/g, '');
154
154
  if (transDay === '几秒前') transDay = '刚刚';
155
155
  if (diff) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools-for-js",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "基于babel构建的javascript工具库",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {