utiller 1.0.151 → 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);
package/lib/index.js CHANGED
@@ -23,12 +23,12 @@ var _exceptioner = _interopRequireDefault(require("./exceptioner"));
23
23
 
24
24
  var _pooller = _interopRequireDefault(require("./pooller"));
25
25
 
26
- var _configerer = require("configerer");
26
+ var _lodash = _interopRequireDefault(require("lodash"));
27
27
 
28
28
  var instance = undefined;
29
29
  exports.utiller = instance;
30
30
 
31
- if (_configerer.configerer.IS_NODE_ENV) {
31
+ if (process !== undefined && !_lodash["default"].isUndefined(process.version) && !_lodash["default"].isEmpty(process.version)) {
32
32
  var self = require('./utiller/nodeutiller');
33
33
 
34
34
  exports.utiller = instance = new self["default"]();
@@ -905,7 +905,7 @@ var Utiller = /*#__PURE__*/function () {
905
905
  }, {
906
906
  key: "printf",
907
907
  value: function printf() {
908
- this.appendInfo("i can use in node.js react.js");
908
+ this.appendInfo("i can use in web || react.js");
909
909
  }
910
910
  }, {
911
911
  key: "isKeywordRule",
@@ -1249,7 +1249,9 @@ var Utiller = /*#__PURE__*/function () {
1249
1249
  }, {
1250
1250
  key: "isUndefinedNullEmpty",
1251
1251
  value: function isUndefinedNullEmpty(obj) {
1252
- 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;
1253
1255
  }
1254
1256
  }, {
1255
1257
  key: "isOrConditionOfUndefinedNullEmpty",
@@ -2373,6 +2375,54 @@ var Utiller = /*#__PURE__*/function () {
2373
2375
  checkValue = checkValue.toUpperCase();
2374
2376
  return checkValue;
2375
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
+ }
2376
2426
  }]);
2377
2427
  return Utiller;
2378
2428
  }();
@@ -1815,7 +1815,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1815
1815
  key: "getStringOfHandledHtml",
1816
1816
  value: function getStringOfHandledHtml(string) {
1817
1817
  var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (document) {
1818
- return document;
1818
+ console.log(document);
1819
1819
  };
1820
1820
  var document = (0, _nodeHtmlParser.parse)(string);
1821
1821
  predicate(document);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.151",
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.150",
14
+ "utiller": "^1.0.153",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.11",
17
17
  "lodash": "^4.17.20",