@ywfe/fe-tools 1.0.2-beta.13 → 1.0.2-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/{lib/ywfe-tools.esm.js → dist/bundle.js} +155 -100
- package/dist/bundle.js.map +1 -0
- package/package.json +17 -20
- package/index.ts +0 -2
- package/jest.config.js +0 -12
- package/lib/index.d.ts +0 -2
- package/lib/request.d.ts +0 -9
- package/lib/userInputToJson.d.ts +0 -8
- package/lib/ywfe-tools.cjs.js +0 -8782
- package/lib/ywfe-tools.cjs.js.map +0 -1
- package/lib/ywfe-tools.esm.js.map +0 -1
- package/request.ts +0 -49
- package/rollup.config.js +0 -73
- package/tsconfig.json +0 -10
- package/tsconfig.type.json +0 -8
- package/userInputToJson.ts +0 -18
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)=> {
|
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
|
package/rollup.config.js
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
import nodeResolver from '@rollup/plugin-node-resolve';
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
3
|
-
import replace from '@rollup/plugin-replace';
|
4
|
-
import json from '@rollup/plugin-json';
|
5
|
-
import nodePolyfills from 'rollup-plugin-node-polyfills';
|
6
|
-
import clear from 'rollup-plugin-clear';
|
7
|
-
import progress from 'rollup-plugin-progress';
|
8
|
-
import typescript from '@rollup/plugin-typescript';
|
9
|
-
import { terser } from 'rollup-plugin-terser';
|
10
|
-
// import pkg from './package.json';
|
11
|
-
|
12
|
-
const isProd = process.env.NODE_ENV === 'production';
|
13
|
-
|
14
|
-
const formats = {
|
15
|
-
commonjs: {
|
16
|
-
format: 'cjs',
|
17
|
-
file: 'lib/ywfe-tools.cjs.js',
|
18
|
-
sourcemap: true,
|
19
|
-
exports: 'named',
|
20
|
-
},
|
21
|
-
esm: {
|
22
|
-
format: 'esm',
|
23
|
-
file: 'lib/ywfe-tools.esm.js',
|
24
|
-
sourcemap: true,
|
25
|
-
exports: 'named',
|
26
|
-
},
|
27
|
-
umd: {
|
28
|
-
format: 'umd',
|
29
|
-
file: 'lib/ywfe-tools.umd.js',
|
30
|
-
name: 'YWTOOLS',
|
31
|
-
sourcemap: true,
|
32
|
-
exports: 'named',
|
33
|
-
globals: {
|
34
|
-
'react': 'React',
|
35
|
-
'react-dom': 'ReactDOM',
|
36
|
-
},
|
37
|
-
},
|
38
|
-
};
|
39
|
-
|
40
|
-
const config = {
|
41
|
-
input: './index.ts',
|
42
|
-
inlineDynamicImports: true,
|
43
|
-
output: [formats.esm, formats.commonjs],
|
44
|
-
external: ['react', 'react-dom'],
|
45
|
-
plugins: [
|
46
|
-
clear({
|
47
|
-
targets: ['lib'],
|
48
|
-
}),
|
49
|
-
progress({
|
50
|
-
clearLine: false,
|
51
|
-
}),
|
52
|
-
replace({
|
53
|
-
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
|
54
|
-
}),
|
55
|
-
nodeResolver(),
|
56
|
-
commonjs(),
|
57
|
-
typescript(),
|
58
|
-
json(),
|
59
|
-
nodePolyfills(),
|
60
|
-
],
|
61
|
-
};
|
62
|
-
|
63
|
-
if (isProd) {
|
64
|
-
const file = formats.umd.file;
|
65
|
-
|
66
|
-
config.output.push({
|
67
|
-
...formats.umd,
|
68
|
-
file,
|
69
|
-
plugins: [terser()],
|
70
|
-
});
|
71
|
-
}
|
72
|
-
|
73
|
-
export default config;
|
package/tsconfig.json
DELETED
package/tsconfig.type.json
DELETED
package/userInputToJson.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
// Ctrl-S保存代码
|
2
|
-
interface userInput {
|
3
|
-
userInput?:string,
|
4
|
-
rules?:string,
|
5
|
-
}
|
6
|
-
async function userInputToJson({input}:{input:userInput}){
|
7
|
-
console.log(input)
|
8
|
-
//const {userInput, rules} = input
|
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
|