@ywfe/fe-tools 1.0.2-beta.4 → 1.0.2-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/JSON2String.ts +13 -0
- package/index.ts +3 -0
- package/jest.config.js +12 -0
- package/package.json +23 -18
- package/request.ts +49 -0
- package/rollup.config.js +77 -0
- package/tsconfig.json +52 -0
- package/tsconfig.type.json +8 -0
- package/userInputToJson.ts +18 -0
- package/dist/bundle.js +0 -8835
- package/dist/bundle.js.map +0 -1
package/JSON2String.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
interface userInput {
|
2
|
+
data?: object;
|
3
|
+
}
|
4
|
+
function JSON2String({ input }) {
|
5
|
+
const { data = {} } = input;
|
6
|
+
try {
|
7
|
+
return "```json" + JSON.stringify(data) + "json```";
|
8
|
+
} catch (error) {
|
9
|
+
return "```json" + JSON.stringify({}) + "json```";
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
export default JSON2String
|
package/index.ts
ADDED
package/jest.config.js
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module.exports = {
|
2
|
+
preset: 'ts-jest',
|
3
|
+
testEnvironment: 'jsdom',
|
4
|
+
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
|
5
|
+
rootDir: '.',
|
6
|
+
roots: ['<rootDir>/src/'],
|
7
|
+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?|ts?)$',
|
8
|
+
transform: {
|
9
|
+
'^.+\\.(t|j)s$': 'ts-jest',
|
10
|
+
'^.+\\.(t|j)sx$': 'ts-jest',
|
11
|
+
},
|
12
|
+
};
|
package/package.json
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
{
|
2
|
+
"private": false,
|
2
3
|
"name": "@ywfe/fe-tools",
|
3
|
-
"version": "1.0.2-beta.
|
4
|
+
"version": "1.0.2-beta.6",
|
4
5
|
"description": "工具函数库",
|
5
|
-
"main": "
|
6
|
-
"module": "
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"dist"
|
10
|
-
],
|
6
|
+
"main": "lib/ywfe-tools.esm.js",
|
7
|
+
"module": "lib/ywfe-tools.esm.js",
|
8
|
+
"browser": "lib/ywfe-tools.umd.js",
|
9
|
+
"types": "lib/index.d.ts",
|
11
10
|
"scripts": {
|
12
|
-
"build": "rollup -c",
|
13
|
-
"
|
11
|
+
"build": "NODE_ENV=production rollup -c",
|
12
|
+
"build:type": "tsc -p ./tsconfig.type.json",
|
13
|
+
"publish:npm": "npm publish --access public",
|
14
|
+
"test": "jest --coverage"
|
14
15
|
},
|
15
|
-
"
|
16
|
-
|
17
|
-
"
|
16
|
+
"repository": "ywfe",
|
17
|
+
"author": {
|
18
|
+
"name": "YWFE",
|
19
|
+
"email": "ywfe@ywwl.com",
|
20
|
+
"url": "http://ywfe.com"
|
18
21
|
},
|
22
|
+
"license": "MIT",
|
19
23
|
"dependencies": {
|
20
|
-
"@ywfe/utils": "^0.10.74"
|
24
|
+
"@ywfe/utils": "^0.10.74",
|
25
|
+
"crypto-js": "^4.0.0",
|
26
|
+
"ramda": "^0.27.1",
|
27
|
+
"strtok3": "^6.3.0",
|
28
|
+
"token-types": "^4.2.0",
|
29
|
+
"uuid": "^8.3.2"
|
21
30
|
},
|
22
|
-
"
|
23
|
-
"typescript": "^5.4.5"
|
24
|
-
},
|
25
|
-
"author": "",
|
26
|
-
"license": "ISC"
|
31
|
+
"gitHead": "795058c747c80a3a69f6904dccffb53c42acfcc7"
|
27
32
|
}
|
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
|
package/rollup.config.js
ADDED
@@ -0,0 +1,77 @@
|
|
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.esm.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
|
+
watch: {
|
62
|
+
include: 'src/**',
|
63
|
+
exclude: 'node_modules/**',
|
64
|
+
},
|
65
|
+
};
|
66
|
+
|
67
|
+
if (isProd) {
|
68
|
+
const file = formats.umd.file;
|
69
|
+
|
70
|
+
config.output.push({
|
71
|
+
...formats.umd,
|
72
|
+
file,
|
73
|
+
plugins: [terser()],
|
74
|
+
});
|
75
|
+
}
|
76
|
+
|
77
|
+
export default config;
|
package/tsconfig.json
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"rootDir": "./src",
|
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
|
+
"paths": {
|
38
|
+
"@/*": [
|
39
|
+
"src/*"
|
40
|
+
]
|
41
|
+
}
|
42
|
+
},
|
43
|
+
"include": [
|
44
|
+
"src/**/*.ts",
|
45
|
+
"**/*.spec.ts",
|
46
|
+
"src/_internal/jsMD5.js"
|
47
|
+
],
|
48
|
+
"exclude": [
|
49
|
+
"node_modules",
|
50
|
+
"src/**/*.js",
|
51
|
+
]
|
52
|
+
}
|
@@ -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',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
|