melperjs 2.0.1 → 3.0.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 +31 -19
- package/lib/index.js +28 -7
- package/package.json +1 -1
- package/src/index.js +31 -7
- package/test/script.js +7 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ const nodeHelper = require("melperjs/node");
|
|
|
21
21
|
const axios = require("axios");
|
|
22
22
|
|
|
23
23
|
(async () => {
|
|
24
|
-
console.log(helper.Exception("something went wrong"));
|
|
24
|
+
console.log(helper.Exception("something went wrong", {status: 500}, "axios error"));
|
|
25
25
|
console.log(helper.time());
|
|
26
26
|
await helper.sleepMs(1000);
|
|
27
27
|
console.log(helper.time());
|
|
@@ -43,8 +43,12 @@ const axios = require("axios");
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}));
|
|
46
|
-
console.log("
|
|
47
|
-
console.log("
|
|
46
|
+
console.log("str empty", helper.checkEmpty(""));
|
|
47
|
+
console.log("1 empty", helper.checkEmpty(1));
|
|
48
|
+
console.log("[] empty", helper.checkEmpty([]));
|
|
49
|
+
console.log(helper.upperCaseFirst("first letter upper"));
|
|
50
|
+
console.log(helper.lowerCaseFirst("First Letter Lower"));
|
|
51
|
+
console.log(helper.titleString("THIS mUsT be Title"));
|
|
48
52
|
console.log(helper.limitString("LONG TEXT", 7));
|
|
49
53
|
console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
|
|
50
54
|
console.log(helper.randomString(32, true, true));
|
|
@@ -75,33 +79,41 @@ const axios = require("axios");
|
|
|
75
79
|
})();
|
|
76
80
|
|
|
77
81
|
/*
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
{
|
|
83
|
+
name: 'AxiosError',
|
|
84
|
+
message: 'something went wrong',
|
|
85
|
+
response: { status: 500 }
|
|
86
|
+
}
|
|
87
|
+
1700529489
|
|
88
|
+
1700529490
|
|
89
|
+
1700529491
|
|
82
90
|
Promise timed out after 1000ms
|
|
83
91
|
{ x: 1, y: 2, c: { d: true } }
|
|
92
|
+
str empty true
|
|
84
93
|
1 empty false
|
|
85
94
|
[] empty true
|
|
95
|
+
First letter upper
|
|
96
|
+
first Letter Lower
|
|
97
|
+
This Must Be Title
|
|
86
98
|
LONG...
|
|
87
99
|
SAFE TEXT
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
15WY89Q4yAMCzPmNsU0ANGX2eiOz7Gfy
|
|
101
|
+
9eb93429
|
|
102
|
+
7e1fb299-251c-4a75-bb37-f7cc3a730121
|
|
91
103
|
strongProbability
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
STIhrofUYVAQ4anplyJW2T7GEwSJkuk7
|
|
105
|
+
6db791a1
|
|
106
|
+
0cbef42d-a277-4f66-8bcc-e4de337c2b56
|
|
95
107
|
strongProbability
|
|
96
108
|
8d777f385d3dfec8815d20f7496026dc
|
|
97
|
-
$2b$10$
|
|
109
|
+
$2b$10$IsuTscKKHbcf6sBp7BrCOOcg6A8v32G9UxzdYN3Y6xyMaUynweYX2
|
|
98
110
|
passwordHash true
|
|
99
111
|
{
|
|
100
|
-
'1P_JAR': '2023-11-
|
|
101
|
-
AEC: '
|
|
102
|
-
NID: '511=
|
|
112
|
+
'1P_JAR': '2023-11-21-01',
|
|
113
|
+
AEC: 'Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM',
|
|
114
|
+
NID: '511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw'
|
|
103
115
|
}
|
|
104
|
-
1P_JAR=2023-11-
|
|
116
|
+
1P_JAR=2023-11-21-01;AEC=Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM;NID=511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw
|
|
105
117
|
http://id:pw-{SESSION}@127.0.0.1:8080
|
|
106
118
|
{
|
|
107
119
|
protocol: 'http',
|
|
@@ -109,7 +121,7 @@ http://id:pw-{SESSION}@127.0.0.1:8080
|
|
|
109
121
|
port: 8080,
|
|
110
122
|
auth: { username: 'id', password: 'pw-{SESSION}' }
|
|
111
123
|
}
|
|
112
|
-
http://id:pw-
|
|
124
|
+
http://id:pw-527ef984@127.0.0.1:8080
|
|
113
125
|
127.0.0.1
|
|
114
126
|
HTTP CODE: 401 FOREIGN false
|
|
115
127
|
HTTP CODE: 407 FOREIGN (Failed Proxy Auth) true
|
package/lib/index.js
CHANGED
|
@@ -4,13 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Exception = Exception;
|
|
7
|
+
exports.checkEmpty = checkEmpty;
|
|
7
8
|
exports.cookieDict = cookieDict;
|
|
8
9
|
exports.cookieHeader = cookieHeader;
|
|
9
10
|
exports.findKeyNode = findKeyNode;
|
|
10
11
|
exports.foreignHttpError = foreignHttpError;
|
|
11
12
|
exports.hashBcrypt = hashBcrypt;
|
|
12
|
-
exports.isEmpty = isEmpty;
|
|
13
13
|
exports.limitString = limitString;
|
|
14
|
+
exports.lowerCaseFirst = lowerCaseFirst;
|
|
15
|
+
exports.pascalCase = pascalCase;
|
|
14
16
|
exports.promiseTimeout = promiseTimeout;
|
|
15
17
|
exports.randomHex = randomHex;
|
|
16
18
|
exports.randomString = randomString;
|
|
@@ -20,6 +22,8 @@ exports.safeString = safeString;
|
|
|
20
22
|
exports.sleep = sleep;
|
|
21
23
|
exports.sleepMs = sleepMs;
|
|
22
24
|
exports.time = time;
|
|
25
|
+
exports.titleString = titleString;
|
|
26
|
+
exports.upperCaseFirst = upperCaseFirst;
|
|
23
27
|
exports.verifyBcrypt = verifyBcrypt;
|
|
24
28
|
var _ = _interopRequireWildcard(require("lodash"));
|
|
25
29
|
var _xss = _interopRequireDefault(require("xss"));
|
|
@@ -28,11 +32,12 @@ var _setCookieParser = _interopRequireDefault(require("set-cookie-parser"));
|
|
|
28
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
30
34
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
31
|
-
function Exception(message, response = {}) {
|
|
35
|
+
function Exception(message, response = {}, name = null) {
|
|
32
36
|
response.status = response.status || 400;
|
|
33
37
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
name: pascalCase(name),
|
|
39
|
+
message,
|
|
40
|
+
response
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
function time() {
|
|
@@ -71,13 +76,28 @@ function findKeyNode(key, node, pair = null) {
|
|
|
71
76
|
}
|
|
72
77
|
return null;
|
|
73
78
|
}
|
|
74
|
-
function
|
|
79
|
+
function checkEmpty(value) {
|
|
75
80
|
if (typeof value === "number") {
|
|
76
81
|
return value === 0;
|
|
77
82
|
} else {
|
|
78
83
|
return _.isEmpty(value);
|
|
79
84
|
}
|
|
80
85
|
}
|
|
86
|
+
function pascalCase(str) {
|
|
87
|
+
return upperCaseFirst(_.camelCase(str));
|
|
88
|
+
}
|
|
89
|
+
function upperCaseFirst(str) {
|
|
90
|
+
str = str || "";
|
|
91
|
+
return _.upperCase(str[0]) + str.slice(1);
|
|
92
|
+
}
|
|
93
|
+
function lowerCaseFirst(str) {
|
|
94
|
+
str = str || "";
|
|
95
|
+
return _.lowerCase(str[0]) + str.slice(1);
|
|
96
|
+
}
|
|
97
|
+
function titleString(str) {
|
|
98
|
+
str = str || "";
|
|
99
|
+
return str.split(' ').map(word => _.capitalize(word)).join(' ');
|
|
100
|
+
}
|
|
81
101
|
function limitString(str, limit = 35) {
|
|
82
102
|
str = str || "";
|
|
83
103
|
if (str.length <= limit) {
|
|
@@ -86,8 +106,9 @@ function limitString(str, limit = 35) {
|
|
|
86
106
|
return str.substring(0, limit - 3) + "...";
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
|
-
function safeString(
|
|
90
|
-
|
|
109
|
+
function safeString(str) {
|
|
110
|
+
str = str || "";
|
|
111
|
+
return (0, _xss.default)(str, {
|
|
91
112
|
whiteList: {},
|
|
92
113
|
stripIgnoreTag: true,
|
|
93
114
|
stripIgnoreTagBody: ["script"]
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from "lodash";
|
|
2
2
|
import xss from "xss";
|
|
3
3
|
import bcrypt from "bcrypt";
|
|
4
4
|
import setCookieParser from "set-cookie-parser";
|
|
5
5
|
|
|
6
|
-
export function Exception(message, response = {}) {
|
|
6
|
+
export function Exception(message, response = {}, name = null) {
|
|
7
7
|
response.status = response.status || 400;
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
name: pascalCase(name),
|
|
10
|
+
message,
|
|
11
|
+
response,
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -55,7 +56,7 @@ export function findKeyNode(key, node, pair = null) {
|
|
|
55
56
|
return null;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export function
|
|
59
|
+
export function checkEmpty(value) {
|
|
59
60
|
if (typeof value === "number") {
|
|
60
61
|
return value === 0;
|
|
61
62
|
} else {
|
|
@@ -63,6 +64,28 @@ export function isEmpty(value) {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
export function pascalCase(str){
|
|
68
|
+
return upperCaseFirst(_.camelCase(str));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function upperCaseFirst(str) {
|
|
72
|
+
str = str || "";
|
|
73
|
+
return _.upperCase(str[0]) + str.slice(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function lowerCaseFirst(str) {
|
|
77
|
+
str = str || "";
|
|
78
|
+
return _.lowerCase(str[0]) + str.slice(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function titleString(str) {
|
|
82
|
+
str = str || "";
|
|
83
|
+
return str
|
|
84
|
+
.split(' ')
|
|
85
|
+
.map(word => _.capitalize(word))
|
|
86
|
+
.join(' ');
|
|
87
|
+
}
|
|
88
|
+
|
|
66
89
|
export function limitString(str, limit = 35) {
|
|
67
90
|
str = str || "";
|
|
68
91
|
if (str.length <= limit) {
|
|
@@ -72,8 +95,9 @@ export function limitString(str, limit = 35) {
|
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
|
|
75
|
-
export function safeString(
|
|
76
|
-
|
|
98
|
+
export function safeString(str) {
|
|
99
|
+
str = str || "";
|
|
100
|
+
return xss(str, {
|
|
77
101
|
whiteList: {},
|
|
78
102
|
stripIgnoreTag: true,
|
|
79
103
|
stripIgnoreTagBody: ["script"]
|
package/test/script.js
CHANGED
|
@@ -4,7 +4,7 @@ import axios from "axios"
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
(async () => {
|
|
7
|
-
console.log(helper.Exception("something went wrong"));
|
|
7
|
+
console.log(helper.Exception("something went wrong", {status: 500}, "axios error"));
|
|
8
8
|
console.log(helper.time());
|
|
9
9
|
await helper.sleepMs(1000);
|
|
10
10
|
console.log(helper.time());
|
|
@@ -26,8 +26,12 @@ import axios from "axios"
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}));
|
|
29
|
-
console.log("
|
|
30
|
-
console.log("
|
|
29
|
+
console.log("str empty", helper.checkEmpty(""));
|
|
30
|
+
console.log("1 empty", helper.checkEmpty(1));
|
|
31
|
+
console.log("[] empty", helper.checkEmpty([]));
|
|
32
|
+
console.log(helper.upperCaseFirst("first letter upper"));
|
|
33
|
+
console.log(helper.lowerCaseFirst("First Letter Lower"));
|
|
34
|
+
console.log(helper.titleString("THIS mUsT be Title"));
|
|
31
35
|
console.log(helper.limitString("LONG TEXT", 7));
|
|
32
36
|
console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
|
|
33
37
|
console.log(helper.randomString(32, true, true));
|