@aitianyu.cn/types 0.0.12 → 0.1.0

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 (87) hide show
  1. package/dist/lib/{utilities/coding → coding}/Error.js +44 -44
  2. package/dist/lib/{utilities/coding → coding}/Path.js +210 -198
  3. package/dist/lib/{utilities/core → core}/Errors.js +86 -86
  4. package/dist/lib/{utilities/core → core}/Language.js +561 -559
  5. package/dist/lib/{utilities/core → core}/Log.js +112 -108
  6. package/dist/lib/{utilities/core → core}/TypeConvertion.js +25 -25
  7. package/dist/lib/{utilities/core → core}/interface/ITJSON.js +3 -3
  8. package/dist/lib/{utilities/core → core}/interface/ITianyuType.js +3 -3
  9. package/dist/lib/{utilities/core → core}/object/ArrayHelper.js +35 -35
  10. package/dist/lib/core/object/Bytes.js +21 -0
  11. package/dist/lib/{utilities/core → core}/object/Calculater.js +240 -230
  12. package/dist/lib/core/object/DataView.js +23 -0
  13. package/dist/lib/core/object/Integer.js +117 -0
  14. package/dist/lib/core/object/Json.js +35 -0
  15. package/dist/lib/{utilities/core/object/Helper.js → core/object/ObjectHelper.js} +202 -201
  16. package/dist/lib/core/object/StringHelper.js +61 -0
  17. package/dist/lib/{utilities/core → core}/type/TArray.js +8 -7
  18. package/dist/lib/{utilities/core → core}/type/TBoolean.js +7 -7
  19. package/dist/lib/{utilities/core → core}/type/TJSON.js +7 -7
  20. package/dist/lib/{utilities/core → core}/type/TNumber.js +7 -7
  21. package/dist/lib/{utilities/core → core}/type/TObject.js +7 -7
  22. package/dist/lib/{utilities/core → core}/type/TString.js +7 -7
  23. package/dist/lib/index.js +70 -54
  24. package/dist/lib/security/Base32.js +104 -0
  25. package/dist/lib/security/Guid.js +26 -0
  26. package/dist/lib/{utilities/security → security}/Hash.js +16 -15
  27. package/dist/lib/security/QRCode.js +46 -0
  28. package/dist/lib/security/RSA.js +62 -0
  29. package/dist/lib/security/SHA.js +67 -0
  30. package/dist/lib/types/AreaCode.js +269 -269
  31. package/dist/lib/types/Exception.js +19 -19
  32. package/dist/lib/types/Logs.js +20 -20
  33. package/dist/lib/types/Object.js +3 -3
  34. package/dist/lib/types/PathBase.js +109 -109
  35. package/dist/lib/types/Security.js +10 -10
  36. package/dist/lib/types/TMap.js +139 -138
  37. package/dist/lib/types/Types.js +3 -3
  38. package/dist/lib/types/index.js +17 -17
  39. package/dist/types/{utilities/coding → coding}/Error.d.ts +27 -27
  40. package/dist/types/{utilities/coding → coding}/Path.d.ts +61 -61
  41. package/dist/types/{utilities/core → core}/Errors.d.ts +47 -47
  42. package/dist/types/{utilities/core → core}/Language.d.ts +17 -17
  43. package/dist/types/{utilities/core → core}/Log.d.ts +12 -12
  44. package/dist/types/{utilities/core → core}/TypeConvertion.d.ts +2 -2
  45. package/dist/types/{utilities/core → core}/interface/ITJSON.d.ts +5 -5
  46. package/dist/types/{utilities/core → core}/interface/ITianyuType.d.ts +5 -5
  47. package/dist/types/{utilities/core → core}/object/ArrayHelper.d.ts +11 -11
  48. package/dist/types/core/object/Bytes.d.ts +13 -0
  49. package/dist/types/{utilities/core → core}/object/Calculater.d.ts +22 -22
  50. package/dist/types/core/object/DataView.d.ts +11 -0
  51. package/dist/types/core/object/Integer.d.ts +71 -0
  52. package/dist/types/core/object/Json.d.ts +22 -0
  53. package/dist/types/{utilities/core/object/Helper.d.ts → core/object/ObjectHelper.d.ts} +39 -39
  54. package/dist/types/core/object/StringHelper.d.ts +21 -0
  55. package/dist/types/{utilities/core → core}/type/TArray.d.ts +3 -3
  56. package/dist/types/{utilities/core → core}/type/TBoolean.d.ts +3 -3
  57. package/dist/types/{utilities/core → core}/type/TJSON.d.ts +3 -3
  58. package/dist/types/{utilities/core → core}/type/TNumber.d.ts +3 -3
  59. package/dist/types/{utilities/core → core}/type/TObject.d.ts +3 -3
  60. package/dist/types/{utilities/core → core}/type/TString.d.ts +3 -3
  61. package/dist/types/index.d.ts +29 -21
  62. package/dist/types/security/Base32.d.ts +42 -0
  63. package/dist/types/security/Guid.d.ts +4 -0
  64. package/dist/types/{utilities/security → security}/Hash.d.ts +3 -3
  65. package/dist/types/security/QRCode.d.ts +11 -0
  66. package/dist/types/security/RSA.d.ts +68 -0
  67. package/dist/types/security/SHA.d.ts +40 -0
  68. package/dist/types/types/AreaCode.d.ts +135 -135
  69. package/dist/types/types/Exception.d.ts +11 -11
  70. package/dist/types/types/Logs.d.ts +64 -64
  71. package/dist/types/types/Object.d.ts +18 -18
  72. package/dist/types/types/PathBase.d.ts +76 -76
  73. package/dist/types/types/Security.d.ts +23 -23
  74. package/dist/types/types/TMap.d.ts +80 -80
  75. package/dist/types/types/Types.d.ts +25 -25
  76. package/dist/types/types/index.d.ts +9 -9
  77. package/package.json +57 -51
  78. package/dist/lib/utilities/coding/index.js +0 -10
  79. package/dist/lib/utilities/core/index.js +0 -21
  80. package/dist/lib/utilities/core/object/StringHelper.js +0 -22
  81. package/dist/lib/utilities/security/Guid.js +0 -20
  82. package/dist/lib/utilities/security/index.js +0 -8
  83. package/dist/types/utilities/coding/index.d.ts +0 -3
  84. package/dist/types/utilities/core/index.d.ts +0 -6
  85. package/dist/types/utilities/core/object/StringHelper.d.ts +0 -4
  86. package/dist/types/utilities/security/Guid.d.ts +0 -3
  87. package/dist/types/utilities/security/index.d.ts +0 -3
@@ -1,108 +1,112 @@
1
- "use strict";
2
- /**@format */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Performance = exports.Log = void 0;
5
- const Logs_1 = require("../../types/Logs");
6
- const Guid_1 = require("../security/Guid");
7
- const _LogLevel = {
8
- DEBUG: { value: 0, name: "DEBUG" },
9
- ERROR: { value: 3, name: "ERROR" },
10
- FATAL: { value: 4, name: "FATAL" },
11
- INFO: { value: 1, name: "INFO" },
12
- WARNING: { value: 2, name: "WARNING" },
13
- LOG: { value: -1, name: "LOG" },
14
- };
15
- function _consoleLog(level, msg, timer) {
16
- if (level.value >= 100) {
17
- console.log(`[${level.name}] ${msg}`);
18
- return;
19
- }
20
- let timeString = "";
21
- if (timer) {
22
- const date = new Date(Date.now());
23
- const millisecondString = date.getMilliseconds().toString();
24
- timeString = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${millisecondString.substring(0, millisecondString.length > 3 ? 3 : millisecondString.length)}]`;
25
- }
26
- const logMessage = `[${level.name}] ${timeString} ${msg}`;
27
- switch (level.value) {
28
- case 0:
29
- console.debug(logMessage);
30
- break;
31
- case 1:
32
- console.info(logMessage);
33
- break;
34
- case 2:
35
- console.warn(logMessage);
36
- break;
37
- case 3:
38
- console.error(logMessage);
39
- break;
40
- case 4:
41
- console.error(logMessage);
42
- break;
43
- default:
44
- console.log(msg);
45
- break;
46
- }
47
- }
48
- const _log = {
49
- log: function (msg, level, timer) {
50
- const logLevel = level ?? Logs_1.LogLevel.INFO;
51
- switch (logLevel) {
52
- case Logs_1.LogLevel.DEBUG:
53
- _consoleLog(_LogLevel["DEBUG"], msg, !!timer);
54
- break;
55
- case Logs_1.LogLevel.WARNING:
56
- _consoleLog(_LogLevel["WARNING"], msg, !!timer);
57
- break;
58
- case Logs_1.LogLevel.ERROR:
59
- _consoleLog(_LogLevel["ERROR"], msg, !!timer);
60
- break;
61
- case Logs_1.LogLevel.FATAL:
62
- _consoleLog(_LogLevel["FATAL"], msg, !!timer);
63
- break;
64
- case Logs_1.LogLevel.INFO:
65
- _consoleLog(_LogLevel["INFO"], msg, !!timer);
66
- break;
67
- default:
68
- _consoleLog(_LogLevel["LOG"], msg, !!timer);
69
- break;
70
- }
71
- },
72
- info: function (msg, timer) {
73
- _consoleLog(_LogLevel["INFO"], msg, !!timer);
74
- },
75
- warn: function (msg, timer) {
76
- _consoleLog(_LogLevel["WARNING"], msg, !!timer);
77
- },
78
- debug: function (msg, timer) {
79
- _consoleLog(_LogLevel["DEBUG"], msg, !!timer);
80
- },
81
- error: function (msg, timer) {
82
- _consoleLog(_LogLevel["ERROR"], msg, !!timer);
83
- },
84
- fatal: function (msg, timer) {
85
- _consoleLog(_LogLevel["FATAL"], msg, !!timer);
86
- },
87
- };
88
- function _startPerf(id) {
89
- return {
90
- id: id || (0, Guid_1.guid)(),
91
- start: Date.now(),
92
- };
93
- }
94
- function _endPerf(recorder, console) {
95
- const perfTime = Date.now() - recorder.start;
96
- if (console) {
97
- const consoleString = `[${recorder.id}] perf time - ${perfTime}`;
98
- _consoleLog({ value: 100, name: "Performance" }, consoleString, false);
99
- }
100
- return perfTime;
101
- }
102
- /** Tianyu Log Instance */
103
- exports.Log = _log;
104
- /** Tianyu Performance Instance */
105
- exports.Performance = {
106
- startPerf: _startPerf,
107
- endPerf: _endPerf,
108
- };
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Performance = exports.Log = void 0;
5
+ const Logs_1 = require("../types/Logs");
6
+ const Guid_1 = require("../security/Guid");
7
+ const _LogLevel = {
8
+ DEBUG: { value: 0, name: "DEBUG" },
9
+ ERROR: { value: 3, name: "ERROR" },
10
+ FATAL: { value: 4, name: "FATAL" },
11
+ INFO: { value: 1, name: "INFO" },
12
+ WARNING: { value: 2, name: "WARNING" },
13
+ LOG: { value: -1, name: "LOG" },
14
+ };
15
+ function _consoleLog(level, msg, timer) {
16
+ if (level.value >= 100) {
17
+ // eslint-disable-next-line no-console
18
+ console.log(`[${level.name}] ${msg}`);
19
+ return;
20
+ }
21
+ let timeString = "";
22
+ if (timer) {
23
+ const date = new Date(Date.now());
24
+ const millisecondString = date.getMilliseconds().toString();
25
+ timeString = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${millisecondString.substring(0, millisecondString.length > 3 ? /* istanbul ignore next */ 3 : millisecondString.length)}]`;
26
+ }
27
+ const logMessage = `[${level.name}] ${timeString} ${msg}`;
28
+ switch (level.value) {
29
+ case 0:
30
+ // eslint-disable-next-line no-console
31
+ console.debug(logMessage);
32
+ break;
33
+ case 1:
34
+ // eslint-disable-next-line no-console
35
+ console.info(logMessage);
36
+ break;
37
+ case 2:
38
+ console.warn(logMessage);
39
+ break;
40
+ case 3:
41
+ console.error(logMessage);
42
+ break;
43
+ case 4:
44
+ console.error(logMessage);
45
+ break;
46
+ default:
47
+ // eslint-disable-next-line no-console
48
+ console.log(msg);
49
+ break;
50
+ }
51
+ }
52
+ const _log = {
53
+ log: function (msg, level, timer) {
54
+ const logLevel = level ?? /* istanbul ignore next */ Logs_1.LogLevel.INFO;
55
+ switch (logLevel) {
56
+ case Logs_1.LogLevel.DEBUG:
57
+ _consoleLog(_LogLevel["DEBUG"], msg, !!timer);
58
+ break;
59
+ case Logs_1.LogLevel.WARNING:
60
+ _consoleLog(_LogLevel["WARNING"], msg, !!timer);
61
+ break;
62
+ case Logs_1.LogLevel.ERROR:
63
+ _consoleLog(_LogLevel["ERROR"], msg, !!timer);
64
+ break;
65
+ case Logs_1.LogLevel.FATAL:
66
+ _consoleLog(_LogLevel["FATAL"], msg, !!timer);
67
+ break;
68
+ case Logs_1.LogLevel.INFO:
69
+ _consoleLog(_LogLevel["INFO"], msg, !!timer);
70
+ break;
71
+ default:
72
+ _consoleLog(_LogLevel["LOG"], msg, !!timer);
73
+ break;
74
+ }
75
+ },
76
+ info: function (msg, timer) {
77
+ _consoleLog(_LogLevel["INFO"], msg, !!timer);
78
+ },
79
+ warn: function (msg, timer) {
80
+ _consoleLog(_LogLevel["WARNING"], msg, !!timer);
81
+ },
82
+ debug: function (msg, timer) {
83
+ _consoleLog(_LogLevel["DEBUG"], msg, !!timer);
84
+ },
85
+ error: function (msg, timer) {
86
+ _consoleLog(_LogLevel["ERROR"], msg, !!timer);
87
+ },
88
+ fatal: function (msg, timer) {
89
+ _consoleLog(_LogLevel["FATAL"], msg, !!timer);
90
+ },
91
+ };
92
+ function _startPerf(id) {
93
+ return {
94
+ id: id || (0, Guid_1.guid)(),
95
+ start: Date.now(),
96
+ };
97
+ }
98
+ function _endPerf(recorder, console) {
99
+ const perfTime = Date.now() - recorder.start;
100
+ if (console) {
101
+ const consoleString = `[${recorder.id}] perf time - ${perfTime}`;
102
+ _consoleLog({ value: 100, name: "Performance" }, consoleString, false);
103
+ }
104
+ return perfTime;
105
+ }
106
+ /** Tianyu Log Instance */
107
+ exports.Log = _log;
108
+ /** Tianyu Performance Instance */
109
+ exports.Performance = {
110
+ startPerf: _startPerf,
111
+ endPerf: _endPerf,
112
+ };
@@ -1,25 +1,25 @@
1
- "use strict";
2
- /**@format */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getBoolean = void 0;
5
- function getBoolean(value) {
6
- if (value === null) {
7
- return false;
8
- }
9
- switch (typeof value) {
10
- case "boolean":
11
- return value;
12
- case "number":
13
- return !!value;
14
- case "string":
15
- if (!value) {
16
- return false;
17
- }
18
- return value.toLowerCase() === "false" ? false : true;
19
- case "undefined":
20
- return false;
21
- default:
22
- return true;
23
- }
24
- }
25
- exports.getBoolean = getBoolean;
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getBoolean = void 0;
5
+ function getBoolean(value) {
6
+ if (value === null) {
7
+ return false;
8
+ }
9
+ switch (typeof value) {
10
+ case "boolean":
11
+ return value;
12
+ case "number":
13
+ return !!value;
14
+ case "string":
15
+ if (!value) {
16
+ return false;
17
+ }
18
+ return value.toLowerCase() === "false" ? false : true;
19
+ case "undefined":
20
+ return false;
21
+ default:
22
+ return true;
23
+ }
24
+ }
25
+ exports.getBoolean = getBoolean;
@@ -1,3 +1,3 @@
1
- "use strict";
2
- /** @format */
3
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
- "use strict";
2
- /** @format */
3
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ /** @format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,35 +1,35 @@
1
- "use strict";
2
- /**@format */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ArrayHelper = void 0;
5
- /** Array type related tools */
6
- class ArrayHelper {
7
- /**
8
- * To merge multiple arrays into a new array and remove duplicated elements.
9
- *
10
- * @param {any[]} array arrays
11
- * @returns return a new array
12
- */
13
- static merge(...array) {
14
- if (array.length === 0) {
15
- return [];
16
- }
17
- const result = [];
18
- for (const item of array) {
19
- if (Array.isArray(item)) {
20
- for (const arrItem of item) {
21
- if (!result.includes(arrItem)) {
22
- result.push(arrItem);
23
- }
24
- }
25
- }
26
- else {
27
- if (!result.includes(item)) {
28
- result.push(item);
29
- }
30
- }
31
- }
32
- return result;
33
- }
34
- }
35
- exports.ArrayHelper = ArrayHelper;
1
+ "use strict";
2
+ /**@format */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ArrayHelper = void 0;
5
+ /** Array type related tools */
6
+ class ArrayHelper {
7
+ /**
8
+ * To merge multiple arrays into a new array and remove duplicated elements.
9
+ *
10
+ * @param {any[]} array arrays
11
+ * @returns return a new array
12
+ */
13
+ static merge(...array) {
14
+ if (array.length === 0) {
15
+ return [];
16
+ }
17
+ const result = [];
18
+ for (const item of array) {
19
+ if (Array.isArray(item)) {
20
+ for (const arrItem of item) {
21
+ if (!result.includes(arrItem)) {
22
+ result.push(arrItem);
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ if (!result.includes(item)) {
28
+ result.push(item);
29
+ }
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+ }
35
+ exports.ArrayHelper = ArrayHelper;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /** @format */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Bytes = void 0;
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ /** Bytes Object type */
10
+ class Bytes {
11
+ /**
12
+ * Get a bytes buffer filled with random data
13
+ *
14
+ * @param size the length of bytes buffer
15
+ * @returns buffer
16
+ */
17
+ static random(size) {
18
+ return crypto_1.default.randomBytes(size);
19
+ }
20
+ }
21
+ exports.Bytes = Bytes;