@bettergi/utils 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -1,11 +1,19 @@
1
- 本项目是一个为[Better Genshin Impact](https://github.com/babalae/better-genshin-impact) 设计的 JavaScript 开发工具函数,旨在帮助开发者简化代码。
1
+ 本项目是一个为[Better Genshin Impact](https://github.com/babalae/better-genshin-impact) 设计的 JavaScript 开发工具集,旨在帮助开发者简化代码、不用重复造轮子。工具函数支持按需引入,轻量依赖。
2
2
 
3
3
  ## 安装
4
4
 
5
+ ### 使用 npm
6
+
5
7
  ```shell
6
8
  npm install @bettergi/utils
7
9
  ```
8
10
 
11
+ ### 使用 pnpm
12
+
13
+ ```shell
14
+ pnpm install @bettergi/utils
15
+ ```
16
+
9
17
  ## 函数清单
10
18
 
11
19
  ### 游戏内操作
@@ -142,10 +150,12 @@ try {
142
150
  > 对网络请求的简易封装。
143
151
 
144
152
  ```ts
145
- import { getForBody } from "@bettergi/utils";
153
+ import { getForBody, postForBody } from "@bettergi/utils";
146
154
 
147
155
  // 发送 GET 请求获取响应体内容
148
156
  // 提示:需要在 `manifest.json` 文件中配置 `http_allowed_urls`,并在 调度器 -> 修改通用配置 中启用
149
- const body = await getForBody("https://example.com/", undefined, { "User-Agent": "BetterGI" });
150
- log.info(`响应体内容${body}`);
157
+ const body1 = await getForBody("https://example.com/", null, { "User-Agent": "BetterGI" });
158
+ const body2 = await postForBody("https://example.com/", null, { "User-Agent": "BetterGI" });
159
+ log.info(`GET 请求响应体内容${body1}`);
160
+ log.info(`POST 请求响应体内容${body2}`);
151
161
  ```
package/dist/http.d.ts CHANGED
@@ -22,8 +22,4 @@ export declare const getForBody: (url: string, body?: string, headers?: Record<s
22
22
  * @param headers 请求头
23
23
  * @returns 响应体内容
24
24
  */
25
- export declare const postForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<{
26
- status_code: number;
27
- headers: Record<string, string>;
28
- body: string;
29
- }>;
25
+ export declare const postForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
package/dist/http.js CHANGED
@@ -33,5 +33,5 @@ export const getForBody = async (url, body, headers) => {
33
33
  * @returns 响应体内容
34
34
  */
35
35
  export const postForBody = (url, body, headers) => {
36
- return http.request("POST", url, body, headers ? JSON.stringify(headers) : undefined);
36
+ return requestForBody("POST", url, body, headers);
37
37
  };
package/dist/ocr.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { type Region } from "@bettergi/types/csharp/BetterGenshinImpact/GameTask/Model/Area/Region";
2
1
  type Direction = "north" | "north-east" | "east" | "south-east" | "south" | "south-west" | "west" | "north-west";
3
2
  /**
4
3
  * 在整个画面内搜索图片
5
4
  * @param path 图片路径
6
5
  * @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
7
6
  */
8
- export declare const findImage: (path: string) => Region | undefined;
7
+ export declare const findImage: (path: string) => globalThis.Region | undefined;
9
8
  /**
10
9
  * 在指定区域内搜索图片
11
10
  * @param path 图片路径
@@ -15,14 +14,14 @@ export declare const findImage: (path: string) => Region | undefined;
15
14
  * @param h 高度
16
15
  * @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
17
16
  */
18
- export declare const findImageWithinBounds: (path: string, x: number, y: number, w: number, h: number) => Region | undefined;
17
+ export declare const findImageWithinBounds: (path: string, x: number, y: number, w: number, h: number) => globalThis.Region | undefined;
19
18
  /**
20
19
  * 在指定方向上搜索图片
21
20
  * @param path 图片路径
22
21
  * @param direction 搜索方向
23
22
  * @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
24
23
  */
25
- export declare const findImageInDirection: (path: string, direction: Direction) => Region | undefined;
24
+ export declare const findImageInDirection: (path: string, direction: Direction) => globalThis.Region | undefined;
26
25
  /**
27
26
  * 在整个画面内搜索文本
28
27
  * @param text 待搜索文本
@@ -30,7 +29,7 @@ export declare const findImageInDirection: (path: string, direction: Direction)
30
29
  * @param ignoreCase 是否忽略大小写
31
30
  * @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
32
31
  */
33
- export declare const findText: (text: string, contains: boolean, ignoreCase: boolean) => Region | undefined;
32
+ export declare const findText: (text: string, contains: boolean, ignoreCase: boolean) => globalThis.Region | undefined;
34
33
  /**
35
34
  * 在指定区域内搜索文本
36
35
  * @param text 待搜索文本
@@ -43,7 +42,7 @@ export declare const findText: (text: string, contains: boolean, ignoreCase: boo
43
42
  * @param h 高度
44
43
  * @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
45
44
  */
46
- export declare const findTextWithinBounds: (text: string, contains: boolean, ignoreCase: boolean, x: number, y: number, w: number, h: number) => Region | undefined;
45
+ export declare const findTextWithinBounds: (text: string, contains: boolean, ignoreCase: boolean, x: number, y: number, w: number, h: number) => globalThis.Region | undefined;
47
46
  /**
48
47
  * 在指定方向上搜索文本
49
48
  * @param text 待搜索文本
@@ -52,7 +51,7 @@ export declare const findTextWithinBounds: (text: string, contains: boolean, ign
52
51
  * @param direction 搜索方向
53
52
  * @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
54
53
  */
55
- export declare const findTextInDirection: (text: string, contains: boolean, ignoreCase: boolean, direction: Direction) => Region | undefined;
54
+ export declare const findTextInDirection: (text: string, contains: boolean, ignoreCase: boolean, direction: Direction) => globalThis.Region | undefined;
56
55
  /**
57
56
  * 在列表视图中滚动搜索文本
58
57
  * @param text 待搜索文本
@@ -70,5 +69,5 @@ export declare const findTextWithinListView: (text: string, contains: boolean, i
70
69
  maxListItems: number;
71
70
  lineHeight: number;
72
71
  padding?: number;
73
- }, timeout?: number) => Promise<Region | undefined>;
72
+ }, timeout?: number) => Promise<globalThis.Region | undefined>;
74
73
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.0.7",
4
- "description": "Utils for BetterGI JavaScript Development",
3
+ "version": "0.0.9",
4
+ "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "build": "tsc"
34
34
  },
35
35
  "devDependencies": {
36
- "@bettergi/types": "^0.0.11",
36
+ "@bettergi/types": "^0.0.13",
37
37
  "typescript": "5.6.3"
38
38
  }
39
39
  }