utiller 1.0.91 → 1.0.94
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/exceptioner/index.js +7 -7
- package/lib/utiller/index.js +103 -1
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
package/lib/exceptioner/index.js
CHANGED
|
@@ -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
|
|
package/lib/utiller/index.js
CHANGED
|
@@ -546,6 +546,13 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
546
546
|
|
|
547
547
|
return result;
|
|
548
548
|
}
|
|
549
|
+
/** 拿前面n個items */
|
|
550
|
+
|
|
551
|
+
}, {
|
|
552
|
+
key: "getArrayOfSize",
|
|
553
|
+
value: function getArrayOfSize(array, n) {
|
|
554
|
+
return _lodash["default"].slice(array, 0, n);
|
|
555
|
+
}
|
|
549
556
|
}, {
|
|
550
557
|
key: "getShuffledArrayWithLimitCount",
|
|
551
558
|
value: function getShuffledArrayWithLimitCount(arr, n) {
|
|
@@ -682,6 +689,21 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
682
689
|
|
|
683
690
|
return after;
|
|
684
691
|
}
|
|
692
|
+
/** 就是用address去找出current index(比較內文要用findIndex),然後取代之
|
|
693
|
+
* array = ['a','b','c'];
|
|
694
|
+
* current = array[1] === 'b'
|
|
695
|
+
* latest = 'd'
|
|
696
|
+
*
|
|
697
|
+
* return ['a','d','c']
|
|
698
|
+
* */
|
|
699
|
+
|
|
700
|
+
}, {
|
|
701
|
+
key: "replaceArrayByContentIndex",
|
|
702
|
+
value: function replaceArrayByContentIndex(array, current, latest) {
|
|
703
|
+
var index = _lodash["default"].indexOf(array, current);
|
|
704
|
+
|
|
705
|
+
array[index] = latest;
|
|
706
|
+
}
|
|
685
707
|
}, {
|
|
686
708
|
key: "deepFlat",
|
|
687
709
|
value: function deepFlat(collection) {
|
|
@@ -903,7 +925,9 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
903
925
|
|
|
904
926
|
}, {
|
|
905
927
|
key: "getIndexOfContext",
|
|
906
|
-
value:
|
|
928
|
+
value:
|
|
929
|
+
/** 比較內文, 不是只比較 memory address */
|
|
930
|
+
function getIndexOfContext(context, stmt) {
|
|
907
931
|
return _lodash["default"].findIndex(context, function (per) {
|
|
908
932
|
return _lodash["default"].isEqual(per.trim(), stmt);
|
|
909
933
|
});
|
|
@@ -1763,6 +1787,84 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
1763
1787
|
segments.shift();
|
|
1764
1788
|
return segments.join(separator);
|
|
1765
1789
|
}
|
|
1790
|
+
/**
|
|
1791
|
+
* array = [{name:'david',id:'kfgijifd'},{name:'serena',id:'kdffof'}....]
|
|
1792
|
+
* attrKeyOfPK = 'id'
|
|
1793
|
+
* result => { kfgijifd: {name:'david',id:'kfgijifd'}, kdffof:{name:'serena',id:'kdffof'} }
|
|
1794
|
+
* */
|
|
1795
|
+
|
|
1796
|
+
}, {
|
|
1797
|
+
key: "toObjectWithAttributeKey",
|
|
1798
|
+
value: function toObjectWithAttributeKey(array, attrKeyOfPK) {
|
|
1799
|
+
var object = {};
|
|
1800
|
+
|
|
1801
|
+
var _iterator13 = _createForOfIteratorHelper(array),
|
|
1802
|
+
_step13;
|
|
1803
|
+
|
|
1804
|
+
try {
|
|
1805
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1806
|
+
var each = _step13.value;
|
|
1807
|
+
var pk = each[attrKeyOfPK];
|
|
1808
|
+
|
|
1809
|
+
if (this.isUndefinedNullEmpty(pk)) {
|
|
1810
|
+
throw new _exceptioner["default"](9999, "48157232 pk can't be empty => '".concat(pk, "'"));
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
object[pk] = each;
|
|
1814
|
+
}
|
|
1815
|
+
} catch (err) {
|
|
1816
|
+
_iterator13.e(err);
|
|
1817
|
+
} finally {
|
|
1818
|
+
_iterator13.f();
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
return object;
|
|
1822
|
+
}
|
|
1823
|
+
/** others returns [{logic:true|false,message:'oops'}]
|
|
1824
|
+
* */
|
|
1825
|
+
|
|
1826
|
+
}, {
|
|
1827
|
+
key: "constraintOfParam",
|
|
1828
|
+
value: function constraintOfParam(collection, type) {
|
|
1829
|
+
var result = false;
|
|
1830
|
+
|
|
1831
|
+
for (var _len16 = arguments.length, others = new Array(_len16 > 2 ? _len16 - 2 : 0), _key17 = 2; _key17 < _len16; _key17++) {
|
|
1832
|
+
others[_key17 - 2] = arguments[_key17];
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
var validOfOthersCondition = _lodash["default"].isEmpty(others) ? true : this.and.apply(this, (0, _toConsumableArray2["default"])(others.map(function (each) {
|
|
1836
|
+
return each.logic;
|
|
1837
|
+
})));
|
|
1838
|
+
|
|
1839
|
+
switch (type) {
|
|
1840
|
+
case "array":
|
|
1841
|
+
if (_lodash["default"].isArray(collection) && validOfOthersCondition) result = true;
|
|
1842
|
+
break;
|
|
1843
|
+
|
|
1844
|
+
case "object":
|
|
1845
|
+
if (_lodash["default"].isObject(collection) && validOfOthersCondition) result = true;
|
|
1846
|
+
break;
|
|
1847
|
+
|
|
1848
|
+
case "string":
|
|
1849
|
+
if (_lodash["default"].isString(collection) && validOfOthersCondition) result = true;
|
|
1850
|
+
break;
|
|
1851
|
+
|
|
1852
|
+
case "number":
|
|
1853
|
+
if (_lodash["default"].isNumber(collection) && validOfOthersCondition) result = true;
|
|
1854
|
+
break;
|
|
1855
|
+
|
|
1856
|
+
case "other":
|
|
1857
|
+
if (validOfOthersCondition) return true;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
var stringOfRules = _lodash["default"].isEmpty(others) ? "" : ", ".concat(others.map(function (each) {
|
|
1861
|
+
return each.message;
|
|
1862
|
+
}).join(" | "));
|
|
1863
|
+
|
|
1864
|
+
if (result === false) {
|
|
1865
|
+
throw new _exceptioner["default"](9999, "7474423 type should be ".concat(type, " but get '").concat((0, _typeof2["default"])(type), "' ").concat(stringOfRules, " "));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1766
1868
|
}]);
|
|
1767
1869
|
return Utiller;
|
|
1768
1870
|
}();
|
package/package.json
CHANGED