@ywfe/fe-tools 1.2.1-beta.3 → 1.2.1-beta.30

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@ywfe/fe-tools",
4
- "version": "1.2.1-beta.3",
4
+ "version": "1.2.1-beta.30",
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 CHANGED
@@ -1,49 +1,55 @@
1
1
  // Ctrl-S保存代码
2
- import {querystring} from '@ywfe/utils'
2
+ import { querystring } from "@ywfe/utils";
3
3
  interface RequestOptions {
4
- url:string,
5
- method?:string,
6
- params?:any
4
+ url: string;
5
+ method?: string;
6
+ params?: any;
7
7
  }
8
- async function request({input}:{input:RequestOptions}){
9
- const method = input.method || 'GET';
8
+ async function request({ input }: { input: RequestOptions }) {
9
+ const method = input.method || "GET";
10
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
- ])
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
16
  const getBasePath = () => {
17
- const env = '{{env}}';
18
- return basePathMap.get(env);
17
+ const env = "{{env}}";
18
+ return basePathMap.get(env);
19
19
  };
20
- const isValidURL = (url:string)=> {
20
+ const isValidURL = (url:string) => {
21
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
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
28
30
  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} = {
31
+ };
32
+ const prefix = getBasePath();
33
+ let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
34
+ const fetchOption: { [key: string]: any } = {
33
35
  method: method,
34
36
  headers: {
35
- 'Content-type': 'application/json',
36
- 'x-token': '{{token}}',
37
+ "Content-type": "application/json",
38
+ "x-token": "{{token}}",
37
39
  },
38
40
  };
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
-
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 };
44
50
  }
45
-
46
- const res = await fetch(requestUrl, fetchOption);
47
- return res.json();
51
+ const result = await response.json();
52
+ return result;
48
53
  }
54
+
49
55
  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(),
@@ -1,17 +1,19 @@
1
- // Ctrl-S保存代码
2
1
  import {request} from './index'
2
+ // Ctrl-S保存代码
3
3
  interface userInput {
4
- userInput?:string,
5
- rules?:string,
4
+ userInput?: string;
5
+ rules?: string;
6
6
  }
7
- async function userInputToJson({input}:{input:userInput}){
8
- const {userInput, rules} = input
9
- const res = await request({
10
- input:{
11
- url:"https://fc-typechat.ywwl.com/userInputToJson",
12
- method:"GET"
13
- }
14
- })
15
- return "2"
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
+ return res
17
+
16
18
  }
17
19
  export default userInputToJson