@fastcar/core 0.2.61 → 0.2.63
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/package.json +1 -1
- package/src/FastCarApplication.ts +30 -9
- package/src/utils/ValidationUtil.ts +1 -3
- package/target/FastCarApplication.js +708 -692
- package/target/annotation/Application.js +45 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +23 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +23 -23
- 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 +18 -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 +17 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- 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 +100 -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 +108 -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 +31 -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 +98 -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 +96 -96
- package/target/type/ComponentDesc.js +2 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +2 -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 +65 -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 +9 -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 -124
- package/target/utils.js +25 -25
- package/test/unit/decorators-test.ts +3 -3
- package/target/src/FastCarApplication.js +0 -704
- package/target/src/annotation/Application.js +0 -45
- package/target/src/annotation/ExceptionMonitor.js +0 -16
- package/target/src/annotation/bind/AddRequireModule.js +0 -21
- package/target/src/annotation/bind/AliasInjection.js +0 -23
- package/target/src/annotation/bind/Autowired.js +0 -13
- package/target/src/annotation/bind/CallDependency.js +0 -23
- package/target/src/annotation/data/DBType.js +0 -11
- package/target/src/annotation/data/DS.js +0 -54
- package/target/src/annotation/data/DSIndex.js +0 -9
- package/target/src/annotation/data/Entity.js +0 -10
- package/target/src/annotation/data/Field.js +0 -18
- package/target/src/annotation/data/PrimaryKey.js +0 -9
- package/target/src/annotation/data/SqlSession.js +0 -9
- package/target/src/annotation/data/Table.js +0 -35
- package/target/src/annotation/data/Transactional.js +0 -52
- package/target/src/annotation/env/ApplicationSetting.js +0 -25
- package/target/src/annotation/env/BaseFilePath.js +0 -14
- package/target/src/annotation/env/BaseName.js +0 -9
- package/target/src/annotation/env/BasePath.js +0 -14
- package/target/src/annotation/env/ENV.js +0 -10
- package/target/src/annotation/env/ResourcePath.js +0 -9
- package/target/src/annotation/lifeCycle/AddLifeCycleItem.js +0 -18
- package/target/src/annotation/lifeCycle/ApplicationDestory.js +0 -15
- package/target/src/annotation/lifeCycle/ApplicationInit.js +0 -15
- package/target/src/annotation/lifeCycle/ApplicationRunner.js +0 -7
- package/target/src/annotation/lifeCycle/ApplicationStart.js +0 -24
- package/target/src/annotation/lifeCycle/ApplicationStop.js +0 -20
- package/target/src/annotation/property/Deprecate.js +0 -19
- package/target/src/annotation/property/NotImplemented.js +0 -8
- package/target/src/annotation/property/Override.js +0 -7
- package/target/src/annotation/property/Readonly.js +0 -16
- package/target/src/annotation/scan/ComponentInjection.js +0 -21
- package/target/src/annotation/scan/ComponentScan.js +0 -9
- package/target/src/annotation/scan/ComponentScanExclusion.js +0 -25
- package/target/src/annotation/scan/ComponentScanMust.js +0 -25
- package/target/src/annotation/scan/Hotter.js +0 -8
- package/target/src/annotation/stereotype/BeanName.js +0 -11
- package/target/src/annotation/stereotype/Component.js +0 -8
- package/target/src/annotation/stereotype/Configure.js +0 -14
- package/target/src/annotation/stereotype/Controller.js +0 -9
- package/target/src/annotation/stereotype/Injection.js +0 -12
- package/target/src/annotation/stereotype/Log.js +0 -22
- package/target/src/annotation/stereotype/Repository.js +0 -9
- package/target/src/annotation/stereotype/Service.js +0 -9
- package/target/src/annotation/valid/AddChildValid.js +0 -56
- package/target/src/annotation/valid/CustomType.js +0 -11
- package/target/src/annotation/valid/DefaultVal.js +0 -10
- package/target/src/annotation/valid/NotNull.js +0 -8
- package/target/src/annotation/valid/Rule.js +0 -100
- package/target/src/annotation/valid/Size.js +0 -10
- package/target/src/annotation/valid/Type.js +0 -10
- package/target/src/annotation/valid/ValidCustom.js +0 -17
- package/target/src/annotation/valid/ValidForm.js +0 -133
- package/target/src/annotation.js +0 -108
- package/target/src/config/ApplicationConfig.js +0 -2
- package/target/src/config/SysConfig.js +0 -19
- package/target/src/constant/AppStatusEnum.js +0 -9
- package/target/src/constant/BootPriority.js +0 -11
- package/target/src/constant/CommonConstant.js +0 -18
- package/target/src/constant/ComponentKind.js +0 -11
- package/target/src/constant/DataTypes.js +0 -19
- package/target/src/constant/FastCarMetaData.js +0 -31
- package/target/src/constant/LifeCycleModule.js +0 -9
- package/target/src/db.js +0 -49
- package/target/src/index.js +0 -21
- package/target/src/interface/ApplicationHook.js +0 -2
- package/target/src/interface/ApplicationInterface.js +0 -2
- package/target/src/interface/ApplicationRunnerService.js +0 -2
- package/target/src/interface/DataSourceManager.js +0 -2
- package/target/src/interface/Logger.js +0 -5
- package/target/src/model/BaseMapper.js +0 -103
- package/target/src/model/DataMap.js +0 -87
- package/target/src/model/FormRuleModel.js +0 -2
- package/target/src/model/ValidError.js +0 -5
- package/target/src/model/WinstonLogger.js +0 -97
- package/target/src/type/ComponentDesc.js +0 -2
- package/target/src/type/DesignMeta.js +0 -15
- package/target/src/type/FileHotterDesc.js +0 -2
- package/target/src/type/MapperType.js +0 -2
- package/target/src/type/ProcessType.js +0 -2
- package/target/src/type/SqlError.js +0 -5
- package/target/src/type/WinstonLoggerType.js +0 -9
- package/target/src/utils/ClassLoader.js +0 -65
- package/target/src/utils/ClassUtils.js +0 -35
- package/target/src/utils/CryptoUtil.js +0 -86
- package/target/src/utils/DataFormat.js +0 -88
- package/target/src/utils/DateUtil.js +0 -71
- package/target/src/utils/FileUtil.js +0 -153
- package/target/src/utils/FormatStr.js +0 -14
- package/target/src/utils/IPUtils.js +0 -34
- package/target/src/utils/Id.js +0 -9
- package/target/src/utils/Mix.js +0 -62
- package/target/src/utils/ReflectUtil.js +0 -22
- package/target/src/utils/TypeUtil.js +0 -53
- package/target/src/utils/ValidationUtil.js +0 -118
- package/target/src/utils.js +0 -25
- package/target/test/example/simple/app-test.js +0 -57
- package/target/test/example/simple/app.js +0 -116
- package/target/test/example/simple/component/StartRunner.js +0 -19
- package/target/test/example/simple/component/StopRunner.js +0 -23
- package/target/test/example/simple/config/EnvConfig.js +0 -16
- package/target/test/example/simple/config/HelloConfig.js +0 -16
- package/target/test/example/simple/config/HotConfig.js +0 -18
- package/target/test/example/simple/controller/AliasController.js +0 -17
- package/target/test/example/simple/controller/HelloController.js +0 -55
- package/target/test/example/simple/controller/NotFoundController.js +0 -36
- package/target/test/example/simple/noclude/excludeApp.js +0 -17
- package/target/test/example/simple/service/CallService.js +0 -24
- package/target/test/example/simple/service/HelloService.js +0 -18
- package/target/test/example/simple/service/LogService.js +0 -32
- package/target/test/multi/app.js +0 -29
- package/target/test/multi/service/aService.js +0 -33
- package/target/test/multi/service/bService.js +0 -35
- package/target/test/multi/service/cService.js +0 -40
- package/target/test/unit/dataMap-test.js +0 -35
- package/target/test/unit/decorators-test.js +0 -59
- package/target/test/unit/ds-test.js +0 -58
- package/target/test/unit/reflectMetadata-test.js +0 -27
- package/target/test/unit/valid-test.js +0 -99
- package/target/test/unit/winston-test.js +0 -15
- package/test/example/logs/fastcar-server.sys.log +0 -3
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +0 -0
- package/test/example/logs/other-server.sys1.log +0 -0
- package/test/example/logs/other-server.sys2.log +0 -0
- package/test/example/logs/other-server.sys3.log +0 -6
- package/test/example/logs/other-server.sys4.log +0 -0
- package/test/example/logs/other-server.sys5.log +0 -0
- package/test/example/logs/other-server.sys6.log +0 -2
- package/test/logs/logger.log +0 -0
- package/test/logs/sys.log +0 -227
|
@@ -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;
|
package/target/utils/FileUtil.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const yaml = require("yaml");
|
|
6
|
-
const SysConfig_1 = require("../config/SysConfig");
|
|
7
|
-
const CommonConstant_1 = require("../constant/CommonConstant");
|
|
8
|
-
const Mix_1 = require("./Mix");
|
|
9
|
-
const fileResSuffix = ["json", "yml", "js"]; //文件资源后缀名
|
|
10
|
-
const bytesUnit = ["B", "K", "M", "G"];
|
|
11
|
-
class FileUtil {
|
|
12
|
-
/***
|
|
13
|
-
* @version 1.0 获取文件路径
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
static getFilePathList(filePath) {
|
|
17
|
-
let pathList = Array.of();
|
|
18
|
-
let existFlag = fs.existsSync(filePath);
|
|
19
|
-
if (!existFlag) {
|
|
20
|
-
return pathList;
|
|
21
|
-
}
|
|
22
|
-
let currStats = fs.statSync(filePath);
|
|
23
|
-
let cfile = currStats.isFile();
|
|
24
|
-
let cdir = currStats.isDirectory();
|
|
25
|
-
if (!cdir && !cfile) {
|
|
26
|
-
return pathList;
|
|
27
|
-
}
|
|
28
|
-
if (cfile) {
|
|
29
|
-
pathList.push(filePath);
|
|
30
|
-
return pathList;
|
|
31
|
-
}
|
|
32
|
-
let childPaths = fs.readdirSync(filePath);
|
|
33
|
-
for (let c of childPaths) {
|
|
34
|
-
let fullPath = path.join(filePath, c);
|
|
35
|
-
let tmpStats = fs.statSync(fullPath);
|
|
36
|
-
if (tmpStats.isDirectory()) {
|
|
37
|
-
let childPaths = FileUtil.getFilePathList(fullPath);
|
|
38
|
-
if (childPaths.length > 0) {
|
|
39
|
-
pathList = [...pathList, ...childPaths];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else if (tmpStats.isFile()) {
|
|
43
|
-
pathList.push(fullPath);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return pathList;
|
|
47
|
-
}
|
|
48
|
-
/***
|
|
49
|
-
* @version 1.0 获取后缀名
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
static getSuffix(filePath) {
|
|
53
|
-
let lastIndex = filePath.lastIndexOf(".") + 1;
|
|
54
|
-
if (lastIndex <= 0) {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
let suffix = filePath.substring(lastIndex);
|
|
58
|
-
return suffix;
|
|
59
|
-
}
|
|
60
|
-
/***
|
|
61
|
-
* @version 1.0 获取文件的文件名
|
|
62
|
-
*/
|
|
63
|
-
static getFileName(filePath) {
|
|
64
|
-
let pList = filePath.split(path.sep);
|
|
65
|
-
let lastPath = pList[pList.length - 1];
|
|
66
|
-
let lastName = lastPath.split(".");
|
|
67
|
-
return lastName[0];
|
|
68
|
-
}
|
|
69
|
-
//加载配置文件
|
|
70
|
-
static getResource(fp) {
|
|
71
|
-
let currSuffix = FileUtil.getSuffix(fp);
|
|
72
|
-
if (!fileResSuffix.includes(currSuffix)) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
if (fs.existsSync(fp)) {
|
|
76
|
-
let currStats = fs.statSync(fp);
|
|
77
|
-
if (currStats.isFile()) {
|
|
78
|
-
//进行解析
|
|
79
|
-
let content = fs.readFileSync(fp, "utf-8");
|
|
80
|
-
switch (currSuffix) {
|
|
81
|
-
case "yml": {
|
|
82
|
-
return yaml.parse(content);
|
|
83
|
-
}
|
|
84
|
-
case "json": {
|
|
85
|
-
return JSON.parse(content);
|
|
86
|
-
}
|
|
87
|
-
case "js":
|
|
88
|
-
case "ts": {
|
|
89
|
-
if (Reflect.has(require.cache, fp)) {
|
|
90
|
-
Reflect.deleteProperty(require.cache, fp);
|
|
91
|
-
}
|
|
92
|
-
return require(fp);
|
|
93
|
-
}
|
|
94
|
-
default: {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
//格式化字节大小
|
|
103
|
-
static formatBytes(n) {
|
|
104
|
-
for (let i = 0; i < bytesUnit.length; i++) {
|
|
105
|
-
let nn = n / Math.pow(1024, i);
|
|
106
|
-
if (nn <= 1024) {
|
|
107
|
-
return `${nn.toFixed(2)}(${bytesUnit[i]})`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
let maxL = bytesUnit.length - 1;
|
|
111
|
-
return `${(n / Math.pow(1024, maxL)).toFixed(2)}(${bytesUnit[maxL]})`;
|
|
112
|
-
}
|
|
113
|
-
//获取加载配置项
|
|
114
|
-
static getApplicationConfig(resPath, configName, sysConfig = SysConfig_1.SYSDefaultConfig) {
|
|
115
|
-
const replaceSetting = (property, fileContent) => {
|
|
116
|
-
let addConfig = Reflect.get(fileContent, property);
|
|
117
|
-
if (addConfig) {
|
|
118
|
-
let currConfig = Reflect.get(sysConfig, property);
|
|
119
|
-
Reflect.deleteProperty(fileContent, property);
|
|
120
|
-
if (CommonConstant_1.CommonConstant.Settings == property) {
|
|
121
|
-
Object.keys(addConfig).forEach((key) => {
|
|
122
|
-
let afterConfig = addConfig[key];
|
|
123
|
-
let beforeConfig = sysConfig.settings.get(key);
|
|
124
|
-
if (beforeConfig) {
|
|
125
|
-
//对settings的属性进行覆盖
|
|
126
|
-
if (typeof beforeConfig == "object") {
|
|
127
|
-
afterConfig = Object.assign(beforeConfig, afterConfig);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
sysConfig.settings.set(key, afterConfig);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
Object.assign(currConfig, addConfig);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
CommonConstant_1.FileResSuffix.forEach((suffix) => {
|
|
139
|
-
let fileContent = FileUtil.getResource(path.join(resPath, `${configName}.${suffix}`));
|
|
140
|
-
if (fileContent) {
|
|
141
|
-
replaceSetting(CommonConstant_1.CommonConstant.Settings, fileContent);
|
|
142
|
-
replaceSetting(CommonConstant_1.CommonConstant.Application, fileContent);
|
|
143
|
-
//将application和sesstings进行删除
|
|
144
|
-
Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Application);
|
|
145
|
-
Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Settings);
|
|
146
|
-
//追加自定的属性
|
|
147
|
-
Mix_1.default.copyProperties(sysConfig, fileContent);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return sysConfig;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.default = FileUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const yaml = require("yaml");
|
|
6
|
+
const SysConfig_1 = require("../config/SysConfig");
|
|
7
|
+
const CommonConstant_1 = require("../constant/CommonConstant");
|
|
8
|
+
const Mix_1 = require("./Mix");
|
|
9
|
+
const fileResSuffix = ["json", "yml", "js"]; //文件资源后缀名
|
|
10
|
+
const bytesUnit = ["B", "K", "M", "G"];
|
|
11
|
+
class FileUtil {
|
|
12
|
+
/***
|
|
13
|
+
* @version 1.0 获取文件路径
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
static getFilePathList(filePath) {
|
|
17
|
+
let pathList = Array.of();
|
|
18
|
+
let existFlag = fs.existsSync(filePath);
|
|
19
|
+
if (!existFlag) {
|
|
20
|
+
return pathList;
|
|
21
|
+
}
|
|
22
|
+
let currStats = fs.statSync(filePath);
|
|
23
|
+
let cfile = currStats.isFile();
|
|
24
|
+
let cdir = currStats.isDirectory();
|
|
25
|
+
if (!cdir && !cfile) {
|
|
26
|
+
return pathList;
|
|
27
|
+
}
|
|
28
|
+
if (cfile) {
|
|
29
|
+
pathList.push(filePath);
|
|
30
|
+
return pathList;
|
|
31
|
+
}
|
|
32
|
+
let childPaths = fs.readdirSync(filePath);
|
|
33
|
+
for (let c of childPaths) {
|
|
34
|
+
let fullPath = path.join(filePath, c);
|
|
35
|
+
let tmpStats = fs.statSync(fullPath);
|
|
36
|
+
if (tmpStats.isDirectory()) {
|
|
37
|
+
let childPaths = FileUtil.getFilePathList(fullPath);
|
|
38
|
+
if (childPaths.length > 0) {
|
|
39
|
+
pathList = [...pathList, ...childPaths];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (tmpStats.isFile()) {
|
|
43
|
+
pathList.push(fullPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return pathList;
|
|
47
|
+
}
|
|
48
|
+
/***
|
|
49
|
+
* @version 1.0 获取后缀名
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
static getSuffix(filePath) {
|
|
53
|
+
let lastIndex = filePath.lastIndexOf(".") + 1;
|
|
54
|
+
if (lastIndex <= 0) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
let suffix = filePath.substring(lastIndex);
|
|
58
|
+
return suffix;
|
|
59
|
+
}
|
|
60
|
+
/***
|
|
61
|
+
* @version 1.0 获取文件的文件名
|
|
62
|
+
*/
|
|
63
|
+
static getFileName(filePath) {
|
|
64
|
+
let pList = filePath.split(path.sep);
|
|
65
|
+
let lastPath = pList[pList.length - 1];
|
|
66
|
+
let lastName = lastPath.split(".");
|
|
67
|
+
return lastName[0];
|
|
68
|
+
}
|
|
69
|
+
//加载配置文件
|
|
70
|
+
static getResource(fp) {
|
|
71
|
+
let currSuffix = FileUtil.getSuffix(fp);
|
|
72
|
+
if (!fileResSuffix.includes(currSuffix)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (fs.existsSync(fp)) {
|
|
76
|
+
let currStats = fs.statSync(fp);
|
|
77
|
+
if (currStats.isFile()) {
|
|
78
|
+
//进行解析
|
|
79
|
+
let content = fs.readFileSync(fp, "utf-8");
|
|
80
|
+
switch (currSuffix) {
|
|
81
|
+
case "yml": {
|
|
82
|
+
return yaml.parse(content);
|
|
83
|
+
}
|
|
84
|
+
case "json": {
|
|
85
|
+
return JSON.parse(content);
|
|
86
|
+
}
|
|
87
|
+
case "js":
|
|
88
|
+
case "ts": {
|
|
89
|
+
if (Reflect.has(require.cache, fp)) {
|
|
90
|
+
Reflect.deleteProperty(require.cache, fp);
|
|
91
|
+
}
|
|
92
|
+
return require(fp);
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
//格式化字节大小
|
|
103
|
+
static formatBytes(n) {
|
|
104
|
+
for (let i = 0; i < bytesUnit.length; i++) {
|
|
105
|
+
let nn = n / Math.pow(1024, i);
|
|
106
|
+
if (nn <= 1024) {
|
|
107
|
+
return `${nn.toFixed(2)}(${bytesUnit[i]})`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let maxL = bytesUnit.length - 1;
|
|
111
|
+
return `${(n / Math.pow(1024, maxL)).toFixed(2)}(${bytesUnit[maxL]})`;
|
|
112
|
+
}
|
|
113
|
+
//获取加载配置项
|
|
114
|
+
static getApplicationConfig(resPath, configName, sysConfig = SysConfig_1.SYSDefaultConfig) {
|
|
115
|
+
const replaceSetting = (property, fileContent) => {
|
|
116
|
+
let addConfig = Reflect.get(fileContent, property);
|
|
117
|
+
if (addConfig) {
|
|
118
|
+
let currConfig = Reflect.get(sysConfig, property);
|
|
119
|
+
Reflect.deleteProperty(fileContent, property);
|
|
120
|
+
if (CommonConstant_1.CommonConstant.Settings == property) {
|
|
121
|
+
Object.keys(addConfig).forEach((key) => {
|
|
122
|
+
let afterConfig = addConfig[key];
|
|
123
|
+
let beforeConfig = sysConfig.settings.get(key);
|
|
124
|
+
if (beforeConfig) {
|
|
125
|
+
//对settings的属性进行覆盖
|
|
126
|
+
if (typeof beforeConfig == "object") {
|
|
127
|
+
afterConfig = Object.assign(beforeConfig, afterConfig);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
sysConfig.settings.set(key, afterConfig);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
Object.assign(currConfig, addConfig);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
CommonConstant_1.FileResSuffix.forEach((suffix) => {
|
|
139
|
+
let fileContent = FileUtil.getResource(path.join(resPath, `${configName}.${suffix}`));
|
|
140
|
+
if (fileContent) {
|
|
141
|
+
replaceSetting(CommonConstant_1.CommonConstant.Settings, fileContent);
|
|
142
|
+
replaceSetting(CommonConstant_1.CommonConstant.Application, fileContent);
|
|
143
|
+
//将application和sesstings进行删除
|
|
144
|
+
Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Application);
|
|
145
|
+
Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Settings);
|
|
146
|
+
//追加自定的属性
|
|
147
|
+
Mix_1.default.copyProperties(sysConfig, fileContent);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return sysConfig;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.default = FileUtil;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class FormatStr {
|
|
4
|
-
static formatFirstToUp(str) {
|
|
5
|
-
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
6
|
-
}
|
|
7
|
-
static formatFirstToLow(str) {
|
|
8
|
-
return str.charAt(0).toLowerCase() + str.substring(1);
|
|
9
|
-
}
|
|
10
|
-
static formatFirstToUpEnd(str) {
|
|
11
|
-
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.default = FormatStr;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class FormatStr {
|
|
4
|
+
static formatFirstToUp(str) {
|
|
5
|
+
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
6
|
+
}
|
|
7
|
+
static formatFirstToLow(str) {
|
|
8
|
+
return str.charAt(0).toLowerCase() + str.substring(1);
|
|
9
|
+
}
|
|
10
|
+
static formatFirstToUpEnd(str) {
|
|
11
|
+
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.default = FormatStr;
|