@ywfe/fe-tools 1.0.2-beta.3 → 1.0.2-beta.5

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@ywfe/fe-tools",
3
- "version": "1.0.2-beta.3",
3
+ "version": "1.0.2-beta.5",
4
4
  "description": "工具函数库",
5
- "main": "./dist/bundle.js",
6
- "module": "./dist/bundle.js",
5
+ "main": "lib/ywfe-tools.esm.js",
6
+ "module": "lib/ywfe-tools.esm.js",
7
+ "browser": "lib/ywfe-tools.umd.js",
8
+ "types": "lib/index.d.ts",
7
9
  "type": "module",
8
- "files": [
9
- "dist"
10
- ],
11
10
  "scripts": {
12
11
  "build": "rollup -c",
13
12
  "prepublishOnly": "npm run build"
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)=> {
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
@@ -0,0 +1,26 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import resolve from '@rollup/plugin-node-resolve';
4
+ import babel from 'rollup-plugin-babel';
5
+ import { terser } from 'rollup-plugin-terser';
6
+ export default {
7
+ input:'./index.ts', // 入口文件
8
+ output:{
9
+ file:'lib/ywfe-tools.esm.js', // 输出文件
10
+ format: 'es', // 输出格式 amd / es / cjs / iife / umd / system
11
+ name:'func', // 当format为iife和umd时必须提供,将作为全局变量挂在window(浏览器环境)下:window.A=...
12
+ sourcemap:true // 生成bundle.js.map文件,方便调试
13
+ },
14
+ treeshake: true,
15
+ plugins: [
16
+ resolve(),
17
+ typescript(),
18
+ commonjs({
19
+ include: /node_modules/,
20
+ }),
21
+ babel({
22
+ exclude: 'node_modules/**', // 排除转换node_modules下的文件
23
+ }),
24
+ // terser(), // 代码压缩
25
+ ]
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "outDir": "./lib",
5
+ /* Basic Options */
6
+ "target": "es2017",
7
+ "module": "esnext",
8
+ "skipLibCheck": true,
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "composite": false,
13
+ "esModuleInterop": true,
14
+ "importHelpers": true,
15
+ /* Strict Type-Checking Options */
16
+ "strict": true,
17
+ "strictBindCallApply": true,
18
+ /* Additional Checks */
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noImplicitAny": true,
22
+ "noImplicitThis": true,
23
+ "noFallthroughCasesInSwitch": true,
24
+ /* Module Resolution Options */
25
+ "moduleResolution": "node",
26
+ "resolveJsonModule": true,
27
+ /* Advanced Options */
28
+ "forceConsistentCasingInFileNames": true,
29
+ /* 实验支持 */
30
+ "experimentalDecorators": true,
31
+ "emitDecoratorMetadata": true,
32
+ /* Cli Options */
33
+ "pretty": true,
34
+ "jsx": "react",
35
+ "allowJs": true,
36
+ "baseUrl": "./"
37
+ },
38
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationDir": "./lib",
6
+ "emitDeclarationOnly": true
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ // Ctrl-S保存代码 测试
2
+ interface userInput {
3
+ userInput?:string,
4
+ rules?:string,
5
+ }
6
+ async function userInputToJson({input}:{input:userInput}){
7
+ const {userInput, rules} = input
8
+ console.log('cesh')
9
+ //@ts-ignore
10
+ const res = await feTools.request({
11
+ input:{
12
+ url:"https://fc-typechat.ywwl.com/userInputToJson",
13
+ method:"GET"
14
+ }
15
+ })
16
+ return res
17
+ }
18
+ export default userInputToJson