tools-for-js 1.2.0 → 1.2.2
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/lib/index.js +12 -0
- package/lib/utils/array.js +6 -5
- package/lib/utils/object.js +18 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -87,6 +87,12 @@ Object.defineProperty(exports, "exactAdd", {
|
|
|
87
87
|
return _calculate.exactAdd;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
+
Object.defineProperty(exports, "getPagination", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function get() {
|
|
93
|
+
return _array.getPagination;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
90
96
|
Object.defineProperty(exports, "getStrLength", {
|
|
91
97
|
enumerable: true,
|
|
92
98
|
get: function get() {
|
|
@@ -141,6 +147,12 @@ Object.defineProperty(exports, "objectToQs", {
|
|
|
141
147
|
return _object.objectToQs;
|
|
142
148
|
}
|
|
143
149
|
});
|
|
150
|
+
Object.defineProperty(exports, "sortByKeyAndTime", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function get() {
|
|
153
|
+
return _array.sortByKeyAndTime;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
144
156
|
Object.defineProperty(exports, "splitString", {
|
|
145
157
|
enumerable: true,
|
|
146
158
|
get: function get() {
|
package/lib/utils/array.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.treeLastChildSum = exports.sortByKeyAndTime = exports.randomNumEnum = exports.getValueFromArray = exports.getPagination = exports.deWeightArray = exports.checkKeyEmpty = exports.arrayToTree = exports.arrExchange = exports.arrEleMove = void 0;
|
|
7
7
|
var _calculate = require("./calculate");
|
|
8
8
|
var _common = require("./common");
|
|
9
|
+
var _object = require("./object");
|
|
9
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
11
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -241,13 +242,13 @@ var sortByKeyAndTime = exports.sortByKeyAndTime = function sortByKeyAndTime(list
|
|
|
241
242
|
timeOrder = _ref3$timeOrder === void 0 ? 'desc' : _ref3$timeOrder;
|
|
242
243
|
var listCopy = (0, _common.deepCopy)(list);
|
|
243
244
|
return listCopy.sort(function (a, b) {
|
|
244
|
-
var a_val = a
|
|
245
|
-
var a_time = new Date(a
|
|
246
|
-
var b_val = b
|
|
247
|
-
var b_time = new Date(b
|
|
245
|
+
var a_val = (0, _object.getValByKey)(a, key);
|
|
246
|
+
var a_time = new Date((0, _object.getValByKey)(a, timeKey));
|
|
247
|
+
var b_val = (0, _object.getValByKey)(b, key);
|
|
248
|
+
var b_time = new Date((0, _object.getValByKey)(b, timeKey));
|
|
248
249
|
if (a_val === b_val) {
|
|
249
250
|
return timeOrder === 'desc' ? b_time - a_time : a_time - b_time;
|
|
250
251
|
}
|
|
251
|
-
return order === 'asc' ?
|
|
252
|
+
return order === 'asc' ? a_val - b_val : b_val - a_val;
|
|
252
253
|
});
|
|
253
254
|
};
|
package/lib/utils/object.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.objectToQs = void 0;
|
|
6
|
+
exports.objectToQs = exports.getValByKey = void 0;
|
|
7
7
|
/*******
|
|
8
8
|
* @description: 将对象转换为查询字符串
|
|
9
9
|
* @author: 琴时
|
|
@@ -15,4 +15,21 @@ var objectToQs = exports.objectToQs = function objectToQs(obj) {
|
|
|
15
15
|
return Object.keys(obj).map(function (key) {
|
|
16
16
|
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(obj[key]));
|
|
17
17
|
}).join('&');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/*******
|
|
21
|
+
* @description: 根据key获取对象值
|
|
22
|
+
* @author: 琴时
|
|
23
|
+
* @param {Object} obj
|
|
24
|
+
* @param {String} key
|
|
25
|
+
* @return {*}
|
|
26
|
+
* @example: getValByKey({a: {b: {c: 1}}}, 'a.b.c') => 1
|
|
27
|
+
*/
|
|
28
|
+
var getValByKey = exports.getValByKey = function getValByKey(obj, key) {
|
|
29
|
+
var keys = key.split('.');
|
|
30
|
+
var value = obj;
|
|
31
|
+
for (var i = 0; i < keys.length; i++) {
|
|
32
|
+
value = value[keys[i]];
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
18
35
|
};
|