@ywfe/fe-tools 1.2.1-beta.24 → 1.2.1-beta.25
Sign up to get free protection for your applications and to get access to all the features.
- package/JSON2String.ts +6 -3
- package/index.ts +0 -2
- package/lib/JSON2String.d.ts +3 -1
- package/lib/index.d.ts +0 -2
- package/lib/ywfe-tools.cjs +5 -8795
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +6 -8794
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +1 -3
- package/lib/ywfe-tools.umd.js.map +1 -1
- package/package.json +1 -1
- package/lib/request.d.ts +0 -9
- package/lib/userInputToJson.d.ts +0 -8
- package/request.ts +0 -55
- package/userInputToJson.ts +0 -24
package/package.json
CHANGED
package/lib/request.d.ts
DELETED
package/lib/userInputToJson.d.ts
DELETED
package/request.ts
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
// Ctrl-S保存代码
|
2
|
-
import { querystring } from "@ywfe/utils";
|
3
|
-
interface RequestOptions {
|
4
|
-
url: string;
|
5
|
-
method?: string;
|
6
|
-
params?: any;
|
7
|
-
}
|
8
|
-
async function request({ input }: { input: RequestOptions }) {
|
9
|
-
const method = input.method || "GET";
|
10
|
-
const basePathMap = new Map([
|
11
|
-
["prod", "https://gateway.ywwl.com"],
|
12
|
-
["test", "https://test-gateway.ywwl.com"],
|
13
|
-
["test2", "https://test2-gateway.ywwl.com"],
|
14
|
-
["dev", "https://dev-gateway.ywwl.com"],
|
15
|
-
]);
|
16
|
-
const getBasePath = () => {
|
17
|
-
const env = "{{env}}";
|
18
|
-
return basePathMap.get(env);
|
19
|
-
};
|
20
|
-
const isValidURL = (url:string) => {
|
21
|
-
var pattern = new RegExp(
|
22
|
-
"^(https?:\\/\\/)?" + // protocol
|
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);
|
31
|
-
};
|
32
|
-
const prefix = getBasePath();
|
33
|
-
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
34
|
-
const fetchOption: { [key: string]: any } = {
|
35
|
-
method: method,
|
36
|
-
headers: {
|
37
|
-
"Content-type": "application/json",
|
38
|
-
"x-token": "{{token}}",
|
39
|
-
},
|
40
|
-
};
|
41
|
-
if (method.toUpperCase() === "POST") {
|
42
|
-
fetchOption.body = JSON.stringify(input.params);
|
43
|
-
} else if (method.toUpperCase() === "GET") {
|
44
|
-
requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`;
|
45
|
-
}
|
46
|
-
const response = await fetch(requestUrl, fetchOption);
|
47
|
-
if (!response.ok) {
|
48
|
-
const message = `An error has occured: ${response.status}`;
|
49
|
-
return { success: false, message };
|
50
|
-
}
|
51
|
-
const result = await response.json();
|
52
|
-
return result;
|
53
|
-
}
|
54
|
-
|
55
|
-
export default request
|
package/userInputToJson.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import {request} from './index'
|
2
|
-
// Ctrl-S保存代码
|
3
|
-
interface userInput {
|
4
|
-
userInput?: string;
|
5
|
-
rules?: string;
|
6
|
-
}
|
7
|
-
async function userInputToJson({ input }: { input: userInput }) {
|
8
|
-
console.log("input", input);
|
9
|
-
const res: { message: string; success: boolean; data: any } =
|
10
|
-
await request({
|
11
|
-
input: {
|
12
|
-
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
13
|
-
method: "GET",
|
14
|
-
params: input,
|
15
|
-
},
|
16
|
-
});
|
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
|
-
}
|
23
|
-
}
|
24
|
-
export default userInputToJson
|