@ywfe/fe-tools 1.2.1-beta.9 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/index.ts +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/userInputToJson.d.ts +1 -1
- package/lib/ywfe-tools.cjs +8 -8717
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +9 -8717
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/package.json +1 -1
- package/userInputToJson.ts +11 -19
- package/lib/request.d.ts +0 -9
- package/request.ts +0 -49
package/package.json
CHANGED
package/userInputToJson.ts
CHANGED
@@ -1,24 +1,16 @@
|
|
1
|
-
import {request} from './index'
|
2
1
|
// Ctrl-S保存代码
|
3
2
|
interface userInput {
|
4
|
-
userInput?:
|
5
|
-
rules?:
|
3
|
+
userInput?:string,
|
4
|
+
rules?:string,
|
6
5
|
}
|
7
|
-
async function userInputToJson({
|
8
|
-
|
9
|
-
const res
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
}
|
6
|
+
async function userInputToJson({input}:{input:userInput}){
|
7
|
+
const {userInput, rules} = input
|
8
|
+
//const res = await fetools.request({
|
9
|
+
//input:{
|
10
|
+
//url:"https://fc-typechat.ywwl.com/userInputToJson",
|
11
|
+
//method:"GET"
|
12
|
+
//}
|
13
|
+
//})
|
14
|
+
return "2"
|
23
15
|
}
|
24
16
|
export default userInputToJson
|
package/lib/request.d.ts
DELETED
package/request.ts
DELETED
@@ -1,49 +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_]*)?$','i'); // fragment locator
|
28
|
-
return !!pattern.test(url);
|
29
|
-
}
|
30
|
-
const prefix = getBasePath()
|
31
|
-
let requestUrl = isValidURL(input.url) ? input.url :`${prefix}${input.url}`
|
32
|
-
const fetchOption: {[key:string]:any} = {
|
33
|
-
method: method,
|
34
|
-
headers: {
|
35
|
-
'Content-type': 'application/json',
|
36
|
-
'x-token': '{{token}}',
|
37
|
-
},
|
38
|
-
};
|
39
|
-
if (method.toUpperCase() === 'POST') {
|
40
|
-
fetchOption.body = JSON.stringify(input.params);
|
41
|
-
}else if(method.toUpperCase() === 'GET'){
|
42
|
-
requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
const res = await fetch(requestUrl, fetchOption);
|
47
|
-
return res.json();
|
48
|
-
}
|
49
|
-
export default request
|