utiller 1.0.90 → 1.0.93

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.
@@ -21,16 +21,16 @@ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/w
21
21
 
22
22
  var _configerer = require("configerer");
23
23
 
24
- var _index = _interopRequireDefault(require("../utiller/index.js"));
25
-
26
24
  var _ERRORs = _interopRequireDefault(require("./ERRORs"));
27
25
 
26
+ var _index = require("../index.js");
27
+
28
+ var _lodash = _interopRequireDefault(require("lodash"));
29
+
28
30
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
29
31
 
30
32
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
31
33
 
32
- var utiller = new _index["default"]();
33
-
34
34
  var MyException = /*#__PURE__*/function (_Error) {
35
35
  (0, _inherits2["default"])(MyException, _Error);
36
36
 
@@ -47,7 +47,7 @@ var MyException = /*#__PURE__*/function (_Error) {
47
47
  }
48
48
 
49
49
  _this = _super.call(this, "".concat(error.message));
50
- _this.uid = utiller.getRandomValue(0, 100000000000);
50
+ _this.uid = _index.utiller.getRandomValue(0, 100000000000);
51
51
  _this.code = code;
52
52
  _this.infos = '';
53
53
  _this._msg = error.message;
@@ -58,11 +58,11 @@ var MyException = /*#__PURE__*/function (_Error) {
58
58
 
59
59
  for (var _i = 0, _infos = infos; _i < _infos.length; _i++) {
60
60
  var info = _infos[_i];
61
- if (info !== undefined) _this.infos += '##' + ' ' + utiller.getAttrValueInSequence(info, 'message', 'msg');
61
+ if (info !== undefined) _this.infos += '##' + ' ' + _index.utiller.getAttrValueInSequence(info, 'message', 'msg');
62
62
  }
63
63
 
64
64
  _this.message = "UID:".concat(_this.uid, " CODE:").concat(_this.code, " REASON:").concat(_this._msg, " INFO:").concat(_this.infos);
65
- if (_configerer.configerer.MODULE_MSG.SHOW_ERROR) utiller.appendError(_this.message);
65
+ if (_configerer.configerer.MODULE_MSG.SHOW_ERROR) _index.utiller.appendError(_this.message);
66
66
  return _this;
67
67
  }
68
68
 
@@ -546,6 +546,11 @@ var Utiller = /*#__PURE__*/function () {
546
546
 
547
547
  return result;
548
548
  }
549
+ }, {
550
+ key: "getArrayOfSize",
551
+ value: function getArrayOfSize(array, n) {
552
+ return _lodash["default"].slice(array, 0, n);
553
+ }
549
554
  }, {
550
555
  key: "getShuffledArrayWithLimitCount",
551
556
  value: function getShuffledArrayWithLimitCount(arr, n) {
@@ -1737,6 +1742,110 @@ var Utiller = /*#__PURE__*/function () {
1737
1742
 
1738
1743
  return equal;
1739
1744
  }
1745
+ /** 把 /a/v/c/d => /a/v/c/ */
1746
+
1747
+ }, {
1748
+ key: "getStringOfPop",
1749
+ value: function getStringOfPop(string, separator) {
1750
+ if (!_lodash["default"].isString(string)) {
1751
+ throw new _exceptioner["default"](9999, "445115,type should be string but ==> ".concat((0, _typeof2["default"])(string)));
1752
+ }
1753
+
1754
+ var segments = string.split(separator);
1755
+ segments.pop();
1756
+ return segments.join(separator);
1757
+ }
1758
+ /** 把 /a/v/c/d => /v/c/d */
1759
+
1760
+ }, {
1761
+ key: "getStringOfShift",
1762
+ value: function getStringOfShift(string, separator) {
1763
+ if (!_lodash["default"].isString(string)) {
1764
+ throw new _exceptioner["default"](9999, "445116,type should be string but ==> ".concat((0, _typeof2["default"])(string)));
1765
+ }
1766
+
1767
+ var segments = string.split(separator);
1768
+ segments.shift();
1769
+ return segments.join(separator);
1770
+ }
1771
+ /**
1772
+ * array = [{name:'david',id:'kfgijifd'},{name:'serena',id:'kdffof'}....]
1773
+ * attrKeyOfPK = 'id'
1774
+ * result => { kfgijifd: {name:'david',id:'kfgijifd'}, kdffof:{name:'serena',id:'kdffof'} }
1775
+ * */
1776
+
1777
+ }, {
1778
+ key: "toObjectWithAttributeKey",
1779
+ value: function toObjectWithAttributeKey(array, attrKeyOfPK) {
1780
+ var object = {};
1781
+
1782
+ var _iterator13 = _createForOfIteratorHelper(array),
1783
+ _step13;
1784
+
1785
+ try {
1786
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1787
+ var each = _step13.value;
1788
+ var pk = each[attrKeyOfPK];
1789
+
1790
+ if (this.isUndefinedNullEmpty(pk)) {
1791
+ throw new _exceptioner["default"](9999, "48157232 pk can't be empty => '".concat(pk, "'"));
1792
+ }
1793
+
1794
+ object[pk] = each;
1795
+ }
1796
+ } catch (err) {
1797
+ _iterator13.e(err);
1798
+ } finally {
1799
+ _iterator13.f();
1800
+ }
1801
+
1802
+ return object;
1803
+ }
1804
+ /** others returns [{logic:true|false,message:'oops'}]
1805
+ * */
1806
+
1807
+ }, {
1808
+ key: "constraintOfParam",
1809
+ value: function constraintOfParam(collection, type) {
1810
+ var result = false;
1811
+
1812
+ for (var _len16 = arguments.length, others = new Array(_len16 > 2 ? _len16 - 2 : 0), _key17 = 2; _key17 < _len16; _key17++) {
1813
+ others[_key17 - 2] = arguments[_key17];
1814
+ }
1815
+
1816
+ var validOfOthersCondition = _lodash["default"].isEmpty(others) ? true : this.and.apply(this, (0, _toConsumableArray2["default"])(others.map(function (each) {
1817
+ return each.logic;
1818
+ })));
1819
+
1820
+ switch (type) {
1821
+ case "array":
1822
+ if (_lodash["default"].isArray(collection) && validOfOthersCondition) result = true;
1823
+ break;
1824
+
1825
+ case "object":
1826
+ if (_lodash["default"].isObject(collection) && validOfOthersCondition) result = true;
1827
+ break;
1828
+
1829
+ case "string":
1830
+ if (_lodash["default"].isString(collection) && validOfOthersCondition) result = true;
1831
+ break;
1832
+
1833
+ case "number":
1834
+ if (_lodash["default"].isNumber(collection) && validOfOthersCondition) result = true;
1835
+ break;
1836
+
1837
+ case "other":
1838
+ if (validOfOthersCondition) return true;
1839
+ }
1840
+
1841
+ var stringOfRules = _lodash["default"].isEmpty(others) ? "" : ", ".concat(others.map(function (each) {
1842
+ return each.message;
1843
+ }).join(" | "));
1844
+
1845
+ if (result === false) {
1846
+ throw new _exceptioner["default"](9999, "7474423 type should be ".concat(type, " but get '").concat((0, _typeof2["default"])(type), "' ").concat(stringOfRules, " "));
1847
+ }
1848
+ }
1740
1849
  }]);
1741
1850
  return Utiller;
1742
1851
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.90",
3
+ "version": "1.0.93",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "configerer": "^1.0.11",
14
- "utiller": "^1.0.89",
14
+ "utiller": "^1.0.92",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.9",
17
17
  "lodash": "^4.17.20",