@ywfe/fe-tools 1.2.1-beta.13 → 1.2.1-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/JSON2String.ts +13 -0
- package/index.ts +1 -2
- package/lib/JSON2String.d.ts +4 -0
- package/lib/index.d.ts +1 -2
- package/lib/ywfe-tools.cjs +10 -8784
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +10 -8783
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +2 -0
- package/lib/ywfe-tools.umd.js.map +1 -0
- package/package.json +5 -4
- package/lib/request.d.ts +0 -9
- package/lib/userInputToJson.d.ts +0 -8
- package/request.ts +0 -49
- package/userInputToJson.ts +0 -24
@@ -0,0 +1,2 @@
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).YWTOOLS={})}(this,(function(n){"use strict";n.JSON2String=function(n){var t=n.input.data,e=void 0===t?{}:t;try{return"```json"+JSON.stringify(e)+"json```"}catch(n){return"```json"+JSON.stringify({})+"json```"}}}));
|
2
|
+
//# sourceMappingURL=ywfe-tools.umd.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ywfe-tools.umd.js","sources":["../JSON2String.ts"],"sourcesContent":["interface userInput {\n data?: object;\n}\nfunction JSON2String({ input }) {\n const { data = {} } = input;\n try {\n return \"```json\" + JSON.stringify(data) + \"json```\";\n } catch (error) {\n return \"```json\" + JSON.stringify({}) + \"json```\";\n }\n}\n\nexport default JSON2String"],"names":["_a","_b","input","data","JSON","stringify","error"],"mappings":"6PAGA,SAAqBA,GAAE,IACbC,EADkBD,EAAAE,MACTC,KAATA,OAAO,IAAAF,EAAA,CAAE,IACjB,IACE,MAAO,UAAYG,KAAKC,UAAUF,GAAQ,SAC3C,CAAC,MAAOG,GACP,MAAO,UAAYF,KAAKC,UAAU,CAAE,GAAI,SACzC,CACH"}
|
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.
|
4
|
+
"version": "1.2.1-beta.14",
|
5
5
|
"description": "工具函数库",
|
6
6
|
"main": "./lib/ywfe-tools.cjs",
|
7
7
|
"module": "./lib/ywfe-tools.esm.js",
|
@@ -24,16 +24,17 @@
|
|
24
24
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
25
25
|
"@rollup/plugin-replace": "^5.0.7",
|
26
26
|
"@rollup/plugin-typescript": "^11.1.6",
|
27
|
+
"@ywfe/utils": "^0.10.74",
|
27
28
|
"crypto-js": "^4.0.0",
|
28
29
|
"ramda": "^0.27.1",
|
30
|
+
"rollup": "^4.18.0",
|
29
31
|
"rollup-plugin-clear": "^2.0.7",
|
30
32
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
31
33
|
"rollup-plugin-progress": "^1.1.2",
|
32
34
|
"rollup-plugin-terser": "^7.0.2",
|
33
35
|
"strtok3": "^6.3.0",
|
34
36
|
"token-types": "^4.2.0",
|
35
|
-
"uuid": "^8.3.2"
|
36
|
-
"rollup": "^4.18.0"
|
37
|
+
"uuid": "^8.3.2"
|
37
38
|
},
|
38
39
|
"gitHead": "795058c747c80a3a69f6904dccffb53c42acfcc7"
|
39
|
-
}
|
40
|
+
}
|
package/lib/request.d.ts
DELETED
package/lib/userInputToJson.d.ts
DELETED
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:string)=> {
|
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/userInputToJson.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import {request} from './index'
|
2
|
-
// Ctrl-S保存代码
|
3
|
-
interface userInput {
|
4
|
-
userInput?: string;
|
5
|
-
rules?: string;
|
6
|
-
}
|
7
|
-
async function userInputToJson({ input }: { input: userInput }) {
|
8
|
-
console.log("input", input);
|
9
|
-
const res: { message: string; success: boolean; data: any } =
|
10
|
-
await request({
|
11
|
-
input: {
|
12
|
-
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
13
|
-
method: "GET",
|
14
|
-
params: input,
|
15
|
-
},
|
16
|
-
});
|
17
|
-
if (res.success) {
|
18
|
-
const result = res.data;
|
19
|
-
return result.success ? result.data : result;
|
20
|
-
} else {
|
21
|
-
return res.success ? res.data : res;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
export default userInputToJson
|