@ywfe/fe-tools 1.2.1-beta.30 → 1.2.1-beta.32
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/userInputToJson.d.ts +1 -5
- package/lib/ywfe-tools.cjs +21 -16
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +21 -16
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +2 -2
- package/lib/ywfe-tools.umd.js.map +1 -1
- package/package.json +1 -1
- package/request.ts +4 -10
- package/userInputToJson.ts +7 -2
package/package.json
CHANGED
package/request.ts
CHANGED
@@ -18,16 +18,8 @@ async function request({ input }: { input: RequestOptions }) {
|
|
18
18
|
return basePathMap.get(env);
|
19
19
|
};
|
20
20
|
const isValidURL = (url:string) => {
|
21
|
-
|
22
|
-
|
23
|
-
"((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|" + // domain name
|
24
|
-
"((\d{1,3}\.){3}\d{1,3}))" + // OR ip (v4) address
|
25
|
-
"(\:\d+)?(\/[-a-z\d%_.~+]*)*" + // port and path
|
26
|
-
"(\?[;&a-z\d%_.~+=-]*)?" + // query string
|
27
|
-
"(\#[-a-z\d_]*)?$",
|
28
|
-
"i"
|
29
|
-
); // fragment locator
|
30
|
-
return !!pattern.test(url);
|
21
|
+
const regex = /^https?:\/\//;
|
22
|
+
return regex.test(url);
|
31
23
|
};
|
32
24
|
const prefix = getBasePath();
|
33
25
|
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
@@ -46,9 +38,11 @@ async function request({ input }: { input: RequestOptions }) {
|
|
46
38
|
const response = await fetch(requestUrl, fetchOption);
|
47
39
|
if (!response.ok) {
|
48
40
|
const message = `An error has occured: ${response.status}`;
|
41
|
+
console.log('req result', message);
|
49
42
|
return { success: false, message };
|
50
43
|
}
|
51
44
|
const result = await response.json();
|
45
|
+
console.log('req result',result);
|
52
46
|
return result;
|
53
47
|
}
|
54
48
|
|
package/userInputToJson.ts
CHANGED
@@ -5,6 +5,7 @@ interface userInput {
|
|
5
5
|
rules?: string;
|
6
6
|
}
|
7
7
|
async function userInputToJson({ input }: { input: userInput }) {
|
8
|
+
console.log("input", input);
|
8
9
|
const res: { message: string; success: boolean; data: any } =
|
9
10
|
await request({
|
10
11
|
input: {
|
@@ -13,7 +14,11 @@ async function userInputToJson({ input }: { input: userInput }) {
|
|
13
14
|
params: input,
|
14
15
|
},
|
15
16
|
});
|
16
|
-
|
17
|
-
|
17
|
+
if (res.success) {
|
18
|
+
const result = res.data;
|
19
|
+
return result.success ? result.data : result;
|
20
|
+
} else {
|
21
|
+
return res.success ? res.data : res;
|
22
|
+
}
|
18
23
|
}
|
19
24
|
export default userInputToJson
|