@ywfe/fe-tools 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/JSON2String.ts +14 -0
- package/gitlabGet.ts +39 -0
- package/index.ts +3 -0
- package/lib/JSON2String.d.ts +7 -0
- package/lib/gitlabGet.d.ts +9 -0
- package/lib/index.d.ts +3 -0
- package/lib/request.d.ts +9 -0
- package/lib/userInputToJson.d.ts +5 -1
- package/lib/ywfe-tools.cjs +8775 -8
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +8773 -9
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +4 -0
- package/lib/ywfe-tools.umd.js.map +1 -0
- package/package.json +1 -2
- package/request.ts +49 -0
- package/rollup.config.js +1 -4
- package/tsconfig.json +4 -2
- package/userInputToJson.ts +15 -11
package/JSON2String.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
interface Input {
|
2
|
+
data: object;
|
3
|
+
}
|
4
|
+
// Ctrl-S保存代码
|
5
|
+
function JSON2String({input}: { input: Input }){
|
6
|
+
const { data } = input;
|
7
|
+
try {
|
8
|
+
const str = JSON.stringify(data);
|
9
|
+
return '```json' + str + 'json```'
|
10
|
+
} catch (error) {
|
11
|
+
return '```json' + '{}' + 'json```'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
export default JSON2String
|
package/gitlabGet.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
// Ctrl-S保存代码
|
2
|
+
interface RequestOptions {
|
3
|
+
url: string;
|
4
|
+
method?: string;
|
5
|
+
params?: any;
|
6
|
+
}
|
7
|
+
async function gitlabGet({ input }: { input: RequestOptions }) {
|
8
|
+
const method = input.method || "GET";
|
9
|
+
const isValidURL = (url: string) => {
|
10
|
+
const regex = /^https?:\/\//;
|
11
|
+
return regex.test(url);
|
12
|
+
};
|
13
|
+
const prefix = 'https://git.ywwl.com/api/v4';
|
14
|
+
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
15
|
+
const API_TOEKN = 'PER-aCLxmYE54ByvzHrY';
|
16
|
+
const fetchOption: { [key: string]: any } = {
|
17
|
+
method: method,
|
18
|
+
headers: {
|
19
|
+
"Content-type": "application/json",
|
20
|
+
'PRIVATE-TOKEN': API_TOEKN,
|
21
|
+
},
|
22
|
+
};
|
23
|
+
if (method.toUpperCase() === "POST") {
|
24
|
+
fetchOption.body = JSON.stringify(input.params);
|
25
|
+
} else if (method.toUpperCase() === "GET") {
|
26
|
+
requestUrl = requestUrl;
|
27
|
+
}
|
28
|
+
const response = await fetch(requestUrl, fetchOption);
|
29
|
+
if (!response.ok) {
|
30
|
+
const message = `An error has occured: ${response.status}`;
|
31
|
+
console.log('req result', message);
|
32
|
+
return { success: false, message };
|
33
|
+
}
|
34
|
+
const result = await response.json();
|
35
|
+
console.log('req result', result);
|
36
|
+
return result;
|
37
|
+
}
|
38
|
+
|
39
|
+
export default gitlabGet
|
package/index.ts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/request.d.ts
ADDED
package/lib/userInputToJson.d.ts
CHANGED