@fastcar/core 0.2.63 → 0.3.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/README.md +5 -2
- package/annotation.d.ts +3 -0
- package/index.d.ts +57 -50
- package/package.json +4 -4
- package/src/FastCarApplication.ts +184 -123
- package/src/annotation/Application.ts +3 -1
- package/src/annotation/bind/AddInjectionService.ts +17 -0
- package/src/annotation/bind/AddRequireModule.ts +1 -1
- package/src/annotation/bind/AliasInjection.ts +8 -15
- package/src/annotation/bind/Autowired.ts +1 -1
- package/src/annotation/bind/CallDependency.ts +7 -17
- package/src/annotation/bind/DemandInjection.ts +16 -0
- package/src/annotation/stereotype/Log.ts +13 -9
- package/src/annotation/stereotype/Value.ts +5 -0
- package/src/annotation.ts +2 -0
- package/src/constant/FastCarMetaData.ts +2 -0
- package/src/model/WinstonLogger.ts +1 -1
- package/src/type/ClassConstructor.ts +5 -0
- package/src/type/ComponentDesc.ts +13 -0
- package/src/type/FileHotterDesc.ts +6 -0
- package/src/utils/ClassLoader.ts +2 -1
- package/src/utils/ValidationUtil.ts +1 -1
- package/target/FastCarApplication.js +764 -708
- package/target/annotation/Application.js +46 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddInjectionService.js +16 -0
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +19 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +16 -23
- package/target/annotation/bind/DemandInjection.js +15 -0
- package/target/annotation/data/DBType.js +11 -11
- package/target/annotation/data/DS.js +54 -54
- package/target/annotation/data/DSIndex.js +9 -9
- package/target/annotation/data/Entity.js +10 -10
- package/target/annotation/data/Field.js +18 -18
- package/target/annotation/data/PrimaryKey.js +9 -9
- package/target/annotation/data/SqlSession.js +9 -9
- package/target/annotation/data/Table.js +35 -35
- package/target/annotation/data/Transactional.js +52 -52
- package/target/annotation/env/ApplicationSetting.js +25 -25
- package/target/annotation/env/BaseFilePath.js +14 -14
- package/target/annotation/env/BaseName.js +9 -9
- package/target/annotation/env/BasePath.js +14 -14
- package/target/annotation/env/ENV.js +10 -10
- package/target/annotation/env/ResourcePath.js +9 -9
- package/target/annotation/lifeCycle/AddLifeCycleItem.js +17 -18
- package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
- package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
- package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
- package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
- package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
- package/target/annotation/property/Deprecate.js +19 -19
- package/target/annotation/property/NotImplemented.js +8 -8
- package/target/annotation/property/Override.js +7 -7
- package/target/annotation/property/Readonly.js +16 -16
- package/target/annotation/scan/ComponentInjection.js +21 -21
- package/target/annotation/scan/ComponentScan.js +9 -9
- package/target/annotation/scan/ComponentScanExclusion.js +25 -25
- package/target/annotation/scan/ComponentScanMust.js +25 -25
- package/target/annotation/scan/Hotter.js +8 -8
- package/target/annotation/stereotype/BeanName.js +11 -11
- package/target/annotation/stereotype/Component.js +8 -8
- package/target/annotation/stereotype/Configure.js +14 -14
- package/target/annotation/stereotype/Controller.js +9 -9
- package/target/annotation/stereotype/Injection.js +12 -12
- package/target/annotation/stereotype/Log.js +19 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- package/target/annotation/stereotype/Value.js +5 -0
- package/target/annotation/valid/AddChildValid.js +56 -56
- package/target/annotation/valid/CustomType.js +11 -11
- package/target/annotation/valid/DefaultVal.js +10 -10
- package/target/annotation/valid/NotNull.js +8 -8
- package/target/annotation/valid/Rule.js +99 -100
- package/target/annotation/valid/Size.js +10 -10
- package/target/annotation/valid/Type.js +10 -10
- package/target/annotation/valid/ValidCustom.js +17 -17
- package/target/annotation/valid/ValidForm.js +133 -133
- package/target/annotation.js +110 -108
- package/target/config/ApplicationConfig.js +2 -2
- package/target/config/SysConfig.js +19 -19
- package/target/constant/AppStatusEnum.js +9 -9
- package/target/constant/BootPriority.js +11 -11
- package/target/constant/CommonConstant.js +18 -18
- package/target/constant/ComponentKind.js +11 -11
- package/target/constant/DataTypes.js +19 -19
- package/target/constant/FastCarMetaData.js +33 -31
- package/target/constant/LifeCycleModule.js +9 -9
- package/target/db.js +49 -49
- package/target/index.js +21 -21
- package/target/interface/ApplicationHook.js +2 -2
- package/target/interface/ApplicationInterface.js +2 -2
- package/target/interface/ApplicationRunnerService.js +2 -2
- package/target/interface/DataSourceManager.js +2 -2
- package/target/interface/Logger.js +5 -5
- package/target/model/BaseMapper.js +103 -98
- package/target/model/DataMap.js +87 -87
- package/target/model/FormRuleModel.js +2 -2
- package/target/model/ValidError.js +5 -5
- package/target/model/WinstonLogger.js +98 -96
- package/target/type/ClassConstructor.js +2 -0
- package/target/type/ComponentDesc.js +9 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +9 -2
- package/target/type/MapperType.js +2 -2
- package/target/type/ProcessType.js +2 -2
- package/target/type/SqlError.js +5 -5
- package/target/type/WinstonLoggerType.js +9 -9
- package/target/utils/ClassLoader.js +66 -65
- package/target/utils/ClassUtils.js +35 -35
- package/target/utils/CryptoUtil.js +86 -86
- package/target/utils/DataFormat.js +88 -88
- package/target/utils/DateUtil.js +71 -71
- package/target/utils/FileUtil.js +153 -153
- package/target/utils/FormatStr.js +14 -14
- package/target/utils/IPUtils.js +34 -34
- package/target/utils/Id.js +8 -9
- package/target/utils/Mix.js +62 -62
- package/target/utils/ReflectUtil.js +22 -22
- package/target/utils/TypeUtil.js +53 -53
- package/target/utils/ValidationUtil.js +123 -123
- package/target/utils.js +25 -25
- package/test/example/logs/fastcar-server.app.log +0 -0
- package/test/example/logs/fastcar-server.sys.log +10 -0
- package/test/example/logs/fastcar-server.sys1.log +8 -0
- package/test/example/logs/fastcar-server.sys2.log +11 -0
- package/test/example/logs/fastcar-server.sys3.log +0 -0
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +5 -0
- package/test/example/logs/sys.log +0 -0
- package/test/example/logs/sys1.log +0 -0
- package/test/example/resource/application.yml +2 -0
- package/test/example/resource/hello.yml +1 -1
- package/test/example/simple/app-test.ts +2 -1
- package/test/example/simple/app.ts +16 -16
- package/test/example/simple/service/CallService.ts +2 -0
- package/test/example/simple/service/HelloService.ts +2 -0
- package/test/unit/sys2.log +6 -0
- package/test/unit/sys3.log +6 -0
- package/test/unit/sys4.log +6 -0
- package/test/unit/sys5.log +6 -0
- package/test/unit/sys6.log +6 -0
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const crypto = require("crypto");
|
|
4
|
-
class CryptoUtil {
|
|
5
|
-
static aesDecode(cryptkey, iv, secretdata, aesType = "aes-256-cbc" /* serects.aes */) {
|
|
6
|
-
let decipher = crypto.createDecipheriv(aesType, cryptkey, iv);
|
|
7
|
-
let decoded = decipher.update(secretdata, "base64", "utf8");
|
|
8
|
-
decoded += decipher.final("utf8");
|
|
9
|
-
return decoded;
|
|
10
|
-
}
|
|
11
|
-
static aesEncode(cryptkey, iv, cleardata, aesType = "aes-256-cbc" /* serects.aes */) {
|
|
12
|
-
let encipher = crypto.createCipheriv("aes-256-cbc" /* serects.aes */, cryptkey, iv);
|
|
13
|
-
let encoded = encipher.update(cleardata, "utf8", "base64");
|
|
14
|
-
encoded += encipher.final("base64");
|
|
15
|
-
return encoded;
|
|
16
|
-
}
|
|
17
|
-
static shaEncode(cryptkey, data) {
|
|
18
|
-
let hash = crypto.createHmac("sha256", cryptkey);
|
|
19
|
-
return hash.update(data).digest("base64");
|
|
20
|
-
}
|
|
21
|
-
static gcmEncrypt(password, msg) {
|
|
22
|
-
try {
|
|
23
|
-
let pwd = Buffer.from(password, "hex");
|
|
24
|
-
let iv = crypto.randomBytes(12);
|
|
25
|
-
let cipher = crypto.createCipheriv("aes-128-gcm", pwd, iv);
|
|
26
|
-
//加密
|
|
27
|
-
let enc = cipher.update(msg, "utf8", "base64");
|
|
28
|
-
enc += cipher.final("base64");
|
|
29
|
-
//cipher.getAuthTag() 方法返回一个 Buffer,它包含已从给定数据计算后的认证标签。
|
|
30
|
-
//cipher.getAuthTag() 方法只能在使用 cipher.final() 之后调用 这里返回的是一个十六进制后的数组
|
|
31
|
-
let tags = cipher.getAuthTag();
|
|
32
|
-
let encStr = Buffer.from(enc, "base64");
|
|
33
|
-
//由于和java对应的AES/GCM/PKCS5Padding模式对应 所以采用这个拼接
|
|
34
|
-
let totalLength = iv.length + encStr.length + tags.length;
|
|
35
|
-
let bufferMsg = Buffer.concat([iv, encStr, tags], totalLength);
|
|
36
|
-
return bufferMsg.toString("base64");
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
console.log("Encrypt is error", e);
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
static gcmDecrypt(password, serect) {
|
|
44
|
-
try {
|
|
45
|
-
let tmpSerect = Buffer.from(serect, "base64");
|
|
46
|
-
let pwd = Buffer.from(password, "hex");
|
|
47
|
-
//读取数组
|
|
48
|
-
let iv = tmpSerect.subarray(0, 12);
|
|
49
|
-
let cipher = crypto.createDecipheriv("aes-128-gcm", pwd, iv);
|
|
50
|
-
//这边的数据为 去除头的iv12位和尾部的tags的16位
|
|
51
|
-
let msg = cipher.update(tmpSerect.subarray(12, tmpSerect.length - 16));
|
|
52
|
-
return msg.toString("utf8");
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
console.log("Decrypt is error", e);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
static sha256Encode(text, serect = crypto.randomBytes(32).toString("hex"), encoding = "base64") {
|
|
60
|
-
let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
|
|
61
|
-
return {
|
|
62
|
-
salt: serect,
|
|
63
|
-
msg: msg,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
static sha256EncodeContent(str, encoding = "base64") {
|
|
67
|
-
let msg = crypto.createHash("sha256").update(str).digest(encoding);
|
|
68
|
-
return msg;
|
|
69
|
-
}
|
|
70
|
-
static sha256Very(msg, serect, encodeMsg, encoding = "base64") {
|
|
71
|
-
let result = this.sha256Encode(msg, serect, encoding);
|
|
72
|
-
return result.msg === encodeMsg;
|
|
73
|
-
}
|
|
74
|
-
static getHashStr(num = 16) {
|
|
75
|
-
return crypto.randomBytes(num).toString("hex");
|
|
76
|
-
}
|
|
77
|
-
//根据给定的字符串返回hash值按照追加的原则
|
|
78
|
-
static getHashStrByLength(serect, num) {
|
|
79
|
-
let list = crypto.createHash("md5").update(serect).digest().toString("hex");
|
|
80
|
-
while (list.length < num) {
|
|
81
|
-
list = list.repeat(num - list.length);
|
|
82
|
-
}
|
|
83
|
-
return list.substring(0, num);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.default = CryptoUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
class CryptoUtil {
|
|
5
|
+
static aesDecode(cryptkey, iv, secretdata, aesType = "aes-256-cbc" /* serects.aes */) {
|
|
6
|
+
let decipher = crypto.createDecipheriv(aesType, cryptkey, iv);
|
|
7
|
+
let decoded = decipher.update(secretdata, "base64", "utf8");
|
|
8
|
+
decoded += decipher.final("utf8");
|
|
9
|
+
return decoded;
|
|
10
|
+
}
|
|
11
|
+
static aesEncode(cryptkey, iv, cleardata, aesType = "aes-256-cbc" /* serects.aes */) {
|
|
12
|
+
let encipher = crypto.createCipheriv("aes-256-cbc" /* serects.aes */, cryptkey, iv);
|
|
13
|
+
let encoded = encipher.update(cleardata, "utf8", "base64");
|
|
14
|
+
encoded += encipher.final("base64");
|
|
15
|
+
return encoded;
|
|
16
|
+
}
|
|
17
|
+
static shaEncode(cryptkey, data) {
|
|
18
|
+
let hash = crypto.createHmac("sha256", cryptkey);
|
|
19
|
+
return hash.update(data).digest("base64");
|
|
20
|
+
}
|
|
21
|
+
static gcmEncrypt(password, msg) {
|
|
22
|
+
try {
|
|
23
|
+
let pwd = Buffer.from(password, "hex");
|
|
24
|
+
let iv = crypto.randomBytes(12);
|
|
25
|
+
let cipher = crypto.createCipheriv("aes-128-gcm", pwd, iv);
|
|
26
|
+
//加密
|
|
27
|
+
let enc = cipher.update(msg, "utf8", "base64");
|
|
28
|
+
enc += cipher.final("base64");
|
|
29
|
+
//cipher.getAuthTag() 方法返回一个 Buffer,它包含已从给定数据计算后的认证标签。
|
|
30
|
+
//cipher.getAuthTag() 方法只能在使用 cipher.final() 之后调用 这里返回的是一个十六进制后的数组
|
|
31
|
+
let tags = cipher.getAuthTag();
|
|
32
|
+
let encStr = Buffer.from(enc, "base64");
|
|
33
|
+
//由于和java对应的AES/GCM/PKCS5Padding模式对应 所以采用这个拼接
|
|
34
|
+
let totalLength = iv.length + encStr.length + tags.length;
|
|
35
|
+
let bufferMsg = Buffer.concat([iv, encStr, tags], totalLength);
|
|
36
|
+
return bufferMsg.toString("base64");
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.log("Encrypt is error", e);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
static gcmDecrypt(password, serect) {
|
|
44
|
+
try {
|
|
45
|
+
let tmpSerect = Buffer.from(serect, "base64");
|
|
46
|
+
let pwd = Buffer.from(password, "hex");
|
|
47
|
+
//读取数组
|
|
48
|
+
let iv = tmpSerect.subarray(0, 12);
|
|
49
|
+
let cipher = crypto.createDecipheriv("aes-128-gcm", pwd, iv);
|
|
50
|
+
//这边的数据为 去除头的iv12位和尾部的tags的16位
|
|
51
|
+
let msg = cipher.update(tmpSerect.subarray(12, tmpSerect.length - 16));
|
|
52
|
+
return msg.toString("utf8");
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.log("Decrypt is error", e);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
static sha256Encode(text, serect = crypto.randomBytes(32).toString("hex"), encoding = "base64") {
|
|
60
|
+
let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
|
|
61
|
+
return {
|
|
62
|
+
salt: serect,
|
|
63
|
+
msg: msg,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
static sha256EncodeContent(str, encoding = "base64") {
|
|
67
|
+
let msg = crypto.createHash("sha256").update(str).digest(encoding);
|
|
68
|
+
return msg;
|
|
69
|
+
}
|
|
70
|
+
static sha256Very(msg, serect, encodeMsg, encoding = "base64") {
|
|
71
|
+
let result = this.sha256Encode(msg, serect, encoding);
|
|
72
|
+
return result.msg === encodeMsg;
|
|
73
|
+
}
|
|
74
|
+
static getHashStr(num = 16) {
|
|
75
|
+
return crypto.randomBytes(num).toString("hex");
|
|
76
|
+
}
|
|
77
|
+
//根据给定的字符串返回hash值按照追加的原则
|
|
78
|
+
static getHashStrByLength(serect, num) {
|
|
79
|
+
let list = crypto.createHash("md5").update(serect).digest().toString("hex");
|
|
80
|
+
while (list.length < num) {
|
|
81
|
+
list = list.repeat(num - list.length);
|
|
82
|
+
}
|
|
83
|
+
return list.substring(0, num);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = CryptoUtil;
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/***
|
|
4
|
-
* @version 1.0 数据格式处理
|
|
5
|
-
*/
|
|
6
|
-
class DataFormat {
|
|
7
|
-
static formatNumber(value, type) {
|
|
8
|
-
if (type === "int") {
|
|
9
|
-
return parseInt(value);
|
|
10
|
-
}
|
|
11
|
-
if (type === "float" || type == "number") {
|
|
12
|
-
return parseFloat(value);
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
static formatString(value) {
|
|
17
|
-
if (typeof value != "string") {
|
|
18
|
-
if (typeof value == "number") {
|
|
19
|
-
return value + "";
|
|
20
|
-
}
|
|
21
|
-
if (typeof value == "object") {
|
|
22
|
-
if (Reflect.has(value, "toString")) {
|
|
23
|
-
return value.toString();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
static formatBoolean(value) {
|
|
31
|
-
if (typeof value == "string") {
|
|
32
|
-
if (value == "false") {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
//增加判断是不是数值类型
|
|
36
|
-
if (!isNaN(parseInt(value))) {
|
|
37
|
-
return !!parseInt(value);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return !!value;
|
|
41
|
-
}
|
|
42
|
-
static formatArray(value, type) {
|
|
43
|
-
if (type.startsWith("array")) {
|
|
44
|
-
if (typeof value === "string") {
|
|
45
|
-
value = JSON.parse(value);
|
|
46
|
-
}
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
let ntype = type.replace(/array/, "");
|
|
49
|
-
value = value.map((item) => {
|
|
50
|
-
return DataFormat.formatValue(item, ntype);
|
|
51
|
-
});
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
static formatDate(value) {
|
|
58
|
-
if (value instanceof Date) {
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
return new Date(value);
|
|
62
|
-
}
|
|
63
|
-
static formatValue(value, type) {
|
|
64
|
-
if (type.startsWith("array")) {
|
|
65
|
-
return DataFormat.formatArray(value, type);
|
|
66
|
-
}
|
|
67
|
-
switch (type) {
|
|
68
|
-
case "string": {
|
|
69
|
-
return DataFormat.formatString(value);
|
|
70
|
-
}
|
|
71
|
-
case "boolean": {
|
|
72
|
-
return DataFormat.formatBoolean(value);
|
|
73
|
-
}
|
|
74
|
-
case "int":
|
|
75
|
-
case "float":
|
|
76
|
-
case "number": {
|
|
77
|
-
return DataFormat.formatNumber(value, type);
|
|
78
|
-
}
|
|
79
|
-
case "date": {
|
|
80
|
-
return DataFormat.formatDate(value);
|
|
81
|
-
}
|
|
82
|
-
default: {
|
|
83
|
-
return value;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.default = DataFormat;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/***
|
|
4
|
+
* @version 1.0 数据格式处理
|
|
5
|
+
*/
|
|
6
|
+
class DataFormat {
|
|
7
|
+
static formatNumber(value, type) {
|
|
8
|
+
if (type === "int") {
|
|
9
|
+
return parseInt(value);
|
|
10
|
+
}
|
|
11
|
+
if (type === "float" || type == "number") {
|
|
12
|
+
return parseFloat(value);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
static formatString(value) {
|
|
17
|
+
if (typeof value != "string") {
|
|
18
|
+
if (typeof value == "number") {
|
|
19
|
+
return value + "";
|
|
20
|
+
}
|
|
21
|
+
if (typeof value == "object") {
|
|
22
|
+
if (Reflect.has(value, "toString")) {
|
|
23
|
+
return value.toString();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
static formatBoolean(value) {
|
|
31
|
+
if (typeof value == "string") {
|
|
32
|
+
if (value == "false") {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
//增加判断是不是数值类型
|
|
36
|
+
if (!isNaN(parseInt(value))) {
|
|
37
|
+
return !!parseInt(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return !!value;
|
|
41
|
+
}
|
|
42
|
+
static formatArray(value, type) {
|
|
43
|
+
if (type.startsWith("array")) {
|
|
44
|
+
if (typeof value === "string") {
|
|
45
|
+
value = JSON.parse(value);
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
let ntype = type.replace(/array/, "");
|
|
49
|
+
value = value.map((item) => {
|
|
50
|
+
return DataFormat.formatValue(item, ntype);
|
|
51
|
+
});
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
static formatDate(value) {
|
|
58
|
+
if (value instanceof Date) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
return new Date(value);
|
|
62
|
+
}
|
|
63
|
+
static formatValue(value, type) {
|
|
64
|
+
if (type.startsWith("array")) {
|
|
65
|
+
return DataFormat.formatArray(value, type);
|
|
66
|
+
}
|
|
67
|
+
switch (type) {
|
|
68
|
+
case "string": {
|
|
69
|
+
return DataFormat.formatString(value);
|
|
70
|
+
}
|
|
71
|
+
case "boolean": {
|
|
72
|
+
return DataFormat.formatBoolean(value);
|
|
73
|
+
}
|
|
74
|
+
case "int":
|
|
75
|
+
case "float":
|
|
76
|
+
case "number": {
|
|
77
|
+
return DataFormat.formatNumber(value, type);
|
|
78
|
+
}
|
|
79
|
+
case "date": {
|
|
80
|
+
return DataFormat.formatDate(value);
|
|
81
|
+
}
|
|
82
|
+
default: {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = DataFormat;
|
package/target/utils/DateUtil.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class DateUtil {
|
|
4
|
-
static twoDigits(num) {
|
|
5
|
-
return num.toString().padStart(2, "0");
|
|
6
|
-
}
|
|
7
|
-
//返回年月日时分秒
|
|
8
|
-
static toDateDesc(datetime = Date.now()) {
|
|
9
|
-
let dataC = new Date(datetime);
|
|
10
|
-
return {
|
|
11
|
-
YYYY: DateUtil.twoDigits(dataC.getFullYear()),
|
|
12
|
-
MM: DateUtil.twoDigits(dataC.getMonth() + 1),
|
|
13
|
-
DD: DateUtil.twoDigits(dataC.getDate()),
|
|
14
|
-
hh: DateUtil.twoDigits(dataC.getHours()),
|
|
15
|
-
mm: DateUtil.twoDigits(dataC.getMinutes()),
|
|
16
|
-
ss: DateUtil.twoDigits(dataC.getSeconds()),
|
|
17
|
-
ms: DateUtil.twoDigits(dataC.getMilliseconds()),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
static toDay(datetime = Date.now(), format = "YYYY-MM-DD") {
|
|
21
|
-
let desc = DateUtil.toDateDesc(datetime);
|
|
22
|
-
let ymd = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD);
|
|
23
|
-
return ymd;
|
|
24
|
-
}
|
|
25
|
-
static toHms(datetime = Date.now(), format = "hh:mm:ss") {
|
|
26
|
-
let desc = DateUtil.toDateDesc(datetime);
|
|
27
|
-
let hms = format.replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
|
|
28
|
-
return hms;
|
|
29
|
-
}
|
|
30
|
-
static toDateTime(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss") {
|
|
31
|
-
let desc = DateUtil.toDateDesc(datetime);
|
|
32
|
-
let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
|
|
33
|
-
return str;
|
|
34
|
-
}
|
|
35
|
-
static toDateTimeMS(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss.sss") {
|
|
36
|
-
let desc = DateUtil.toDateDesc(datetime);
|
|
37
|
-
let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss).replace(/sss/, desc.ms);
|
|
38
|
-
return str;
|
|
39
|
-
}
|
|
40
|
-
static toCutDown(datetime, format = "hh:mm:ss") {
|
|
41
|
-
let hours = Math.floor(datetime / 60 / 60);
|
|
42
|
-
let minutes = Math.floor((datetime - hours * 60 * 60) / 60);
|
|
43
|
-
let seconds = datetime - (hours * 60 + minutes) * 60;
|
|
44
|
-
let str = format.replace(/hh/, hours.toString()).replace(/mm/, minutes.toString()).replace(/ss/, seconds.toString());
|
|
45
|
-
return str;
|
|
46
|
-
}
|
|
47
|
-
static getTimeStr(datetime) {
|
|
48
|
-
let days = datetime / (1000 * 60 * 60 * 24);
|
|
49
|
-
if (days >= 1) {
|
|
50
|
-
return `${days.toFixed(2)}d`;
|
|
51
|
-
}
|
|
52
|
-
let hours = datetime / (1000 * 60 * 60);
|
|
53
|
-
if (hours >= 1) {
|
|
54
|
-
return `${hours.toFixed(2)}h`;
|
|
55
|
-
}
|
|
56
|
-
let minutes = datetime / (1000 * 60);
|
|
57
|
-
if (minutes >= 1) {
|
|
58
|
-
return `${minutes.toFixed(2)}m`;
|
|
59
|
-
}
|
|
60
|
-
let seconds = datetime / 1000;
|
|
61
|
-
return `${Math.floor(seconds)}s`;
|
|
62
|
-
}
|
|
63
|
-
static getDateTime(datetimeStr) {
|
|
64
|
-
if (datetimeStr) {
|
|
65
|
-
let dataC = new Date(datetimeStr);
|
|
66
|
-
return dataC.getTime();
|
|
67
|
-
}
|
|
68
|
-
return Date.now();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.default = DateUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class DateUtil {
|
|
4
|
+
static twoDigits(num) {
|
|
5
|
+
return num.toString().padStart(2, "0");
|
|
6
|
+
}
|
|
7
|
+
//返回年月日时分秒
|
|
8
|
+
static toDateDesc(datetime = Date.now()) {
|
|
9
|
+
let dataC = new Date(datetime);
|
|
10
|
+
return {
|
|
11
|
+
YYYY: DateUtil.twoDigits(dataC.getFullYear()),
|
|
12
|
+
MM: DateUtil.twoDigits(dataC.getMonth() + 1),
|
|
13
|
+
DD: DateUtil.twoDigits(dataC.getDate()),
|
|
14
|
+
hh: DateUtil.twoDigits(dataC.getHours()),
|
|
15
|
+
mm: DateUtil.twoDigits(dataC.getMinutes()),
|
|
16
|
+
ss: DateUtil.twoDigits(dataC.getSeconds()),
|
|
17
|
+
ms: DateUtil.twoDigits(dataC.getMilliseconds()),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
static toDay(datetime = Date.now(), format = "YYYY-MM-DD") {
|
|
21
|
+
let desc = DateUtil.toDateDesc(datetime);
|
|
22
|
+
let ymd = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD);
|
|
23
|
+
return ymd;
|
|
24
|
+
}
|
|
25
|
+
static toHms(datetime = Date.now(), format = "hh:mm:ss") {
|
|
26
|
+
let desc = DateUtil.toDateDesc(datetime);
|
|
27
|
+
let hms = format.replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
|
|
28
|
+
return hms;
|
|
29
|
+
}
|
|
30
|
+
static toDateTime(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss") {
|
|
31
|
+
let desc = DateUtil.toDateDesc(datetime);
|
|
32
|
+
let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
|
|
33
|
+
return str;
|
|
34
|
+
}
|
|
35
|
+
static toDateTimeMS(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss.sss") {
|
|
36
|
+
let desc = DateUtil.toDateDesc(datetime);
|
|
37
|
+
let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss).replace(/sss/, desc.ms);
|
|
38
|
+
return str;
|
|
39
|
+
}
|
|
40
|
+
static toCutDown(datetime, format = "hh:mm:ss") {
|
|
41
|
+
let hours = Math.floor(datetime / 60 / 60);
|
|
42
|
+
let minutes = Math.floor((datetime - hours * 60 * 60) / 60);
|
|
43
|
+
let seconds = datetime - (hours * 60 + minutes) * 60;
|
|
44
|
+
let str = format.replace(/hh/, hours.toString()).replace(/mm/, minutes.toString()).replace(/ss/, seconds.toString());
|
|
45
|
+
return str;
|
|
46
|
+
}
|
|
47
|
+
static getTimeStr(datetime) {
|
|
48
|
+
let days = datetime / (1000 * 60 * 60 * 24);
|
|
49
|
+
if (days >= 1) {
|
|
50
|
+
return `${days.toFixed(2)}d`;
|
|
51
|
+
}
|
|
52
|
+
let hours = datetime / (1000 * 60 * 60);
|
|
53
|
+
if (hours >= 1) {
|
|
54
|
+
return `${hours.toFixed(2)}h`;
|
|
55
|
+
}
|
|
56
|
+
let minutes = datetime / (1000 * 60);
|
|
57
|
+
if (minutes >= 1) {
|
|
58
|
+
return `${minutes.toFixed(2)}m`;
|
|
59
|
+
}
|
|
60
|
+
let seconds = datetime / 1000;
|
|
61
|
+
return `${Math.floor(seconds)}s`;
|
|
62
|
+
}
|
|
63
|
+
static getDateTime(datetimeStr) {
|
|
64
|
+
if (datetimeStr) {
|
|
65
|
+
let dataC = new Date(datetimeStr);
|
|
66
|
+
return dataC.getTime();
|
|
67
|
+
}
|
|
68
|
+
return Date.now();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = DateUtil;
|