@ywfe/fe-tools 1.2.1 → 2.0.0

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 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
@@ -1 +1,4 @@
1
+ export { default as request } from './request'
1
2
  export { default as userInputToJson } from './userInputToJson'
3
+ export { default as JSON2String } from './JSON2String'
4
+ export { default as gitlabGet } from './gitlabGet'
@@ -0,0 +1,7 @@
1
+ interface Input {
2
+ data: object;
3
+ }
4
+ declare function JSON2String({ input }: {
5
+ input: Input;
6
+ }): string;
7
+ export default JSON2String;
@@ -0,0 +1,9 @@
1
+ interface RequestOptions {
2
+ url: string;
3
+ method?: string;
4
+ params?: any;
5
+ }
6
+ declare function gitlabGet({ input }: {
7
+ input: RequestOptions;
8
+ }): Promise<any>;
9
+ export default gitlabGet;
package/lib/index.d.ts CHANGED
@@ -1 +1,4 @@
1
+ export { default as request } from './request';
1
2
  export { default as userInputToJson } from './userInputToJson';
3
+ export { default as JSON2String } from './JSON2String';
4
+ export { default as gitlabGet } from './gitlabGet';
@@ -0,0 +1,9 @@
1
+ interface RequestOptions {
2
+ url: string;
3
+ method?: string;
4
+ params?: any;
5
+ }
6
+ declare function request({ input }: {
7
+ input: RequestOptions;
8
+ }): Promise<any>;
9
+ export default request;
@@ -4,5 +4,9 @@ interface userInput {
4
4
  }
5
5
  declare function userInputToJson({ input }: {
6
6
  input: userInput;
7
- }): Promise<string>;
7
+ }): Promise<{
8
+ message: string;
9
+ success: boolean;
10
+ data: any;
11
+ }>;
8
12
  export default userInputToJson;