topkat-utils 1.1.14 → 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.
Files changed (72) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +9 -13
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/array-utils.js +23 -45
  6. package/dist/src/array-utils.js.map +1 -1
  7. package/dist/src/clean-stack-trace.d.ts +1 -0
  8. package/dist/src/clean-stack-trace.js +46 -0
  9. package/dist/src/clean-stack-trace.js.map +1 -0
  10. package/dist/src/config.d.ts +1 -1
  11. package/dist/src/config.js +5 -16
  12. package/dist/src/config.js.map +1 -1
  13. package/dist/src/date-utils.js +91 -141
  14. package/dist/src/date-utils.js.map +1 -1
  15. package/dist/src/env-utils.js +4 -4
  16. package/dist/src/env-utils.js.map +1 -1
  17. package/dist/src/error-utils.d.ts +23 -2
  18. package/dist/src/error-utils.js +95 -105
  19. package/dist/src/error-utils.js.map +1 -1
  20. package/dist/src/isset.js +2 -6
  21. package/dist/src/isset.js.map +1 -1
  22. package/dist/src/logger-utils.d.ts +1 -1
  23. package/dist/src/logger-utils.js +139 -268
  24. package/dist/src/logger-utils.js.map +1 -1
  25. package/dist/src/loop-utils.d.ts +1 -1
  26. package/dist/src/loop-utils.js +35 -121
  27. package/dist/src/loop-utils.js.map +1 -1
  28. package/dist/src/math-utils.js +8 -24
  29. package/dist/src/math-utils.js.map +1 -1
  30. package/dist/src/mongo-utils.js +6 -20
  31. package/dist/src/mongo-utils.js.map +1 -1
  32. package/dist/src/object-utils.d.ts +1 -1
  33. package/dist/src/object-utils.js +74 -114
  34. package/dist/src/object-utils.js.map +1 -1
  35. package/dist/src/regexp-utils.js +6 -7
  36. package/dist/src/regexp-utils.js.map +1 -1
  37. package/dist/src/remove-circular-json-stringify.js +4 -5
  38. package/dist/src/remove-circular-json-stringify.js.map +1 -1
  39. package/dist/src/string-utils.d.ts +1 -1
  40. package/dist/src/string-utils.js +49 -107
  41. package/dist/src/string-utils.js.map +1 -1
  42. package/dist/src/tests-utils.d.ts +1 -1
  43. package/dist/src/tests-utils.js +19 -22
  44. package/dist/src/tests-utils.js.map +1 -1
  45. package/dist/src/timer-utils.js +37 -121
  46. package/dist/src/timer-utils.js.map +1 -1
  47. package/dist/src/transaction-utils.js +44 -129
  48. package/dist/src/transaction-utils.js.map +1 -1
  49. package/dist/src/types.d.ts +5 -0
  50. package/dist/src/types.js +3 -0
  51. package/dist/src/types.js.map +1 -0
  52. package/dist/src/validation-utils.d.ts +1 -1
  53. package/dist/src/validation-utils.js +80 -134
  54. package/dist/src/validation-utils.js.map +1 -1
  55. package/dist/src/wtf-utils.js +35 -40
  56. package/dist/src/wtf-utils.js.map +1 -1
  57. package/index.ts +1 -1
  58. package/package.json +4 -4
  59. package/src/clean-stack-trace.ts +40 -0
  60. package/src/config.ts +1 -1
  61. package/src/date-utils.ts +5 -5
  62. package/src/error-utils.ts +86 -44
  63. package/src/logger-utils.ts +2 -2
  64. package/src/loop-utils.ts +1 -1
  65. package/src/object-utils.ts +6 -6
  66. package/src/string-utils.ts +1 -1
  67. package/src/tests-utils.ts +2 -2
  68. package/src/timer-utils.ts +2 -2
  69. package/src/{private/types.ts → types.ts} +0 -0
  70. package/src/validation-utils.ts +8 -8
  71. package/tsconfig.json +1 -1
  72. package/src/private/error-handler.ts +0 -21
@@ -4,18 +4,17 @@
4
4
  //----------------------------------------
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.unComp = exports.compAuto = exports.randomEmoji = exports.chineseProverb = void 0;
7
- var regexp_utils_1 = require("./regexp-utils");
8
- var logger_utils_1 = require("./logger-utils");
9
- var isset_1 = require("./isset");
7
+ const regexp_utils_1 = require("./regexp-utils");
8
+ const logger_utils_1 = require("./logger-utils");
9
+ const isset_1 = require("./isset");
10
10
  function chineseProverb() {
11
11
  // no spoil man
12
- var str = 'Aécrçsçséçséènéopporùunçùyérçdçngéùhàédèngàrouséwçnd$Iù\'sébàùùàréùoébàéwçùhouùéèébookéùhènéùoébàlçàvàéèébookéànùçràly$Aélçùùlàéçmpèùçàncàéwçlléspoçlégràèùéplèns$Tèlkédoàsénoùécookérçcà$Aénààdlàéçsénoùéshèrpéèùéboùhéànds$Thàébàsùéùçmàéùoéplènùéèéùrààéwèsé20éyàèrséègo.éThàésàcondébàsùéùçmàéçséùodèy$Inéèégroupéofémènyéwords,éùhàràéçséboundéùoébàéèémçsùèkàésomàwhàràéçnéùhàm$Pèùçàncàéçséèébçùùàréplènù,ébuùéçùséfruçùéçséswààù$Twoégoodéùèlkàrséèràénoùéworùhéonàégoodélçsùànàr$Aéhundràdéno\'séèràélàsséègonçzçngéùhènéonàéçnsçncàràéyàs$Hàéwhoéchàèùséùhàéàèrùhéwçllébàéchàèùàdébyéùhàéàèrùh';
13
- return ['é ', 'àe', 'èa', 'ùt', 'çi'].reduce(function (s, e) { return s.replace(new RegExp(e[0], 'g'), e[1]); }, str).split('$')[Math.floor(Math.random() * 11)];
12
+ const str = 'Aécrçsçséçséènéopporùunçùyérçdçngéùhàédèngàrouséwçnd$Iù\'sébàùùàréùoébàéwçùhouùéèébookéùhènéùoébàlçàvàéèébookéànùçràly$Aélçùùlàéçmpèùçàncàéwçlléspoçlégràèùéplèns$Tèlkédoàsénoùécookérçcà$Aénààdlàéçsénoùéshèrpéèùéboùhéànds$Thàébàsùéùçmàéùoéplènùéèéùrààéwèsé20éyàèrséègo.éThàésàcondébàsùéùçmàéçséùodèy$Inéèégroupéofémènyéwords,éùhàràéçséboundéùoébàéèémçsùèkàésomàwhàràéçnéùhàm$Pèùçàncàéçséèébçùùàréplènù,ébuùéçùséfruçùéçséswààù$Twoégoodéùèlkàrséèràénoùéworùhéonàégoodélçsùànàr$Aéhundràdéno\'séèràélàsséègonçzçngéùhènéonàéçnsçncàràéyàs$Hàéwhoéchàèùséùhàéàèrùhéwçllébàéchàèùàdébyéùhàéàèrùh';
13
+ return ['é ', 'àe', 'èa', 'ùt', 'çi'].reduce((s, e) => s.replace(new RegExp(e[0], 'g'), e[1]), str).split('$')[Math.floor(Math.random() * 11)];
14
14
  }
15
15
  exports.chineseProverb = chineseProverb;
16
- function randomEmoji(msg, length) {
17
- if (length === void 0) { length = 20; }
18
- var o = "\u0298\u203F\u0298\u00A7\u0CA0_\u0CA0\u00A7(\uFF61\u25D5\u203F\u25D5\uFF61)\u00A7\uFF08\u3000\uFF9F\u0414\uFF9F\uFF09\u00A7(\u256C \u0CA0\u76CA\u0CA0)\u00A7\u0CA0\u203F\u0CA0\u00A7( \u0361\u00B0 \u035C\u0296 \u0361\u00B0)\u00A7\u0CA5_\u0CA5\u00A7\u0CA5\uFE4F\u0CA5\u00A7\u2299\uFE4F\u2299\u00A7\u00B0\u203F\u203F\u00B0\u00A7(\u00B4\uFF65_\uFF65`)\u00A7\u0C20_\u0C20\u00A7(\u2299_\u25CE)\u00A7\u30DF\u25CF\uFE4F\u2609\u30DF\u00A7(\u0CA5\u2323\u0CA5)\u00A7(\u0E51\u2022\u0301 \u2083 \u2022\u0300\u0E51)\u00A7\u25D4_\u25D4\u00A7\u2665\u203F\u2665\u00A7( \u02D8 \u00B3\u02D8)\u2665\u00A7( \u02C7\u0DF4\u02C7 )\u00A7(\u0482\u25E1_\u25E1)\u00A7\u2940.\u2940\u00A7(\u2A7E\uFE4F\u2A7D)\u00A7( \u0C20 \u035F\u0296 \u0C20)\u00A7( \u0361\u0CA0 \u0296\u032F \u0361\u0CA0)\u00A7( \u0CA0 \u0296\u032F \u0CA0)\u00A7\u2668_\u2668\u00A7(._.)\u00A7\uB208_\uB208\u00A7(\u25E0\uFE4F\u25E0)\u00A7\u25D6\u1D54\u1D25\u1D54\u25D7 \u266A \u266B\u00A7{\u2022\u0303_\u2022\u0303}\u00A7(\u1D54\u1D25\u1D54)\u00A7(\u053E\u2038 \u053E)\u00A7\u00AF\\_(\u30C4)_/\u00AF\u00A7\u00AF\\(\u00B0_o)/\u00AF\u00A7\u00AF\\_(\u2299\uFE3F\u2299)_/\u00AF\u00A7\u0505(\u2256\u203F\u2256\u0505)\u00A7\u10DA(\uFF40\u30FC\u00B4\u10DA)\u00A7\u261C(\u2312\u25BD\u2312)\u261E\u00A7\u30FD(\u00B4\u25BD`)/\u00A7\u30FD(\u00B4\u30FC\uFF40)\u30CE\u00A7\u1559(\u21C0\u2038\u21BC\u2036)\u1557\u00A7\u1566(\u00F2_\u00F3\u02C7)\u1564\u00A7\u2282(\u25C9\u203F\u25C9)\u3064\u00A7q(\u2742\u203F\u2742)p\u00A7\u00BF\u24E7_\u24E7\uFB8C\u00A7(\u2299.\u2609)\u00A7\u0449\uFF08\uFF9F\u0414\uFF9F\u0449\uFF09\u00A7\u0669(\u0E4F_\u0E4F)\u06F6\u00A7t(-_-t)\u00A7(\u3065\uFFE3 \u00B3\uFFE3)\u3065\u00A7(\u3065\uFF61\u25D5\u203F\u203F\u25D5\uFF61)\u3065\u00A7\u201C\u30FD(\u00B4\u25BD\uFF40)\u30CE\u201D\u00A7\u250C(\u3186\u3268\u3186)\u0283\u00A7(\u2283\uFF61\u2022\u0301\u203F\u2022\u0300\uFF61)\u2283\u00A7(\u3063\u02D8\u06A1\u02D8\u03C2)\u00A7(\u0E07\u30C4)\u0E27\u00A7\u30FE(-_- )\u309E\u00A7\u266A\u266A \u30FD(\u02C7\u2200\u02C7 )\u309E\u00A7\u30FE(\u00B4\u3007`)\uFF89\u266A\u266A\u266A\u00A7(\u3063\u2580\u00AF\u2580)\u3064\u00A7(\u00B4\u0436\uFF40\u03C2)\u00A7(\u00B0 \u035C\u0296\u0361\u00B0)\u256D\u2229\u256E\u00A7\u062D(\u2022\u0300\u0436\u2022\u0301)\u0E07 \u2020\u00A7~(^-^)~\u00A7\\(\u1D54\u1D55\u1D54)/\u00A7\u10DA(\u2022\u0301\u2022\u0301\u10DA)\u00A7(\u0E07\u2019\u0300-\u2018\u0301)\u0E07\u00A7(\u2022\u0300\u1D17\u2022\u0301)\u0648 \u0311\u0311\u00A7[\u00AC\u00BA-\u00B0]\u00AC\u00A7(\u261E\uFF9F\u30EE\uFF9F)\u261E\u00A7\u00BB\u2310(\u0CA0\u06FE\u0CA0)\u00AC \u00BB\u2019\u00A7(\u3063\u2022\u0301\uFF61\u2022\u0301)\u266A\u266C\u00A7\u01AA(\u0693\u05F2)\u200E\u01AA\u200B\u200B\u00A7\u0295\u2022\u1D25\u2022\u0294\u00A7\u0295\u1D54\u1D25\u1D54\u0294\u00A7\u0295 \u2022`\u1D25\u2022\u00B4\u0294\u00A7\u0295 \u2022\u0301\u0608\u2022\u0300 \u208E\u00A7(`\uFF65\u03C9\uFF65\u00B4)\u00A7\u1D52\u1D25\u1D52\u00A7V\u2022\u1D25\u2022V\u00A7\u0E05^\u2022\uFECC\u2022^\u0E05\u00A7( \u0C20\u0D60\u0C20 )\uFF89\u00A7\u0295\u0298\u0305\u035C\u0298\u0305\u0294\u00A7\u062D\u02DA\u0BF0\u02DA\u3065\u00A7(\u256F\u00B0\u25A1\u00B0\uFF09\u256F\uFE35 \u253B\u2501\u253B\u00A7\u252C\u2500\u252C\uFEFF \u30CE( \u309C-\u309C\u30CE)\u00A7\u252C\u2500\u252C\u20F0\u0361\u2007(\u1D54\u1D55\u1D54\u035C\u2007)\u00A7\u253B\u2501\u253B \uFE35\u30FD(`\u0414\u00B4)\uFF89\uFE35\uFEFF \u253B\u2501\u253B\u00A7(\u30CE\u0CA0 \u2229\u0CA0)\u30CE\u5F61( \\o\u00B0o)\\\u00A7\uFF08 ^_^\uFF09o\u81EA\u81EAo\uFF08^_^ \uFF09\u00A7\u0F3C\u2235\u0F3D\u00A7\u0F3C\u2368\u0F3D\u00A7\u0F3C\u2362\u0F3D\u00A7\u0F3C\u2364\u0F3D\u00A7\u30FD\u0F3C \u0CA0\u76CA\u0CA0 \u0F3D\uFF89\u00A7\u4E41( \u25D4 \u0C6A\u25D4)\u300C\u00A7(\u2229\uFF40-\u00B4)\u2283\u2501\u2606\uFF9F.*\uFF65\uFF61\uFF9F".split('§')[Math.floor(Math.random() * 100)];
16
+ function randomEmoji(msg, length = 20) {
17
+ const o = `\u0298\u203f\u0298§\u0ca0\u005f\u0ca0§\u0028\uff61\u25d5\u203f\u25d5\uff61\u0029§\uff08\u3000\uff9f\u0414\uff9f\uff09§\u0028\u256c\u0020\u0ca0\u76ca\u0ca0\u0029§\u0ca0\u203f\u0ca0§\u0028\u0020\u0361\u00b0\u0020\u035c\u0296\u0020\u0361\u00b0\u0029§\u0ca5\u005f\u0ca5§\u0ca5\ufe4f\u0ca5§\u2299\ufe4f\u2299§\u00b0\u203f\u203f\u00b0§\u0028\u00b4\uff65\u005f\uff65\u0060\u0029§\u0c20\u005f\u0c20§\u0028\u2299\u005f\u25ce\u0029§\u30df\u25cf\ufe4f\u2609\u30df§\u0028\u0ca5\u2323\u0ca5\u0029§\u0028\u0e51\u2022\u0301\u0020\u2083\u0020\u2022\u0300\u0e51\u0029§\u25d4\u005f\u25d4§\u2665\u203f\u2665§\u0028\u0020\u02d8\u0020\u00b3\u02d8\u0029\u2665§\u0028\u0020\u02c7\u0df4\u02c7\u0020\u0029§\u0028\u0482\u25e1\u005f\u25e1\u0029§\u2940\u002e\u2940§\u0028\u2a7e\ufe4f\u2a7d\u0029§\u0028\u0020\u0c20\u0020\u035f\u0296\u0020\u0c20\u0029§\u0028\u0020\u0361\u0ca0\u0020\u0296\u032f\u0020\u0361\u0ca0\u0029§\u0028\u0020\u0ca0\u0020\u0296\u032f\u0020\u0ca0\u0029§\u2668\u005f\u2668§\u0028\u002e\u005f\u002e\u0029§\ub208\u005f\ub208§\u0028\u25e0\ufe4f\u25e0\u0029§\u25d6\u1d54\u1d25\u1d54\u25d7\u0020\u266a\u0020\u266b§\u007b\u2022\u0303\u005f\u2022\u0303\u007d§\u0028\u1d54\u1d25\u1d54\u0029§\u0028\u053e\u2038\u0020\u053e\u0029§\u00af\u005c\u005f\u0028\u30c4\u0029\u005f\u002f\u00af§\u00af\u005c\u0028\u00b0\u005f\u006f\u0029\u002f\u00af§\u00af\u005c\u005f\u0028\u2299\ufe3f\u2299\u0029\u005f\u002f\u00af§\u0505\u0028\u2256\u203f\u2256\u0505\u0029§\u10da\u0028\uff40\u30fc\u00b4\u10da\u0029§\u261c\u0028\u2312\u25bd\u2312\u0029\u261e§\u30fd\u0028\u00b4\u25bd\u0060\u0029\u002f§\u30fd\u0028\u00b4\u30fc\uff40\u0029\u30ce§\u1559\u0028\u21c0\u2038\u21bc\u2036\u0029\u1557§\u1566\u0028\u00f2\u005f\u00f3\u02c7\u0029\u1564§\u2282\u0028\u25c9\u203f\u25c9\u0029\u3064§\u0071\u0028\u2742\u203f\u2742\u0029\u0070§\u00bf\u24e7\u005f\u24e7\ufb8c§\u0028\u2299\u002e\u2609\u0029§\u0449\uff08\uff9f\u0414\uff9f\u0449\uff09§\u0669\u0028\u0e4f\u005f\u0e4f\u0029\u06f6§\u0074\u0028\u002d\u005f\u002d\u0074\u0029§\u0028\u3065\uffe3\u0020\u00b3\uffe3\u0029\u3065§\u0028\u3065\uff61\u25d5\u203f\u203f\u25d5\uff61\u0029\u3065§\u201c\u30fd\u0028\u00b4\u25bd\uff40\u0029\u30ce\u201d§\u250c\u0028\u3186\u3268\u3186\u0029\u0283§\u0028\u2283\uff61\u2022\u0301\u203f\u2022\u0300\uff61\u0029\u2283§\u0028\u3063\u02d8\u06a1\u02d8\u03c2\u0029§\u0028\u0e07\u30c4\u0029\u0e27§\u30fe\u0028\u002d\u005f\u002d\u0020\u0029\u309e§\u266a\u266a\u0020\u30fd\u0028\u02c7\u2200\u02c7\u0020\u0029\u309e§\u30fe\u0028\u00b4\u3007\u0060\u0029\uff89\u266a\u266a\u266a§\u0028\u3063\u2580\u00af\u2580\u0029\u3064§\u0028\u00b4\u0436\uff40\u03c2\u0029§\u0028\u00b0\u0020\u035c\u0296\u0361\u00b0\u0029\u256d\u2229\u256e§\u062d\u0028\u2022\u0300\u0436\u2022\u0301\u0029\u0e07\u0020\u2020§\u007e\u0028\u005e\u002d\u005e\u0029\u007e§\u005c\u0028\u1d54\u1d55\u1d54\u0029\u002f§\u10da\u0028\u2022\u0301\u2022\u0301\u10da\u0029§\u0028\u0e07\u2019\u0300\u002d\u2018\u0301\u0029\u0e07§\u0028\u2022\u0300\u1d17\u2022\u0301\u0029\u0648\u0020\u0311\u0311§\u005b\u00ac\u00ba\u002d\u00b0\u005d\u00ac§\u0028\u261e\uff9f\u30ee\uff9f\u0029\u261e§\u00bb\u2310\u0028\u0ca0\u06fe\u0ca0\u0029\u00ac\u0020\u00bb\u2019§\u0028\u3063\u2022\u0301\uff61\u2022\u0301\u0029\u266a\u266c§\u01aa\u0028\u0693\u05f2\u0029\u200e\u01aa\u200b\u200b§\u0295\u2022\u1d25\u2022\u0294§\u0295\u1d54\u1d25\u1d54\u0294§\u0295\u0020\u2022\u0060\u1d25\u2022\u00b4\u0294§\u0295\u0020\u2022\u0301\u0608\u2022\u0300\u0020\u208e§\u0028\u0060\uff65\u03c9\uff65\u00b4\u0029§\u1d52\u1d25\u1d52§\u0056\u2022\u1d25\u2022\u0056§\u0e05\u005e\u2022\ufecc\u2022\u005e\u0e05§\u0028\u0020\u0c20\u0d60\u0c20\u0020\u0029\uff89§\u0295\u0298\u0305\u035c\u0298\u0305\u0294§\u062d\u02da\u0bf0\u02da\u3065§\u0028\u256f\u00b0\u25a1\u00b0\uff09\u256f\ufe35\u0020\u253b\u2501\u253b§\u252c\u2500\u252c\ufeff\u0020\u30ce\u0028\u0020\u309c\u002d\u309c\u30ce\u0029§\u252c\u2500\u252c\u20f0\u0361\u2007\u0028\u1d54\u1d55\u1d54\u035c\u2007\u0029§\u253b\u2501\u253b\u0020\ufe35\u30fd\u0028\u0060\u0414\u00b4\u0029\uff89\ufe35\ufeff\u0020\u253b\u2501\u253b§\u0028\u30ce\u0ca0\u0020\u2229\u0ca0\u0029\u30ce\u5f61\u0028\u0020\u005c\u006f\u00b0\u006f\u0029\u005c§\uff08\u0020\u005e\u005f\u005e\uff09\u006f\u81ea\u81ea\u006f\uff08\u005e\u005f\u005e\u0020\uff09§\u0f3c\u2235\u0f3d§\u0f3c\u2368\u0f3d§\u0f3c\u2362\u0f3d§\u0f3c\u2364\u0f3d§\u30fd\u0f3c\u0020\u0ca0\u76ca\u0ca0\u0020\u0f3d\uff89§\u4e41\u0028\u0020\u25d4\u0020\u0c6a\u25d4\u0029\u300c§\u0028\u2229\uff40\u002d\u00b4\u0029\u2283\u2501\u2606\uff9f\u002e\u002a\uff65\uff61\uff9f`.split('§')[Math.floor(Math.random() * 100)];
19
18
  return o.padEnd(length, ' ') + (msg ? '< ' + msg : '');
20
19
  }
21
20
  exports.randomEmoji = randomEmoji;
@@ -23,64 +22,60 @@ exports.randomEmoji = randomEmoji;
23
22
  * peut facilement être utilisé par uncomp directement (stock les metadonnées sur la comp)
24
23
  */
25
24
  function compAuto(str) {
26
- var oldStrLength = str.length;
27
- var utf8Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:;<=>%?@"#$&\'()*+,-./[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f€\u0081‚ƒ„…†‡ˆ‰Š‹ŒŽ\u008f‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŹźŻżſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƓƔƕƖƗƘƙƚƛƜƝƞƟ'.split('');
28
- var unusedChars = utf8Chars.filter(function (c) { return !str.includes(c); });
29
- var charMap = [];
30
- var mostFreqStr = function (str2) {
31
- var o = {};
25
+ const oldStrLength = str.length;
26
+ const utf8Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:;<=>%?@"#$&\'()*+,-./[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f€\u0081‚ƒ„…†‡ˆ‰Š‹ŒŽ\u008f‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŹźŻżſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƓƔƕƖƗƘƙƚƛƜƝƞƟ'.split('');
27
+ const unusedChars = utf8Chars.filter(c => !str.includes(c));
28
+ const charMap = [];
29
+ const mostFreqStr = str2 => {
30
+ const o = {};
32
31
  // recherche la meilleure optim selon le nb de char
33
- for (var strLength = 2; strLength < 16; strLength++) {
34
- for (var i = 0; (0, isset_1.isset)(str2[i + strLength - 1]); i++) {
35
- var s = '';
32
+ for (let strLength = 2; strLength < 16; strLength++) {
33
+ for (let i = 0; (0, isset_1.isset)(str2[i + strLength - 1]); i++) {
34
+ let s = '';
36
35
  while (s.length < strLength)
37
36
  s += str2[i + s.length];
38
37
  o[s] = !(0, isset_1.isset)(o[s]) ? -2 : o[s] + strLength - 1; // nb of char economised (the first == -2 because this is space for mapping)
39
38
  }
40
39
  }
41
40
  return Object.keys(o) // {'aa':12, 'ab':8}
42
- .filter(function (subStr) { return o[subStr] > subStr.length + 2; }) // will not be comp if charEconomised != substr.length
43
- .sort(function (a, b) { return o[b] - o[a]; })[0];
41
+ .filter(subStr => o[subStr] > subStr.length + 2) // will not be comp if charEconomised != substr.length
42
+ .sort((a, b) => o[b] - o[a])[0];
44
43
  };
45
44
  // on trouve les [deepness] double char les plus représentés ['aa', 'bb'...]
46
45
  // on les remplace le nb de [recursion], ce qui permet de remplacer des remplacements
47
- var strLengthBefore;
46
+ let strLengthBefore;
48
47
  while (strLengthBefore !== str.length && unusedChars.length > 0) {
49
48
  strLengthBefore = str.length;
50
- var toReplace = mostFreqStr(str);
49
+ const toReplace = mostFreqStr(str);
51
50
  if ((0, isset_1.isset)(toReplace)) {
52
- var char = unusedChars.shift();
53
- charMap.push({ char: char, replacement: toReplace }); // { ù: 'aa' }
51
+ const char = unusedChars.shift();
52
+ charMap.push({ char, replacement: toReplace }); // { ù: 'aa' }
54
53
  str = str.replace(new RegExp((0, regexp_utils_1.escapeRegexp)(toReplace), 'g'), char);
55
54
  }
56
55
  }
57
- for (var _i = 0, charMap_1 = charMap; _i < charMap_1.length; _i++) {
58
- var _a = charMap_1[_i], char = _a.char, replacement = _a.replacement;
56
+ for (const { char, replacement } of charMap) {
59
57
  // rrrr => rƠ4
60
- var reg = replacement.length > 3 && replacement.split('').every(function (char2, i, a) { return char2 == a[0]; }) ? "".concat(replacement[0], "\u01A0").concat(replacement.length) : replacement;
61
- str = "".concat(char).concat(reg, "\u00A7") + str;
58
+ const reg = replacement.length > 3 && replacement.split('').every((char2, i, a) => char2 == a[0]) ? `${replacement[0]}Ơ${replacement.length}` : replacement;
59
+ str = `${char}${reg}§` + str;
62
60
  }
63
- logger_utils_1.C.info("COMP percentage: ".concat(Math.round((str.length / oldStrLength) * 100), "% of its original size"));
61
+ logger_utils_1.C.info(`COMP percentage: ${Math.round((str.length / oldStrLength) * 100)}% of its original size`);
64
62
  return str;
65
63
  }
66
64
  exports.compAuto = compAuto;
67
65
  function unComp(str) {
68
- var charMap = [];
69
- var map = str.split('§');
66
+ const charMap = [];
67
+ const map = str.split('§');
70
68
  str = map.pop();
71
- map.forEach(function (e) {
72
- var char = e[0];
73
- var replacement = e.substring(1, 999);
69
+ map.forEach(e => {
70
+ let char = e[0];
71
+ let replacement = e.substring(1, 999);
74
72
  if (replacement.includes('Ơ')) {
75
- var _a = replacement.split('Ơ'), char_1 = _a[0], nb = _a[1];
76
- replacement = char_1.repeat(nb);
73
+ const [char, nb] = replacement.split('Ơ');
74
+ replacement = char.repeat(nb);
77
75
  }
78
- charMap.push({ char: char, replacement: replacement });
76
+ charMap.push({ char, replacement });
79
77
  });
80
- charMap.forEach(function (_a) {
81
- var char = _a.char, replacement = _a.replacement;
82
- return str = str.replace(new RegExp((0, regexp_utils_1.escapeRegexp)(char), 'g'), replacement);
83
- } // regexp excape
78
+ charMap.forEach(({ char, replacement }) => str = str.replace(new RegExp((0, regexp_utils_1.escapeRegexp)(char), 'g'), replacement) // regexp excape
84
79
  );
85
80
  return str;
86
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wtf-utils.js","sourceRoot":"","sources":["../../src/wtf-utils.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,YAAY;AACZ,0CAA0C;;;AAE1C,+CAA6C;AAC7C,+CAAkC;AAClC,iCAA+B;AAE/B,SAAgB,cAAc;IAC1B,eAAe;IACf,IAAM,GAAG,GAAG,0kBAA0kB,CAAA;IACtlB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAtC,CAAsC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,G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GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAA,2BAAY,EAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,gBAAgB;KACvF,CAAA;IAED,OAAO,GAAG,CAAA;AACd,CAAC;AAnBD,wBAmBC"}
package/index.ts CHANGED
@@ -17,7 +17,7 @@ export * from './src/is-empty'
17
17
  export * from './src/remove-circular-json-stringify'
18
18
  export * from './src/is-object'
19
19
  export * from './src/regexp-utils'
20
- export * from './src/private/error-handler'
20
+ export * from './src/clean-stack-trace'
21
21
  export { registerConfig } from './src/config'
22
22
 
23
23
  import { moyenne } from './src/math-utils'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.1.14",
3
+ "version": "1.2.2",
4
4
  "type": "commonjs",
5
5
  "types": "index.ts",
6
6
  "private": false,
@@ -19,9 +19,9 @@
19
19
  "bump:patch": "npm run build & node node_modules/bump-simple/bump-simple.js --patch"
20
20
  },
21
21
  "devDependencies": {
22
- "@types/node": "^16.11.6",
22
+ "@types/node": "^18.11.18",
23
+ "bump-simple": "^1.0.0",
23
24
  "eslint": "^8.0.0",
24
- "typescript": "^4.4.4",
25
- "bump-simple": "^1.0.0"
25
+ "typescript": "^4.4.4"
26
26
  }
27
27
  }
@@ -0,0 +1,40 @@
1
+
2
+ export function cleanStackTrace(stack) {
3
+ if (typeof stack !== 'string') return ''
4
+ stack.replace(/home\/[^/]+\/[^/]+\//g, '')
5
+ const lines = stack.split('\n')
6
+ const removeIfContain = [
7
+ 'logger-utils.js',
8
+ 'TCP.onread',
9
+ 'readableAddChunk',
10
+ 'Socket.EventEmitter.emit (domain.js',
11
+ 'Socket.emit (events.js',
12
+ 'Connection.EventEmitter.emit (domain.js',
13
+ 'Connection.emit (events.js',
14
+ 'Socket.Readable.push (_stream_readable',
15
+ 'model.Query',
16
+ 'Object.promiseOrCallback',
17
+ 'Connection.<anonymous>',
18
+ 'process.topLevelDomainCallback',
19
+ // internal
20
+ 'internal/process',
21
+ 'internal/timers',
22
+ 'internal/modules',
23
+ 'internal/main',
24
+ 'DefaultError.throw',
25
+ 'Object.throw',
26
+ 'mongoose/lib/utils',
27
+ 'at Array.forEach (<anonymous>)',
28
+ ]
29
+ const linesClean = lines
30
+ .map((line, i) => {
31
+ if (i === 0) return ''
32
+ else {
33
+ const [, start, fileName, end] = line.match(/(^.+\/)([^/]+:\d+:\d+)(.{0,3})/) || []
34
+ return fileName ? `\x1b[2m${start}\x1b[0m${fileName}\x1b[2m${end}\x1b[0m` : `\x1b[2m${line}\x1b[0m`
35
+ }
36
+ })
37
+ .filter(l => l && !removeIfContain.some(text => l.includes(text)))
38
+ .join('\n')
39
+ return linesClean
40
+ }
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Color } from './private/types'
1
+ import { Color } from './types'
2
2
  import { isset } from './isset'
3
3
 
4
4
  export type TopkatUtilConfig = {
package/src/date-utils.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  //----------------------------------------
4
4
  import { isset } from "./isset"
5
5
  import { pad } from "./math-utils"
6
- import { dataValidationUtilErrorHandler } from "./private/error-handler"
6
+ import { DescriptiveError } from "./error-utils"
7
7
  import { err422IfNotSet } from "./error-utils"
8
8
 
9
9
  const int = parseInt
@@ -154,7 +154,7 @@ export function isTimeStringValid(timeStr, outputAnError$ = false) {
154
154
  let m = int(timeArr[1])
155
155
  let test1 = h >= 0 && h < 24
156
156
  let test2 = m >= 0 && m < 60
157
- if (outputAnError$ && !(test1 && test2)) throw new dataValidationUtilErrorHandler('timeStringOutOfRange', 422, { origin: 'Time validator' })
157
+ if (outputAnError$ && !(test1 && test2)) throw new DescriptiveError('timeStringOutOfRange', { code: 422, origin: 'Time validator' })
158
158
  else return test1 && test2
159
159
  }
160
160
 
@@ -351,7 +351,7 @@ export function isDateIntOrStringValid(dateStringOrInt, outputAnError = false, l
351
351
  if (!isset(dateStringOrInt)) return false
352
352
  const dateStr = dateStringOrInt.toString()
353
353
 
354
- if (length && dateStr.length !== length) throw new dataValidationUtilErrorHandler(`wrongLengthForDateInt`, 422, { origin: 'Date Int validator', dateStringOrInt: dateStringOrInt, extraInfo: `${dateStringOrInt} length !== ${length}` })
354
+ if (length && dateStr.length !== length) throw new DescriptiveError(`wrongLengthForDateInt`, { code: 422, origin: 'Date Int validator', dateStringOrInt: dateStringOrInt, extraInfo: `${dateStringOrInt} length !== ${length}` })
355
355
 
356
356
  if ((typeof dateStringOrInt === 'object' && isNaN(int(dateStr))) || ![4, 6, 8, 10, 12, 17].includes(dateStr.length)) return false
357
357
 
@@ -364,7 +364,7 @@ export function isDateIntOrStringValid(dateStringOrInt, outputAnError = false, l
364
364
  const test4 = !isset(h) || (int(h) <= 23 && int(h) >= 0) // H
365
365
  const test5 = !isset(m) || (int(m) <= 59 && int(m) >= 0) // M
366
366
 
367
- if (outputAnError && !(test1 && test2 && test3 && test4 && test5)) throw new dataValidationUtilErrorHandler(`dateStringOrIntFormatInvalid`, 422, { origin: 'Date Int validator', dateStringOrInt: dateStringOrInt, extraInfo: 'Needs YYYYMMDD[HHMM] between 100001010000 and 999912312359', dateArr, isYearValid: test1, isMonthValid: test2, isDayValid: test3, isHourValid: test4, isMinutesValid: test5 })
367
+ if (outputAnError && !(test1 && test2 && test3 && test4 && test5)) throw new DescriptiveError(`dateStringOrIntFormatInvalid`, { code: 422, origin: 'Date Int validator', dateStringOrInt: dateStringOrInt, extraInfo: 'Needs YYYYMMDD[HHMM] between 100001010000 and 999912312359', dateArr, isYearValid: test1, isMonthValid: test2, isDayValid: test3, isHourValid: test4, isMinutesValid: test5 })
368
368
  return true
369
369
  }
370
370
 
@@ -372,6 +372,6 @@ export function isDateIsoOrObjectValid(dateIsoOrObj, outputAnError = false) {
372
372
  let dateObj: Date | number | string = dateIsoOrObj
373
373
  if (typeof dateIsoOrObj === 'string') dateObj = new Date(dateIsoOrObj)
374
374
  let valid = dateObj instanceof Date
375
- if (outputAnError && !valid) throw new dataValidationUtilErrorHandler('dateIsoStringOrObjectIsNotValid', 422, { origin: 'Date Object validator', isoDate: dateIsoOrObj })
375
+ if (outputAnError && !valid) throw new DescriptiveError('dateIsoStringOrObjectIsNotValid', { code: 422, origin: 'Date Object validator', isoDate: dateIsoOrObj })
376
376
  return valid
377
377
  }
@@ -1,11 +1,13 @@
1
1
  //----------------------------------------
2
2
  // ERROR UTILS
3
3
  //----------------------------------------
4
- import { dataValidationUtilErrorHandler } from "./private/error-handler"
5
4
  import { isset } from "./isset"
6
5
  import { isEmpty } from "./is-empty"
6
+ import { ObjectGeneric } from "./types"
7
+ import { cleanStackTrace } from "./clean-stack-trace"
8
+ import { C } from "./logger-utils"
7
9
 
8
- export function errIfNotSet(objOfVarNamesWithValues, additionalMessage) { return errXXXIfNotSet(422, false, objOfVarNamesWithValues) }
10
+ export function errIfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(422, false, objOfVarNamesWithValues) }
9
11
 
10
12
  export function err500IfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(500, false, objOfVarNamesWithValues) }
11
13
 
@@ -18,54 +20,14 @@ export function errXXXIfNotSet(errCode, checkEmpty, objOfVarNamesWithValues) {
18
20
  for (let prop in objOfVarNamesWithValues) {
19
21
  if (!isset(objOfVarNamesWithValues[prop]) || (checkEmpty && isEmpty(objOfVarNamesWithValues[prop]))) missingVars.push(prop)
20
22
  }
21
- if (missingVars.length) throw new dataValidationUtilErrorHandler(`requiredVariableEmptyOrNotSet`, errCode, { origin: 'Validator', varNames: missingVars.join(', ') })
23
+ if (missingVars.length) throw new DescriptiveError(`requiredVariableEmptyOrNotSet`, { code: errCode, origin: 'Validator', varNames: missingVars.join(', ') })
22
24
  }
23
25
 
24
26
 
25
27
  export function err422IfNotSet(o) {
26
28
  let m = []
27
29
  for (let p in o) if (!isset(o[p])) m.push(p)
28
- if (m.length) throw new dataValidationUtilErrorHandler(`requiredVariableEmptyOrNotSet`, 422, { origin: 'Validator', varNames: m.join(', ') })
29
- }
30
-
31
- export function cleanStackTrace(stack) {
32
- if (typeof stack !== 'string') return ''
33
- stack.replace(/home\/[^/]+\/[^/]+\//g, '')
34
- const lines = stack.split('\n')
35
- const removeIfContain = [
36
- 'logger-utils.js',
37
- 'TCP.onread',
38
- 'readableAddChunk',
39
- 'Socket.EventEmitter.emit (domain.js',
40
- 'Socket.emit (events.js',
41
- 'Connection.EventEmitter.emit (domain.js',
42
- 'Connection.emit (events.js',
43
- 'Socket.Readable.push (_stream_readable',
44
- 'model.Query',
45
- 'Object.promiseOrCallback',
46
- 'Connection.<anonymous>',
47
- 'process.topLevelDomainCallback',
48
- // internal
49
- 'internal/process',
50
- 'internal/timers',
51
- 'internal/modules',
52
- 'internal/main',
53
- 'DefaultError.throw',
54
- 'Object.throw',
55
- 'mongoose/lib/utils',
56
- 'at Array.forEach (<anonymous>)',
57
- ]
58
- const linesClean = lines
59
- .map((line, i) => {
60
- if (i === 0) return ''
61
- else {
62
- const [, start, fileName, end] = line.match(/(^.+\/)([^/]+:\d+:\d+)(.{0,3})/) || []
63
- return fileName ? `\x1b[2m${start}\x1b[0m${fileName}\x1b[2m${end}\x1b[0m` : `\x1b[2m${line}\x1b[0m`
64
- }
65
- })
66
- .filter(l => l && !removeIfContain.some(text => l.includes(text)))
67
- .join('\n')
68
- return linesClean
30
+ if (m.length) throw new DescriptiveError(`requiredVariableEmptyOrNotSet`, { code: 422, origin: 'Validator', varNames: m.join(', ') })
69
31
  }
70
32
 
71
33
  export async function tryCatch(callback: Function, onErr: Function = () => { }) {
@@ -74,4 +36,84 @@ export async function tryCatch(callback: Function, onErr: Function = () => { })
74
36
  } catch (err) {
75
37
  return await onErr(err)
76
38
  }
39
+ }
40
+
41
+
42
+ export type ErrorOptions = {
43
+ err?: any
44
+ doNotThrow?: boolean
45
+ code?: number
46
+ notifyOnSlackChannel?: boolean
47
+ extraInfosRenderer?: (extraInfosObj: ObjectGeneric) => void
48
+ doNotWaitOneFrameForLog?: boolean
49
+ [k: string]: any
50
+ }
51
+
52
+ function extraInfosRendererDefault(extraInfos) {
53
+ C.error(false, '== EXTRA INFOS ==')
54
+ C.error(false, JSON.stringify(extraInfos, null, 2))
55
+ }
56
+
57
+ export class DescriptiveError extends Error {
58
+ errorDescription: { [k: string]: any }
59
+ code: number
60
+ msg: string
61
+ options: ErrorOptions
62
+ hasBeenLogged: boolean
63
+
64
+ constructor(msg: string, options: ErrorOptions = {}) {
65
+ super(msg)
66
+ delete options.errMsgId
67
+ this.msg = msg
68
+ const { doNotWaitOneFrameForLog = false, ...optionsClean } = options
69
+ this.options = optionsClean
70
+ if (optionsClean.err) optionsClean.err.hasBeenLogged = true
71
+ this.hasBeenLogged = false
72
+ if (doNotWaitOneFrameForLog) this.log()
73
+ else setTimeout(() => {
74
+ if (!this.hasBeenLogged) this.log() // wait one event loop to see if not catched
75
+ })
76
+ }
77
+ log(doNotCountHasLogged = false) {
78
+ if (!this.hasBeenLogged) {
79
+ const { err, doNotThrow = false, ressource, extraInfosRenderer = extraInfosRendererDefault, notifyOnSlackChannel = false, originalMessage, ...extraInfosRaw } = this.options
80
+ let { code } = this.options
81
+ const extraInfos = { ...extraInfosRaw, ...(this.options.extraInfos || {}) }
82
+
83
+ if (!isset(extraInfos.value) && this.options.hasOwnProperty('value')) extraInfos.value = 'undefined'
84
+ if (!isset(extraInfos.gotValue) && this.options.hasOwnProperty('gotValue')) extraInfos.gotValue = 'undefined'
85
+
86
+ if (isset(ressource)) {
87
+ code = 404
88
+ if (this.msg === '404') this.msg = `Ressource ${ressource} not found`
89
+ extraInfos.ressource = ressource
90
+ }
91
+
92
+ C.error(false, this.msg || this.message)
93
+ if (Object.keys(extraInfos).length > 0) extraInfosRenderer(extraInfos)
94
+ if (err) {
95
+ C.error(false, '== ORIGINAL ERROR ==')
96
+ if (err.log) {
97
+ err.hasBeenLogged = false
98
+ err.log()
99
+ } else {
100
+ C.error(err)
101
+ if (err.extraInfos) C.error(false, err.extraInfos)
102
+ }
103
+ } else {
104
+ C.error(false, C.dim(cleanStackTrace(extraInfosRaw.stack || this.stack)))
105
+ }
106
+ this.code = code || 500
107
+ this.errorDescription = {
108
+ msg: this.msg,
109
+ code,
110
+ ressource,
111
+ ...extraInfos,
112
+ }
113
+ }
114
+ if (!doNotCountHasLogged) this.hasBeenLogged = true
115
+ }
116
+ toString() {
117
+ return this.log(true)
118
+ }
77
119
  }
@@ -3,9 +3,9 @@
3
3
  //----------------------------------------
4
4
  import { configFn } from "./config"
5
5
  import { isset } from "./isset"
6
- import { Color } from "./private/types"
6
+ import { Color } from "./types"
7
7
  import { removeCircularJSONstringify } from "./remove-circular-json-stringify"
8
- import { cleanStackTrace } from "./error-utils"
8
+ import { cleanStackTrace } from "./clean-stack-trace"
9
9
 
10
10
  export const logger = {
11
11
  log(str, type = 'log') {
package/src/loop-utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  //----------------------------------------
2
2
  // LOOP UTILS
3
3
  //----------------------------------------
4
- import { ObjectGeneric } from "./private/types"
4
+ import { ObjectGeneric } from "./types"
5
5
  import { err500IfNotSet } from "./error-utils"
6
6
  import { isObject } from "./is-object"
7
7
 
@@ -1,12 +1,12 @@
1
1
  //----------------------------------------
2
2
  // OBJECT UTILS
3
3
  //----------------------------------------
4
- import { ObjectGeneric } from "./private/types"
4
+ import { ObjectGeneric } from "./types"
5
5
  import { err500IfNotSet } from "./error-utils"
6
6
  import { recursiveGenericFunctionSync } from "./loop-utils"
7
7
  import { isset } from "./isset"
8
8
  import { isObject } from "./is-object"
9
- import { dataValidationUtilErrorHandler } from "./private/error-handler"
9
+ import { DescriptiveError } from "./error-utils"
10
10
 
11
11
  /**
12
12
  *
@@ -97,7 +97,7 @@ export function objForceWrite(obj: ObjectGeneric, addr: string, item) {
97
97
  const nextChunk = chunks[i + 1]
98
98
  if (isset(nextChunk) && nextChunk.startsWith('[')) lastItem[chunk] = []
99
99
  else lastItem[chunk] = {}
100
- } else if (typeof lastItem[chunk] !== 'object') throw new dataValidationUtilErrorHandler(`itemNotTypeObjectOrArrayInAddrChainForObjForceWrite`, 500, { origin: 'Validator', chunks, actualValueOfItem: lastItem[chunk], actualChunk: chunk })
100
+ } else if (typeof lastItem[chunk] !== 'object') throw new DescriptiveError(`itemNotTypeObjectOrArrayInAddrChainForObjForceWrite`, { code: 500, origin: 'Validator', chunks, actualValueOfItem: lastItem[chunk], actualChunk: chunk })
101
101
  lastItem = lastItem[chunk]
102
102
  })
103
103
  }
@@ -191,7 +191,7 @@ export function objFilterUndefined(o) {
191
191
 
192
192
  /** Lock all 1st level props of an object to read only */
193
193
  export function readOnly(o) {
194
- const throwErr = () => { throw new dataValidationUtilErrorHandler('Cannot modify object that is read only', 500) }
194
+ const throwErr = () => { throw new DescriptiveError('Cannot modify object that is read only', { code: 500 }) }
195
195
  return new Proxy(o, {
196
196
  set: throwErr,
197
197
  defineProperty: throwErr,
@@ -203,14 +203,14 @@ export function readOnly(o) {
203
203
  export function reassignForbidden(o) {
204
204
  return new Proxy(o, {
205
205
  defineProperty: function (that, key, value) {
206
- if (key in that) throw new dataValidationUtilErrorHandler(`Cannot reassign the property ${key.toString()} of this object`, 500)
206
+ if (key in that) throw new DescriptiveError(`Cannot reassign the property ${key.toString()} of this object`, { code: 500 })
207
207
  else {
208
208
  that[key] = value
209
209
  return true
210
210
  }
211
211
  },
212
212
  deleteProperty: function (_, key) {
213
- throw new dataValidationUtilErrorHandler(`Cannot delete the property ${key.toString()} of this object`, 500)
213
+ throw new DescriptiveError(`Cannot delete the property ${key.toString()} of this object`, { code: 500 })
214
214
  }
215
215
  })
216
216
  }
@@ -2,7 +2,7 @@
2
2
  // STRING UTILS
3
3
  //----------------------------------------
4
4
  import { err500IfEmptyOrNotSet } from "./error-utils"
5
- import { ObjectGeneric } from "./private/types"
5
+ import { ObjectGeneric } from "./types"
6
6
  import { isset } from "./isset"
7
7
 
8
8
  /**Eg: camelCase */
@@ -5,7 +5,7 @@ import { C } from "./logger-utils"
5
5
  import { ValidatorObject } from "./validation-utils"
6
6
  import { isset } from "./isset"
7
7
  import { validatorReturnErrArray } from "./validation-utils"
8
- import { Override } from "./private/types"
8
+ import { Override } from "./types"
9
9
  import { isObject } from "./is-object"
10
10
 
11
11
  export const restTestMini = {
@@ -55,7 +55,7 @@ export function assert(description: string, value: any, validatorObject?: Overri
55
55
  else if (isset(validatorObject)) validatorObjReal.eq = validatorObject
56
56
 
57
57
  const issetCheck = !isset(validatorObjReal) // isEmpty()
58
- const [errMsg, , extraInfos] = validatorReturnErrArray(validatorObjReal)
58
+ const [errMsg, extraInfos] = validatorReturnErrArray(validatorObjReal)
59
59
  const msg2 = description + ` ${issetCheck ? 'isset' : `${JSON.stringify(validatorObject)}`}`
60
60
  if (isset(errMsg)) {
61
61
  const err = msg2 + `\n ${errMsg}\n ${JSON.stringify(extraInfos)}`
@@ -3,7 +3,7 @@
3
3
  // TIMEOUT UTILS
4
4
  //----------------------------------------
5
5
  import { cliProgressBar, C } from "./logger-utils"
6
- import { dataValidationUtilErrorHandler } from "./private/error-handler"
6
+ import { DescriptiveError } from "./error-utils"
7
7
 
8
8
 
9
9
  export async function timeout(ms, fn = () => { }) { return new Promise(res => setTimeout(res, ms)).then(fn) }
@@ -29,7 +29,7 @@ export async function waitUntilTrue(callback, timeoutSec = 10, errorAfterNSecond
29
29
  await timeout(300)
30
30
  }
31
31
  if (cliOutput) process.stdout.write(`\n`)
32
- if (!generalTimeout && errorAfterNSeconds) throw new dataValidationUtilErrorHandler(errMess, 500)
32
+ if (!generalTimeout && errorAfterNSeconds) throw new DescriptiveError(errMess, { code: 500 })
33
33
  }
34
34
 
35
35
 
File without changes