@ywfe/fe-tools 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/JSON2String.ts +14 -0
- package/gitlabGet.ts +39 -0
- package/index.ts +3 -0
- package/lib/JSON2String.d.ts +7 -0
- package/lib/gitlabGet.d.ts +9 -0
- package/lib/index.d.ts +3 -0
- package/lib/request.d.ts +9 -0
- package/lib/userInputToJson.d.ts +5 -1
- package/lib/ywfe-tools.cjs +8775 -8
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +8773 -9
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +4 -0
- package/lib/ywfe-tools.umd.js.map +1 -0
- package/package.json +1 -2
- package/request.ts +49 -0
- package/rollup.config.js +1 -4
- package/tsconfig.json +4 -2
- package/userInputToJson.ts +15 -11
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"private": false,
|
3
3
|
"name": "@ywfe/fe-tools",
|
4
|
-
"version": "
|
4
|
+
"version": "2.0.0",
|
5
5
|
"description": "工具函数库",
|
6
6
|
"main": "./lib/ywfe-tools.cjs",
|
7
7
|
"module": "./lib/ywfe-tools.esm.js",
|
@@ -12,7 +12,6 @@
|
|
12
12
|
"prepublishOnly": "npm run build && npm run build:type",
|
13
13
|
"test": "jest --coverage"
|
14
14
|
},
|
15
|
-
"repository": "ywfe",
|
16
15
|
"author": {
|
17
16
|
"name": "YWFE",
|
18
17
|
"email": "ywfe@ywwl.com",
|
package/request.ts
ADDED
@@ -0,0 +1,49 @@
|
|
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
|
+
const regex = /^https?:\/\//;
|
22
|
+
return regex.test(url);
|
23
|
+
};
|
24
|
+
const prefix = getBasePath();
|
25
|
+
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
26
|
+
const fetchOption: { [key: string]: any } = {
|
27
|
+
method: method,
|
28
|
+
headers: {
|
29
|
+
"Content-type": "application/json",
|
30
|
+
"x-token": "{{token}}",
|
31
|
+
},
|
32
|
+
};
|
33
|
+
if (method.toUpperCase() === "POST") {
|
34
|
+
fetchOption.body = JSON.stringify(input.params);
|
35
|
+
} else if (method.toUpperCase() === "GET") {
|
36
|
+
requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`;
|
37
|
+
}
|
38
|
+
const response = await fetch(requestUrl, fetchOption);
|
39
|
+
if (!response.ok) {
|
40
|
+
const message = `An error has occured: ${response.status}`;
|
41
|
+
console.log('req result', message);
|
42
|
+
return { success: false, message };
|
43
|
+
}
|
44
|
+
const result = await response.json();
|
45
|
+
console.log('req result',result);
|
46
|
+
return result;
|
47
|
+
}
|
48
|
+
|
49
|
+
export default request
|
package/rollup.config.js
CHANGED
@@ -39,7 +39,7 @@ const formats = {
|
|
39
39
|
|
40
40
|
const config = {
|
41
41
|
input: './index.ts',
|
42
|
-
inlineDynamicImports: true,
|
42
|
+
// inlineDynamicImports: true,
|
43
43
|
output: [formats.esm, formats.commonjs],
|
44
44
|
external: ['react', 'react-dom'],
|
45
45
|
plugins: [
|
@@ -49,9 +49,6 @@ const config = {
|
|
49
49
|
progress({
|
50
50
|
clearLine: false,
|
51
51
|
}),
|
52
|
-
replace({
|
53
|
-
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
|
54
|
-
}),
|
55
52
|
nodeResolver(),
|
56
53
|
commonjs(),
|
57
54
|
typescript(),
|
package/tsconfig.json
CHANGED
package/userInputToJson.ts
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
import {request} from './index'
|
1
2
|
// Ctrl-S保存代码
|
2
3
|
interface userInput {
|
3
|
-
userInput?:string
|
4
|
-
rules?:string
|
4
|
+
userInput?: string;
|
5
|
+
rules?: string;
|
5
6
|
}
|
6
|
-
async function userInputToJson({input}:{input:userInput}){
|
7
|
-
const {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
async function userInputToJson({ input }: { input: userInput }) {
|
8
|
+
const res: { message: string; success: boolean; data: any } =
|
9
|
+
await request({
|
10
|
+
input: {
|
11
|
+
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
12
|
+
method: "GET",
|
13
|
+
params: input,
|
14
|
+
},
|
15
|
+
});
|
16
|
+
console.log('userINput1',res)
|
17
|
+
return res
|
18
|
+
|
15
19
|
}
|
16
20
|
export default userInputToJson
|