@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.
- package/dist/lib/{utilities/coding → coding}/Error.js +44 -44
- package/dist/lib/{utilities/coding → coding}/Path.js +210 -198
- package/dist/lib/{utilities/core → core}/Errors.js +86 -86
- package/dist/lib/{utilities/core → core}/Language.js +561 -559
- package/dist/lib/{utilities/core → core}/Log.js +112 -108
- package/dist/lib/{utilities/core → core}/TypeConvertion.js +25 -25
- package/dist/lib/{utilities/core → core}/interface/ITJSON.js +3 -3
- package/dist/lib/{utilities/core → core}/interface/ITianyuType.js +3 -3
- package/dist/lib/{utilities/core → core}/object/ArrayHelper.js +35 -35
- package/dist/lib/core/object/Bytes.js +21 -0
- package/dist/lib/{utilities/core → core}/object/Calculater.js +240 -230
- package/dist/lib/core/object/DataView.js +23 -0
- package/dist/lib/core/object/Integer.js +117 -0
- package/dist/lib/core/object/Json.js +35 -0
- package/dist/lib/{utilities/core/object/Helper.js → core/object/ObjectHelper.js} +202 -201
- package/dist/lib/core/object/StringHelper.js +61 -0
- package/dist/lib/{utilities/core → core}/type/TArray.js +8 -7
- package/dist/lib/{utilities/core → core}/type/TBoolean.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TJSON.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TNumber.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TObject.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TString.js +7 -7
- package/dist/lib/index.js +70 -54
- package/dist/lib/security/Base32.js +104 -0
- package/dist/lib/security/Guid.js +26 -0
- package/dist/lib/{utilities/security → security}/Hash.js +16 -15
- package/dist/lib/security/QRCode.js +46 -0
- package/dist/lib/security/RSA.js +62 -0
- package/dist/lib/security/SHA.js +67 -0
- package/dist/lib/types/AreaCode.js +269 -269
- package/dist/lib/types/Exception.js +19 -19
- package/dist/lib/types/Logs.js +20 -20
- package/dist/lib/types/Object.js +3 -3
- package/dist/lib/types/PathBase.js +109 -109
- package/dist/lib/types/Security.js +10 -10
- package/dist/lib/types/TMap.js +139 -138
- package/dist/lib/types/Types.js +3 -3
- package/dist/lib/types/index.js +17 -17
- package/dist/types/{utilities/coding → coding}/Error.d.ts +27 -27
- package/dist/types/{utilities/coding → coding}/Path.d.ts +61 -61
- package/dist/types/{utilities/core → core}/Errors.d.ts +47 -47
- package/dist/types/{utilities/core → core}/Language.d.ts +17 -17
- package/dist/types/{utilities/core → core}/Log.d.ts +12 -12
- package/dist/types/{utilities/core → core}/TypeConvertion.d.ts +2 -2
- package/dist/types/{utilities/core → core}/interface/ITJSON.d.ts +5 -5
- package/dist/types/{utilities/core → core}/interface/ITianyuType.d.ts +5 -5
- package/dist/types/{utilities/core → core}/object/ArrayHelper.d.ts +11 -11
- package/dist/types/core/object/Bytes.d.ts +13 -0
- package/dist/types/{utilities/core → core}/object/Calculater.d.ts +22 -22
- package/dist/types/core/object/DataView.d.ts +11 -0
- package/dist/types/core/object/Integer.d.ts +71 -0
- package/dist/types/core/object/Json.d.ts +22 -0
- package/dist/types/{utilities/core/object/Helper.d.ts → core/object/ObjectHelper.d.ts} +39 -39
- package/dist/types/core/object/StringHelper.d.ts +21 -0
- package/dist/types/{utilities/core → core}/type/TArray.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TBoolean.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TJSON.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TNumber.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TObject.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TString.d.ts +3 -3
- package/dist/types/index.d.ts +29 -21
- package/dist/types/security/Base32.d.ts +42 -0
- package/dist/types/security/Guid.d.ts +4 -0
- package/dist/types/{utilities/security → security}/Hash.d.ts +3 -3
- package/dist/types/security/QRCode.d.ts +11 -0
- package/dist/types/security/RSA.d.ts +68 -0
- package/dist/types/security/SHA.d.ts +40 -0
- package/dist/types/types/AreaCode.d.ts +135 -135
- package/dist/types/types/Exception.d.ts +11 -11
- package/dist/types/types/Logs.d.ts +64 -64
- package/dist/types/types/Object.d.ts +18 -18
- package/dist/types/types/PathBase.d.ts +76 -76
- package/dist/types/types/Security.d.ts +23 -23
- package/dist/types/types/TMap.d.ts +80 -80
- package/dist/types/types/Types.d.ts +25 -25
- package/dist/types/types/index.d.ts +9 -9
- package/package.json +57 -51
- package/dist/lib/utilities/coding/index.js +0 -10
- package/dist/lib/utilities/core/index.js +0 -21
- package/dist/lib/utilities/core/object/StringHelper.js +0 -22
- package/dist/lib/utilities/security/Guid.js +0 -20
- package/dist/lib/utilities/security/index.js +0 -8
- package/dist/types/utilities/coding/index.d.ts +0 -3
- package/dist/types/utilities/core/index.d.ts +0 -6
- package/dist/types/utilities/core/object/StringHelper.d.ts +0 -4
- package/dist/types/utilities/security/Guid.d.ts +0 -3
- 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("
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.
|
|
36
|
-
break;
|
|
37
|
-
case
|
|
38
|
-
console.
|
|
39
|
-
break;
|
|
40
|
-
case
|
|
41
|
-
console.error(logMessage);
|
|
42
|
-
break;
|
|
43
|
-
|
|
44
|
-
console.
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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;
|