@domain.js/main 0.1.0 → 0.1.1
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/.husky/pre-commit +1 -1
- package/dist/Errors/index.d.ts +16 -0
- package/dist/Errors/index.js +27 -0
- package/dist/basic-errors.d.ts +1 -0
- package/dist/basic-errors.js +10 -0
- package/dist/cfg/index.d.ts +6 -0
- package/dist/cfg/index.js +26 -0
- package/dist/defaults.d.ts +102 -0
- package/dist/defaults.js +36 -0
- package/dist/deps/cache/After.d.ts +1 -2
- package/dist/deps/cache/Before.js +3 -3
- package/dist/deps/cache/Define.d.ts +2 -0
- package/dist/deps/cache/index.js +2 -2
- package/dist/deps/checker/index.d.ts +4 -0
- package/dist/deps/checker/index.js +2 -3
- package/dist/deps/cia/index.d.ts +8 -0
- package/dist/deps/cia/index.js +3 -6
- package/dist/deps/cron/index.d.ts +4 -0
- package/dist/deps/cron/index.js +2 -4
- package/dist/deps/defines.d.ts +2 -2
- package/dist/deps/defines.js +2 -2
- package/dist/deps/errors/index.d.ts +1 -0
- package/dist/deps/errors/index.js +10 -0
- package/dist/deps/logger/index.d.ts +12 -1
- package/dist/deps/logger/index.js +6 -6
- package/dist/deps/parallel/index.d.ts +22 -4
- package/dist/deps/parallel/index.js +20 -11
- package/dist/deps/redis/index.d.ts +12 -1
- package/dist/deps/redis/index.js +12 -4
- package/dist/deps/request/index.d.ts +43 -0
- package/dist/deps/request/index.js +67 -0
- package/dist/deps/rest/index.d.ts +16 -3
- package/dist/deps/rest/index.js +41 -2
- package/dist/deps/rest/stats.d.ts +8 -1
- package/dist/deps/rest/stats.js +9 -2
- package/dist/deps/rest/utils.d.ts +8 -0
- package/dist/deps/rest/utils.js +1 -3
- package/dist/deps/schema/index.d.ts +20 -5
- package/dist/deps/schema/index.js +35 -11
- package/dist/deps/sequelize/index.d.ts +7 -2
- package/dist/deps/sequelize/index.js +3 -4
- package/dist/deps/signer/index.d.ts +33 -8
- package/dist/deps/signer/index.js +50 -27
- package/dist/dm/index.d.ts +16 -1
- package/dist/dm/index.js +15 -0
- package/dist/errors/index.d.ts +16 -0
- package/dist/errors/index.js +27 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +10 -0
- package/dist/http/defines.d.ts +45 -0
- package/dist/http/defines.js +2 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -4
- package/dist/npms.d.ts +88 -0
- package/dist/npms.js +31 -0
- package/dist/utils/index.d.ts +55 -13
- package/dist/utils/index.js +61 -15
- package/jest.config.js +8 -1
- package/package.json +13 -12
package/dist/utils/index.js
CHANGED
|
@@ -7,7 +7,11 @@ const RAND_STR_DICT = {
|
|
|
7
7
|
normal: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
8
8
|
strong: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&’()*+,-./:;<=>?@[]^_`{|}~",
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the MD5 value of the given string
|
|
12
|
+
* @param str string or An object that contains a toString method that returns a string
|
|
13
|
+
* @returns hex md5 string
|
|
14
|
+
*/
|
|
11
15
|
const md5 = (str) => {
|
|
12
16
|
const hash = crypto.createHash("md5");
|
|
13
17
|
return hash.update(str.toString()).digest().toString("hex");
|
|
@@ -25,19 +29,43 @@ function randStr(len, type) {
|
|
|
25
29
|
.join("");
|
|
26
30
|
}
|
|
27
31
|
exports.randStr = randStr;
|
|
28
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Replace line breaks and tabs in the string with ordinary spaces
|
|
34
|
+
* @param value string that will be replaced
|
|
35
|
+
* @returns has been replaced string
|
|
36
|
+
*/
|
|
29
37
|
const nt2space = (value) => value.replace(/(\\[ntrfv]|\s)+/g, " ").trim();
|
|
30
38
|
exports.nt2space = nt2space;
|
|
31
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* The first character of the string is capitalized
|
|
41
|
+
* @param value string
|
|
42
|
+
* @returns string
|
|
43
|
+
* @example ufrist("hello"); // Return a string is: "Hello"
|
|
44
|
+
* @see lcfirst
|
|
45
|
+
*/
|
|
32
46
|
const ucfirst = (value) => value[0].toUpperCase() + value.substring(1);
|
|
33
47
|
exports.ucfirst = ucfirst;
|
|
34
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* The first character of the string is lowercase
|
|
50
|
+
* @param value string
|
|
51
|
+
* @returns string
|
|
52
|
+
* @example ufrist("Hello"); // Return a string is: "hello"
|
|
53
|
+
* @see ucfirst
|
|
54
|
+
*/
|
|
35
55
|
const lcfirst = (value) => value[0].toLowerCase() + value.substring(1);
|
|
36
56
|
exports.lcfirst = lcfirst;
|
|
37
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Pause, waiting
|
|
59
|
+
* @param ms The time you want to wait, in milliseconds
|
|
60
|
+
* @returns None
|
|
61
|
+
*/
|
|
38
62
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
39
63
|
exports.sleep = sleep;
|
|
40
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Freeze a object and deepth
|
|
66
|
+
* @param object The object that will be freezed
|
|
67
|
+
* @returns freezed object
|
|
68
|
+
*/
|
|
41
69
|
const deepFreeze = (object) => {
|
|
42
70
|
// Retrieve the property names defined on object
|
|
43
71
|
const propNames = Object.getOwnPropertyNames(object);
|
|
@@ -50,24 +78,42 @@ const deepFreeze = (object) => {
|
|
|
50
78
|
return Object.freeze(object);
|
|
51
79
|
};
|
|
52
80
|
exports.deepFreeze = deepFreeze;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Mask exceptions of functions
|
|
83
|
+
* @param fn The function will be mask exceptions
|
|
84
|
+
* @param errorLog Error handle function, when has happed throw exception
|
|
85
|
+
* @returns Wrapped function
|
|
86
|
+
*/
|
|
87
|
+
const tryCatchLog = (fn, errorLog) => {
|
|
88
|
+
const wrapped = async (...args) => {
|
|
89
|
+
try {
|
|
90
|
+
await fn(...args);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
errorLog(e);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return wrapped;
|
|
60
97
|
};
|
|
61
98
|
exports.tryCatchLog = tryCatchLog;
|
|
62
99
|
/**
|
|
63
|
-
|
|
100
|
+
* Determine whether a second timestamp has expired
|
|
101
|
+
* @param time timestamp
|
|
102
|
+
* @param life Effective time, seconds
|
|
103
|
+
* @returns true or false
|
|
64
104
|
*/
|
|
65
105
|
const inExpired = (time, life) => {
|
|
66
106
|
const now = (Date.now() / 1000) | 0;
|
|
67
107
|
return time < now - life;
|
|
68
108
|
};
|
|
69
109
|
exports.inExpired = inExpired;
|
|
70
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Modify a URL address, add some attributes and delete some attributes
|
|
112
|
+
* @param address URL address
|
|
113
|
+
* @param adds The params will be expand to address
|
|
114
|
+
* @param removes The string list will be remove from address
|
|
115
|
+
* @returns Modified address
|
|
116
|
+
*/
|
|
71
117
|
const modifiyURL = (address, adds, removes) => {
|
|
72
118
|
const obj = new URL(address);
|
|
73
119
|
if (typeof adds === "object") {
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domain.js/main",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "DDD framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,16 +15,6 @@
|
|
|
15
15
|
"author": "Redstone Zhao",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@types/async": "^3.2.10",
|
|
19
|
-
"@types/crypto-js": "^4.0.2",
|
|
20
|
-
"@types/ioredis": "^4.28.1",
|
|
21
|
-
"@types/jest": "^27.0.3",
|
|
22
|
-
"@types/lodash": "^4.14.177",
|
|
23
|
-
"@types/lru-cache": "^5.1.1",
|
|
24
|
-
"@types/restify": "^8.5.4",
|
|
25
|
-
"@types/restify-errors": "^4.3.4",
|
|
26
|
-
"@types/uuid": "^8.3.3",
|
|
27
|
-
"@types/validator": "^13.7.0",
|
|
28
18
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
29
19
|
"@typescript-eslint/parser": "^4.22.0",
|
|
30
20
|
"babel-eslint": "^10.1.0",
|
|
@@ -42,6 +32,7 @@
|
|
|
42
32
|
"prettier": "^2.3.0",
|
|
43
33
|
"sequelize-json-schema": "^2.1.1",
|
|
44
34
|
"ts-jest": "^27.0.7",
|
|
35
|
+
"ts-node": "^10.4.0",
|
|
45
36
|
"typescript": "^4.5.2"
|
|
46
37
|
},
|
|
47
38
|
"prettier": {
|
|
@@ -55,6 +46,16 @@
|
|
|
55
46
|
]
|
|
56
47
|
},
|
|
57
48
|
"dependencies": {
|
|
49
|
+
"@types/async": "^3.2.10",
|
|
50
|
+
"@types/crypto-js": "^4.0.2",
|
|
51
|
+
"@types/ioredis": "^4.28.1",
|
|
52
|
+
"@types/jest": "^27.0.3",
|
|
53
|
+
"@types/lodash": "^4.14.177",
|
|
54
|
+
"@types/lru-cache": "^5.1.1",
|
|
55
|
+
"@types/restify": "^8.5.4",
|
|
56
|
+
"@types/restify-errors": "^4.3.4",
|
|
57
|
+
"@types/uuid": "^8.3.3",
|
|
58
|
+
"@types/validator": "^13.7.0",
|
|
58
59
|
"ajv": "^8.8.1",
|
|
59
60
|
"ajv-formats": "^2.1.1",
|
|
60
61
|
"async": "^3.2.2",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"restify-errors": "^8.0.2",
|
|
73
74
|
"sequelize": "^6.9.0",
|
|
74
75
|
"swagger-ui-restify": "^3.0.8",
|
|
75
|
-
"
|
|
76
|
+
"type-fest": "^2.8.0",
|
|
76
77
|
"uuid": "^8.3.2",
|
|
77
78
|
"xlsx": "^0.17.4"
|
|
78
79
|
}
|