utiller 1.0.153 → 1.0.154

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.
@@ -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 = _index.utiller.getRandomValue(0, 100000000000);
50
+ _this.uid = _index.utiller === undefined ? '777Debug777' : _index.utiller.getRandomValue(0, 100000000000);
51
51
  _this.code = code;
52
52
  _this.infos = '';
53
53
  _this._msg = error.message;
@@ -58,7 +58,7 @@ 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 += '##' + ' ' + _index.utiller.getAttrValueInSequence(info, 'message', 'msg');
61
+ if (info !== undefined) _this.infos += '##' + ' ' + "".concat(_index.utiller === undefined ? "777Debug777-".concat(info) : _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);
@@ -35,8 +35,6 @@ var _moment = _interopRequireDefault(require("moment"));
35
35
 
36
36
  var _uuid = require("uuid");
37
37
 
38
- var _nodeHtmlParser = require("node-html-parser");
39
-
40
38
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
41
39
 
42
40
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -1251,7 +1249,9 @@ var Utiller = /*#__PURE__*/function () {
1251
1249
  }, {
1252
1250
  key: "isUndefinedNullEmpty",
1253
1251
  value: function isUndefinedNullEmpty(obj) {
1254
- return obj === undefined || _lodash["default"].isEmpty(obj) || obj === null;
1252
+ var first = obj === undefined || obj === null;
1253
+ var second = _lodash["default"].isString(obj) || _lodash["default"].isArray(obj) ? _lodash["default"].isEmpty(obj) : false;
1254
+ return first || second;
1255
1255
  }
1256
1256
  }, {
1257
1257
  key: "isOrConditionOfUndefinedNullEmpty",
@@ -2375,6 +2375,54 @@ var Utiller = /*#__PURE__*/function () {
2375
2375
  checkValue = checkValue.toUpperCase();
2376
2376
  return checkValue;
2377
2377
  }
2378
+ /**
2379
+ * @param content = object
2380
+ * @param rules {KEY:predicate} | 'KEY', rules如果只放字串, rule = KEY就代表這個欄位不得為isUndefinedEmpty(), 如果是物件 => {key:predicate}
2381
+ * @param idOfError 用在每個呼叫的method, 有個stack trace的概念
2382
+ *
2383
+ *
2384
+ * console.log(utiller.isPayloadObjectValid({a: 3, b: 4}, ['a',{b:(value) => value > 5}]));
2385
+ * //ATTRIBUTE:'b' is not valid of custom rule
2386
+ */
2387
+
2388
+ }, {
2389
+ key: "isPayloadObjectValid",
2390
+ value: function isPayloadObjectValid(content) {
2391
+ var rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
2392
+ var idOfError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.getRandomHash(10);
2393
+
2394
+ if (this.isUndefinedNullEmpty(content)) {
2395
+ throw new _exceptioner["default"](9999, "".concat(idOfError, " content(pay-load) is undefined || empty"));
2396
+ }
2397
+
2398
+ var _iterator17 = _createForOfIteratorHelper(rules),
2399
+ _step17;
2400
+
2401
+ try {
2402
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2403
+ var rule = _step17.value;
2404
+
2405
+ if (_lodash["default"].isString(rule)) {
2406
+ if (this.isUndefinedNullEmpty(content[rule])) {
2407
+ throw new _exceptioner["default"](9999, "".concat(idOfError, " ATTRIBUTE:'").concat(rule, "' is not Exist"));
2408
+ }
2409
+ } else if (_lodash["default"].isObject(rule)) {
2410
+ var key = this.getObjectKey(rule);
2411
+ var predicate = this.getObjectValue(rule);
2412
+
2413
+ if (!predicate(content[key])) {
2414
+ throw new _exceptioner["default"](9999, "".concat(idOfError, " ATTRIBUTE:'").concat(key, "' is not valid of custom rule"));
2415
+ }
2416
+ }
2417
+ }
2418
+ } catch (err) {
2419
+ _iterator17.e(err);
2420
+ } finally {
2421
+ _iterator17.f();
2422
+ }
2423
+
2424
+ return true;
2425
+ }
2378
2426
  }]);
2379
2427
  return Utiller;
2380
2428
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.153",
3
+ "version": "1.0.154",
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.152",
14
+ "utiller": "^1.0.153",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.11",
17
17
  "lodash": "^4.17.20",