ms-types 0.0.10 → 0.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-types",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -9,11 +9,12 @@
9
9
  "files": [
10
10
  "types"
11
11
  ],
12
- "typesVersions": {
13
- "*": {
14
- "*": [
15
- "types/*"
16
- ]
17
- }
12
+ "scripts": {
13
+ "docs:dev": "vitepress dev docs",
14
+ "docs:build": "vitepress build docs",
15
+ "docs:preview": "vitepress preview docs"
16
+ },
17
+ "devDependencies": {
18
+ "vitepress": "^1.0.0"
18
19
  }
19
20
  }
package/types/action.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 操作相关函数
2
+ * 动作模块 包含点击、滑动、长按滑动、返回首页等动作
3
3
  */
4
4
  declare namespace action {
5
5
  /**
@@ -7,8 +7,9 @@ declare namespace action {
7
7
  * @param x 坐标x
8
8
  * @param y 坐标y
9
9
  * @param duration 持续时间
10
- * @param jitter 抖动
10
+ * @param jitter 抖动 开启抖动,会在像素范围随机偏移 点击
11
11
  * @returns 点击是否成功
12
+ * @example action.click(100, 100, 20, true)
12
13
  */
13
14
  function click(
14
15
  x: number,
@@ -23,9 +24,10 @@ declare namespace action {
23
24
  * @param endX 结束坐标x
24
25
  * @param endY 结束坐标y
25
26
  * @param duration 持续时间
26
- * @param jitter 抖动
27
- * @param steps 步数
27
+ * @param jitter 抖动 开启抖动,会在像素范围随机偏移 滑动
28
+ * @param steps 步数 生成抖动点数量
28
29
  * @returns 滑动是否成功
30
+ * @example action.swipe(100, 100, 200, 200, 500, true, 10)
29
31
  */
30
32
  function swipe(
31
33
  startX: number,
@@ -45,9 +47,10 @@ declare namespace action {
45
47
  * @param touch_down_duration 按下持续时间
46
48
  * @param touch_move_duration 移动持续时间
47
49
  * @param touch_up_duration 松开持续时间
48
- * @param jitter 抖动
49
- * @param steps 步数
50
+ * @param jitter 抖动 开启抖动,会在像素范围随机偏移 长按滑动
51
+ * @param steps 步数 生成抖动点数量
50
52
  * @returns 长按滑动是否成功
53
+ * @example action.pressAndSwipe(100, 100, 200, 200, 500, 500, 500, true, 10)
51
54
  */
52
55
  function pressAndSwipe(
53
56
  startX: number,
@@ -63,19 +66,22 @@ declare namespace action {
63
66
  /**
64
67
  * 返回首页
65
68
  * @returns 返回首页是否成功
69
+ * @example action.homeScreen()
66
70
  */
67
71
  function homeScreen(): boolean;
68
72
  /**
69
73
  * 按下按钮
70
- * @param button 按钮
74
+ * @param button 按钮 home 按下home键 volumeup 按下音量上键 volumedown 按下音量下键
71
75
  * @returns 按下按钮是否成功
76
+ * @example action.pressButton("home")
72
77
  */
73
78
  function pressButton(button: "home" | "volumeup" | "volumedown"): boolean;
74
79
  /**
75
- * 按下HID按钮
76
- * @param button HID按钮
77
- * @param duration 持续时间
80
+ * 模拟按下HID按钮
81
+ * @param button HID按钮 home 按下home键 volumeup 按下音量上键 volumedown 按下音量下键 power 按下电源键 snapshot 按下截图键
82
+ * @param duration 持续时间 单位毫秒
78
83
  * @returns 按下HID按钮是否成功
84
+ * @example action.pressHidButton("home", 200)
79
85
  */
80
86
  function pressHidButton(
81
87
  button: "home" | "volumeup" | "volumedown" | "power" | "snapshot",
package/types/config.d.ts CHANGED
@@ -1,34 +1,39 @@
1
1
  /**
2
- * 配置相关函数
2
+ * 配置模块 包含读取配置、更新配置、删除配置等功能
3
3
  */
4
4
  declare namespace config {
5
5
  /**
6
6
  * 读取配置Int
7
7
  * @param key 配置key
8
8
  * @returns 配置值
9
+ * @example config.readConfigInt("key")
9
10
  */
10
11
  function readConfigInt(key: string): number;
11
12
  /**
12
13
  * 读取配置Double
13
14
  * @param key 配置key
14
15
  * @returns 配置值
16
+ * @example config.readConfigDouble("key")
15
17
  */
16
18
  function readConfigDouble(key: string): number;
17
19
  /**
18
20
  * 读取配置String
19
21
  * @param key 配置key
20
22
  * @returns 配置值
23
+ * @example config.readConfigString("key")
21
24
  */
22
25
  function readConfigString(key: string): string;
23
26
  /**
24
27
  * 读取配置Bool
25
28
  * @param key 配置key
26
29
  * @returns 配置值
30
+ * @example config.readConfigBool("key")
27
31
  */
28
32
  function readConfigBool(key: string): boolean;
29
33
  /**
30
34
  * 获取所有配置JSON
31
35
  * @returns 所有配置JSON
36
+ * @example config.getConfigJSON()
32
37
  */
33
38
  function getConfigJSON(): Record<string, any>;
34
39
  /**
@@ -36,12 +41,14 @@ declare namespace config {
36
41
  * @param key 配置key
37
42
  * @param value 配置值
38
43
  * @returns 更新是否成功
44
+ * @example config.updateConfig("key", 100)
39
45
  */
40
46
  function updateConfig(key: string, value: any): boolean;
41
47
  /**
42
48
  * 删除配置
43
49
  * @param key 配置key
44
50
  * @returns 删除是否成功
51
+ * @example config.deleteConfig("key")
45
52
  */
46
53
  function deleteConfig(key: string): boolean;
47
54
  }
package/types/device.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
- * 设备相关函数
2
+ * 设备模块 包含获取设备信息、设备操作等功能
3
3
  */
4
4
  declare namespace device {
5
5
  /**
6
6
  * 获取电池信息
7
7
  * @returns 电池信息
8
+ * @example device.getBatteryInfo()
8
9
  */
9
10
  function getBatteryInfo(): {
10
11
  /**
@@ -17,52 +18,67 @@ declare namespace device {
17
18
  isCharging: boolean;
18
19
  };
19
20
  /**
20
- * 获取设备UDID
21
- * @returns 设备UDID
21
+ * 获取设备ID
22
+ * @returns 设备ID
23
+ * @example device.getDeviceID()
22
24
  */
23
- function getDeviceUDID(): string;
25
+ function getDeviceID(): string;
24
26
  /**
25
27
  * 获取设备名称
26
28
  * @returns 设备名称
29
+ * @example device.getDeviceName()
27
30
  */
28
31
  function getDeviceName(): string;
29
32
  /**
30
33
  * 获取设备型号
31
34
  * @returns 设备型号
35
+ * @example device.getDeviceModel()
32
36
  */
33
37
  function getDeviceModel(): string;
34
38
  /**
35
39
  * 获取屏幕大小
36
40
  * @returns 屏幕大小
41
+ * @example device.getScreenSize()
37
42
  */
38
43
  function getScreenSize(): {
44
+ /**
45
+ * 屏幕宽度
46
+ */
39
47
  width: number;
48
+ /**
49
+ * 屏幕高度
50
+ */
40
51
  height: number;
41
52
  };
42
53
  /**
43
54
  * 获取屏幕缩放比例
44
55
  * @returns 屏幕缩放比例
56
+ * @example device.getScreenScale()
45
57
  */
46
58
  function getScreenScale(): number;
47
59
  /**
48
- * 获取设备方向
60
+ * 获取设备方向 PORTRAIT 竖屏 LANDSCAPE 横屏
49
61
  * @returns 设备方向
62
+ * @example device.getOrientation()
50
63
  */
51
64
  function getOrientation(): "PORTRAIT" | "LANDSCAPE";
52
65
  /**
53
- * 获取系统版本
66
+ * 获取系统版本 例如 16.7.11
54
67
  * @returns 系统版本
68
+ * @example device.getOSVersion()
55
69
  */
56
70
  function getOSVersion(): string;
57
71
  /**
58
- * 获取局域网IP
72
+ * 获取局域网IP 例如 192.168.1.100
59
73
  * @returns 局域网IP
74
+ * @example device.getLanIp()
60
75
  */
61
76
  function getLanIp(): string;
62
77
  /**
63
78
  * 振动
64
- * @param duration 持续时间
79
+ * @param duration 持续时间 单位毫秒
65
80
  * @param intensity 强度 0.0-1.0
81
+ * @example device.vibrate(1000, 0.5)
66
82
  */
67
83
  function vibrate(duration: number, intensity: number): void;
68
84
  }
package/types/file.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * 文件相关函数
2
+ * 文件模块 包含文件操作、文件内容读写等功能
3
3
  */
4
4
  declare namespace file {
5
5
  /**
6
6
  * 获取应用内部目录
7
7
  * @param type 目录类型
8
8
  * @returns 目录路径
9
+ * @example file.getInternalDir("documents")
9
10
  */
10
11
  function getInternalDir(
11
12
  type: "documents" | "library" | "temp" | "libraryCaches"
@@ -13,36 +14,42 @@ declare namespace file {
13
14
  /**
14
15
  * 获取应用数据目录
15
16
  * @returns 目录路径
17
+ * @example file.getDataDir()
16
18
  */
17
19
  function getDataDir(): string;
18
20
  /**
19
21
  * 获取应用数据文件路径
20
22
  * @param file 文件名
21
23
  * @returns 文件路径
24
+ * @example file.getDataFile("config.json")
22
25
  */
23
26
  function getDataFile(file: string): string;
24
27
  /**
25
28
  * 创建文件
26
29
  * @param path 文件路径
27
30
  * @returns 是否创建成功
31
+ * @example file.create("config.json")
28
32
  */
29
33
  function create(path: string): boolean;
30
34
  /**
31
35
  * 创建目录
32
36
  * @param path 目录路径
33
37
  * @returns 是否创建成功
38
+ * @example file.mkdirs("config")
34
39
  */
35
40
  function mkdirs(path: string): boolean;
36
41
  /**
37
42
  * 删除文件或目录
38
43
  * @param path 文件或目录路径
39
44
  * @returns 是否删除成功
45
+ * @example file.deleteAllFile("config")
40
46
  */
41
47
  function deleteAllFile(path: string): boolean;
42
48
  /**
43
49
  * 读取文件内容
44
50
  * @param path 文件路径
45
51
  * @returns 文件内容
52
+ * @example file.readFile("config.json")
46
53
  */
47
54
  function readFile(path: string): string;
48
55
  /**
@@ -51,13 +58,19 @@ declare namespace file {
51
58
  * @param line 行号 如果是-1 代表这个条件不生效
52
59
  * @param contains 包含内容 如果是null 代表这个条件不生效
53
60
  * @returns 是否删除成功
61
+ * @example file.deleteLine("config.json", 1, null)
54
62
  */
55
- function deleteLine(path: string, line: number, contains?: string): boolean;
63
+ function deleteLine(
64
+ path: string,
65
+ line: number,
66
+ contains: string | null
67
+ ): boolean;
56
68
  /**
57
69
  * 列出目录下所有文件
58
70
  * @param path 目录路径
59
71
  * @param recursion 是否递归
60
72
  * @returns 文件路径数组
73
+ * @example file.listDir("config", true)
61
74
  */
62
75
  function listDir(path: string, recursion: boolean): string[];
63
76
  /**
@@ -65,6 +78,7 @@ declare namespace file {
65
78
  * @param path 文件路径
66
79
  * @param content 文件内容
67
80
  * @returns 是否写入成功
81
+ * @example file.writeFile("config.json", "name=wda")
68
82
  */
69
83
  function writeFile(path: string, content: string): boolean;
70
84
  /**
@@ -72,6 +86,7 @@ declare namespace file {
72
86
  * @param path 文件路径
73
87
  * @param content 文件内容
74
88
  * @returns 是否追加成功
89
+ * @example file.appendLine("config.json", "name=wda")
75
90
  */
76
91
  function appendLine(path: string, content: string): boolean;
77
92
  /**
@@ -79,18 +94,21 @@ declare namespace file {
79
94
  * @param path 文件路径
80
95
  * @param lineNo 行号
81
96
  * @returns 行内容
97
+ * @example file.readLine("config.json", 1)
82
98
  */
83
99
  function readLine(path: string, lineNo: number): string;
84
100
  /**
85
101
  * 读取文件所有行内容
86
102
  * @param path 文件路径
87
103
  * @returns 行内容数组
104
+ * @example file.readAllLines("config.json")
88
105
  */
89
106
  function readAllLines(path: string): string[];
90
107
  /**
91
108
  * 文件或者文件夹是否存在
92
109
  * @param path 文件路径
93
110
  * @returns 是否存在
111
+ * @example file.exists("config.json")
94
112
  */
95
113
  function exists(path: string): boolean;
96
114
  /**
@@ -98,12 +116,14 @@ declare namespace file {
98
116
  * @param src 源文件路径
99
117
  * @param dest 目标文件路径
100
118
  * @returns 是否复制成功
119
+ * @example file.copy("config.json", "config2.json")
101
120
  */
102
121
  function copy(src: string, dest: string): boolean;
103
122
  /**
104
123
  * 获取文件MD5值
105
124
  * @param path 文件路径
106
125
  * @returns 文件MD5值
126
+ * @example file.fileMD5("config.json")
107
127
  */
108
128
  function fileMD5(path: string): string | null;
109
129
  }
package/types/global.d.ts CHANGED
@@ -22,6 +22,14 @@ declare const __appName__: string;
22
22
  * 应用 bundleId
23
23
  */
24
24
  declare const __bundleId__: string;
25
+ /**
26
+ * 当前线程名称
27
+ */
28
+ declare const __threadName__: string;
29
+ /**
30
+ * 当前进程名称
31
+ */
32
+ declare const __workerName__: string;
25
33
  /**
26
34
  * 应用包信息
27
35
  */
package/types/http.d.ts CHANGED
@@ -1,8 +1,16 @@
1
+ /**
2
+ * HTTP模块 包含发送HTTP请求、下载文件等功能、websocket等功能
3
+ */
1
4
  declare namespace http {
2
5
  /**
3
6
  * 通用发送HTTP请求
4
7
  * @param params 请求参数
5
8
  * @returns 请求结果
9
+ * @example
10
+ * http.request({
11
+ * url: "https://www.baidu.com",
12
+ * method: "GET",
13
+ * })
6
14
  */
7
15
  function request(params: {
8
16
  /**
@@ -116,6 +124,8 @@ declare namespace http {
116
124
  * @param timeout 超时时间
117
125
  * @param headers 请求头
118
126
  * @returns 下载是否成功
127
+ * @example
128
+ * http.downloadFile("https://www.baidu.com", "baidu.html")
119
129
  */
120
130
  function downloadFile(
121
131
  url: string,
@@ -131,6 +141,8 @@ declare namespace http {
131
141
  * @param timeout 超时时间
132
142
  * @param headers 请求头
133
143
  * @returns 请求结果
144
+ * @example
145
+ * http.httpGet("https://www.baidu.com")
134
146
  */
135
147
  function httpGet(
136
148
  url: string,
@@ -147,6 +159,8 @@ declare namespace http {
147
159
  * @param timeout 超时时间
148
160
  * @param headers 请求头
149
161
  * @returns 请求结果
162
+ * @example
163
+ * http.httpPost("https://www.baidu.com")
150
164
  */
151
165
  function httpPost(
152
166
  url: string,
@@ -163,6 +177,11 @@ declare namespace http {
163
177
  * @param timeout 超时时间
164
178
  * @param headers 请求头
165
179
  * @returns 请求结果
180
+ * @example
181
+ * http.postJSON("https://www.baidu.com", {
182
+ * "name": "MagicScript",
183
+ * "version": "1.0.0"
184
+ * })
166
185
  */
167
186
  function postJSON(
168
187
  url: string,
@@ -171,6 +190,9 @@ declare namespace http {
171
190
  headers?: Record<string, string>
172
191
  ): string;
173
192
 
193
+ /**
194
+ * WebSocket连接
195
+ */
174
196
  interface WebSocket {
175
197
  /**
176
198
  * 连接WebSocket服务器
@@ -262,6 +284,14 @@ declare namespace http {
262
284
  * @param url 连接地址
263
285
  * @param header 连接头
264
286
  * @returns WebSocket连接对象
287
+ * @example
288
+ * const ws = http.newWebsocket("ws://www.baidu.com")
289
+ * ws.connect()
290
+ * ws.onText((data) => {
291
+ * console.log(data)
292
+ * })
293
+ * ws.sendText("hello")
294
+ * ws.close()
265
295
  */
266
296
  function newWebsocket(
267
297
  url: string,