@fastcar/core 0.2.44 → 0.2.46

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/core",
3
- "version": "0.2.44",
3
+ "version": "0.2.46",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "main": "target/index.js",
6
6
  "author": "william_zhong",
@@ -74,10 +74,7 @@ export default class CryptoUtil {
74
74
  }
75
75
 
76
76
  static sha256Encode(text: string, serect: string = crypto.randomBytes(32).toString("hex"), encoding: BinaryToTextEncoding = "base64"): { salt: string; msg: string } {
77
- let msg = crypto
78
- .createHmac("sha256", serect)
79
- .update(text)
80
- .digest(encoding);
77
+ let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
81
78
 
82
79
  return {
83
80
  salt: serect,
@@ -86,10 +83,7 @@ export default class CryptoUtil {
86
83
  }
87
84
 
88
85
  static sha256EncodeContent(str: string, encoding: BinaryToTextEncoding = "base64"): string {
89
- let msg = crypto
90
- .createHash("sha256")
91
- .update(str)
92
- .digest(encoding);
86
+ let msg = crypto.createHash("sha256").update(str).digest(encoding);
93
87
 
94
88
  return msg;
95
89
  }
@@ -103,4 +97,15 @@ export default class CryptoUtil {
103
97
  static getHashStr(num: number = 16): string {
104
98
  return crypto.randomBytes(num).toString("hex");
105
99
  }
100
+
101
+ //根据给定的字符串返回hash值按照追加的原则
102
+ static getHashStrByLength(serect: string, num: number): string {
103
+ let list = crypto.createHash("md5").update(serect).digest().toString("hex");
104
+
105
+ while (list.length < num) {
106
+ list = list.repeat(num - list.length);
107
+ }
108
+
109
+ return list.substring(0, num);
110
+ }
106
111
  }
@@ -0,0 +1,35 @@
1
+ const getIPNum = function (address: string) {
2
+ let ip = address.split(".");
3
+ let total = 0;
4
+ ip.forEach((item, index) => {
5
+ total += parseInt(item) * Math.pow(256, 3 - index);
6
+ });
7
+
8
+ return total;
9
+ };
10
+
11
+ const InnerIPList = [
12
+ ["10.0.0.0", "10.255.255.255"],
13
+ ["172.16.0.0", "172.31.255.255"],
14
+ ["192.168.0.0", "192.168.255.255"],
15
+ ["127.0.0.0", "127.255.255.255"],
16
+ ].map((item) => {
17
+ return [getIPNum(item[0]), getIPNum(item[1])];
18
+ });
19
+
20
+ export default class IPUtils {
21
+ static isInnerIP = (ip: string): boolean => {
22
+ if (["0.0.0.0", "localhost"].includes(ip)) {
23
+ return true;
24
+ }
25
+
26
+ let n = ip.split(".");
27
+ if (n.length != 4) {
28
+ return false;
29
+ }
30
+ let ipn = getIPNum(ip);
31
+ return InnerIPList.some((item) => {
32
+ return ipn >= item[0] && ipn <= item[1];
33
+ });
34
+ };
35
+ }
package/src/utils.ts CHANGED
@@ -8,6 +8,7 @@ import FormatStr from "./utils/FormatStr";
8
8
  import MixTool from "./utils/Mix";
9
9
  import TypeUtil from "./utils/TypeUtil";
10
10
  import ValidationUtil from "./utils/ValidationUtil";
11
+ import IPUtils from "./utils/IPUtils";
11
12
 
12
13
  //实用工具集合类
13
- export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool };
14
+ export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils };
@@ -57,20 +57,14 @@ class CryptoUtil {
57
57
  }
58
58
  }
59
59
  static sha256Encode(text, serect = crypto.randomBytes(32).toString("hex"), encoding = "base64") {
60
- let msg = crypto
61
- .createHmac("sha256", serect)
62
- .update(text)
63
- .digest(encoding);
60
+ let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
64
61
  return {
65
62
  salt: serect,
66
63
  msg: msg,
67
64
  };
68
65
  }
69
66
  static sha256EncodeContent(str, encoding = "base64") {
70
- let msg = crypto
71
- .createHash("sha256")
72
- .update(str)
73
- .digest(encoding);
67
+ let msg = crypto.createHash("sha256").update(str).digest(encoding);
74
68
  return msg;
75
69
  }
76
70
  static sha256Very(msg, serect, encodeMsg, encoding = "base64") {
@@ -80,5 +74,13 @@ class CryptoUtil {
80
74
  static getHashStr(num = 16) {
81
75
  return crypto.randomBytes(num).toString("hex");
82
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
+ }
83
85
  }
84
86
  exports.default = CryptoUtil;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getIPNum = function (address) {
4
+ let ip = address.split(".");
5
+ let total = 0;
6
+ ip.forEach((item, index) => {
7
+ total += parseInt(item) * Math.pow(256, 3 - index);
8
+ });
9
+ return total;
10
+ };
11
+ const InnerIPList = [
12
+ ["10.0.0.0", "10.255.255.255"],
13
+ ["172.16.0.0", "172.31.255.255"],
14
+ ["192.168.0.0", "192.168.255.255"],
15
+ ["127.0.0.0", "127.255.255.255"],
16
+ ].map((item) => {
17
+ return [getIPNum(item[0]), getIPNum(item[1])];
18
+ });
19
+ class IPUtils {
20
+ }
21
+ exports.default = IPUtils;
22
+ IPUtils.isInnerIP = (ip) => {
23
+ if (["0.0.0.0", "localhost"].includes(ip)) {
24
+ return true;
25
+ }
26
+ let n = ip.split(".");
27
+ if (n.length != 4) {
28
+ return false;
29
+ }
30
+ let ipn = getIPNum(ip);
31
+ return InnerIPList.some((item) => {
32
+ return ipn >= item[0] && ipn <= item[1];
33
+ });
34
+ };
package/target/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
3
+ exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
4
4
  const classLoader_1 = require("./utils/classLoader");
5
5
  exports.ClassLoader = classLoader_1.default;
6
6
  const ClassUtils_1 = require("./utils/ClassUtils");
@@ -21,3 +21,5 @@ const TypeUtil_1 = require("./utils/TypeUtil");
21
21
  exports.TypeUtil = TypeUtil_1.default;
22
22
  const ValidationUtil_1 = require("./utils/ValidationUtil");
23
23
  exports.ValidationUtil = ValidationUtil_1.default;
24
+ const IPUtils_1 = require("./utils/IPUtils");
25
+ exports.IPUtils = IPUtils_1.default;
@@ -0,0 +1,3 @@
1
+ {"timestamp":"2023-07-24 16:49:43.665","level":"INFO","label":"fastcar-server.logger","message":"自定义的日志输出"}
2
+ {"timestamp":"2023-07-24 16:49:43.666","level":"WARN","label":"fastcar-server.logger","message":"自定义警告"}
3
+ {"timestamp":"2023-07-24 16:49:43.667","level":"ERROR","label":"fastcar-server.logger","message":"自定义报错"}
@@ -0,0 +1,8 @@
1
+ {"timestamp":"2023-07-24 16:49:36.843","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2023-07-24 16:49:38.241","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2023-07-24 16:49:39.408","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2023-07-24 16:49:39.912","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2023-07-24 16:49:40.384","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2023-07-24 16:49:45.679","level":"INFO","label":"fastcar-server.sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
7
+ {"timestamp":"2023-07-24 16:49:45.680","level":"INFO","label":"fastcar-server.sys","message":"Call the method before the application stops"}
8
+ {"timestamp":"2023-07-24 16:49:50.692","level":"INFO","label":"fastcar-server.sys","message":"application stop"}
@@ -1,2 +0,0 @@
1
- {"timestamp":"2023-05-17 15:11:40.448","level":"ERROR","label":"sys","message":"Unsatisfied dependency expressed through [notFound] ","stack":"Error: Unsatisfied dependency expressed through [notFound] \n at NotFoundController.get (D:\\code\\fast-car\\fast-car\\fastcar-core\\src\\annotation\\bind\\AliasInjection.ts:16:27)\n at NotFoundController.getNotFound (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\controller\\NotFoundController.ts:14:15)\n at Context.<anonymous> (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\app.ts:89:13)\n at callFn (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:366:21)\n at Test.Runnable.run (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:354:5)\n at Runner.runTest (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:678:10)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:801:12\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:593:14)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:603:7\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:486:14)\n at Immediate._onImmediate (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:571:5)\n at processImmediate (node:internal/timers:466:21)\n at process.topLevelDomainCallback (node:domain:152:15)\n at process.callbackTrampoline (node:internal/async_hooks:128:24)"}
2
- {"timestamp":"2023-05-17 15:11:40.456","level":"ERROR","label":"sys","message":"Unsatisfied dependency expressed through [autoNotFound] ","stack":"Error: Unsatisfied dependency expressed through [autoNotFound] \n at NotFoundController.get (D:\\code\\fast-car\\fast-car\\fastcar-core\\src\\annotation\\bind\\CallDependency.ts:17:26)\n at NotFoundController.getAutoNotFound (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\controller\\NotFoundController.ts:18:15)\n at Context.<anonymous> (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\app.ts:95:13)\n at callFn (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:366:21)\n at Test.Runnable.run (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:354:5)\n at Runner.runTest (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:678:10)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:801:12\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:593:14)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:603:7\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:486:14)\n at Immediate._onImmediate (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:571:5)\n at processImmediate (node:internal/timers:466:21)\n at process.topLevelDomainCallback (node:domain:152:15)\n at process.callbackTrampoline (node:internal/async_hooks:128:24)"}
package/utils.d.ts CHANGED
@@ -57,6 +57,8 @@ export class CryptoUtil {
57
57
  static sha256Very(msg: string, serect: string, encodeMsg: string, encoding?: BinaryToTextEncoding): boolean;
58
58
 
59
59
  static getHashStr(num?: number): string;
60
+
61
+ static getHashStrByLength(serect: string, num: number): string;
60
62
  }
61
63
 
62
64
  export class FileUtil {
@@ -164,3 +166,7 @@ export class MixTool {
164
166
  //多个对象赋值
165
167
  static assign(target: any, source: any): void;
166
168
  }
169
+
170
+ export class IPUtils {
171
+ static isInnerIP(ip: string): boolean;
172
+ }
@@ -1,3 +0,0 @@
1
- {"timestamp":"2023-05-17 15:11:40.432","level":"INFO","label":"[fastcar-server] logger","message":"自定义的日志输出"}
2
- {"timestamp":"2023-05-17 15:11:40.433","level":"WARN","label":"[fastcar-server] logger","message":"自定义警告"}
3
- {"timestamp":"2023-05-17 15:11:40.434","level":"ERROR","label":"[fastcar-server] logger","message":"自定义报错"}
@@ -1,8 +0,0 @@
1
- {"timestamp":"2023-05-17 15:11:21.300","level":"INFO","label":"[fastcar-server] sys","message":"Start scanning component"}
2
- {"timestamp":"2023-05-17 15:11:40.421","level":"INFO","label":"[fastcar-server] sys","message":"Complete component scan"}
3
- {"timestamp":"2023-05-17 15:11:40.422","level":"INFO","label":"[fastcar-server] sys","message":"Call application initialization method"}
4
- {"timestamp":"2023-05-17 15:11:40.424","level":"INFO","label":"[fastcar-server] sys","message":"start server app is run"}
5
- {"timestamp":"2023-05-17 15:11:40.425","level":"INFO","label":"[fastcar-server] sys","message":"version 1.0.0"}
6
- {"timestamp":"2023-05-17 15:11:42.456","level":"INFO","label":"[fastcar-server] sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
7
- {"timestamp":"2023-05-17 15:11:42.457","level":"INFO","label":"[fastcar-server] sys","message":"Call the method before the application stops"}
8
- {"timestamp":"2023-05-17 15:11:47.460","level":"INFO","label":"[fastcar-server] sys","message":"application stop"}