@ybgnb/utils 0.1.8 → 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +1 -1
  2. package/dist/core.cjs +504 -0
  3. package/dist/core.cjs.map +1 -0
  4. package/dist/core.d.cts +369 -0
  5. package/dist/core.d.ts +369 -2
  6. package/dist/core.js +433 -295
  7. package/dist/core.js.map +1 -1
  8. package/dist/dom.cjs +263 -0
  9. package/dist/dom.cjs.map +1 -0
  10. package/dist/dom.d.cts +105 -0
  11. package/dist/dom.d.ts +105 -2
  12. package/dist/dom.js +213 -122
  13. package/dist/dom.js.map +1 -1
  14. package/dist/node.cjs +410 -0
  15. package/dist/node.cjs.map +1 -0
  16. package/dist/node.d.cts +153 -0
  17. package/dist/node.d.ts +153 -2
  18. package/dist/node.js +348 -199
  19. package/dist/node.js.map +1 -1
  20. package/package.json +11 -11
  21. package/dist/core/error/common-error.d.ts +0 -8
  22. package/dist/core/index.d.ts +0 -17
  23. package/dist/core/result/biz-result.d.ts +0 -17
  24. package/dist/core/result/exec-biz.d.ts +0 -6
  25. package/dist/core/types/helpers.d.ts +0 -54
  26. package/dist/core/types/physical.d.ts +0 -16
  27. package/dist/core/utils/array.d.ts +0 -12
  28. package/dist/core/utils/error.d.ts +0 -22
  29. package/dist/core/utils/fetch.d.ts +0 -13
  30. package/dist/core/utils/function.d.ts +0 -28
  31. package/dist/core/utils/github.d.ts +0 -31
  32. package/dist/core/utils/number/format.d.ts +0 -19
  33. package/dist/core/utils/random.d.ts +0 -28
  34. package/dist/core/utils/serialize.d.ts +0 -23
  35. package/dist/core/utils/sleep.d.ts +0 -13
  36. package/dist/core/utils/time.d.ts +0 -19
  37. package/dist/core/utils/type.d.ts +0 -9
  38. package/dist/core/utils/url.d.ts +0 -36
  39. package/dist/core.umd.cjs +0 -2
  40. package/dist/core.umd.cjs.map +0 -1
  41. package/dist/dom/index.d.ts +0 -6
  42. package/dist/dom/utils/color.d.ts +0 -32
  43. package/dist/dom/utils/css.d.ts +0 -4
  44. package/dist/dom/utils/img.d.ts +0 -14
  45. package/dist/dom/utils/network.d.ts +0 -25
  46. package/dist/dom/utils/page.d.ts +0 -10
  47. package/dist/dom/utils/scroll.d.ts +0 -13
  48. package/dist/dom.umd.cjs +0 -2
  49. package/dist/dom.umd.cjs.map +0 -1
  50. package/dist/node/index.d.ts +0 -8
  51. package/dist/node/utils/env.d.ts +0 -6
  52. package/dist/node/utils/file/base.d.ts +0 -20
  53. package/dist/node/utils/file/delete.d.ts +0 -12
  54. package/dist/node/utils/file/download.d.ts +0 -4
  55. package/dist/node/utils/file/find.d.ts +0 -14
  56. package/dist/node/utils/file/json.d.ts +0 -20
  57. package/dist/node/utils/file/size.d.ts +0 -19
  58. package/dist/node/utils/win/cmd.d.ts +0 -21
  59. package/dist/node/utils/win/copy.d.ts +0 -4
  60. package/dist/node/utils/win/explorer.d.ts +0 -5
  61. package/dist/node/utils/win/regedit.d.ts +0 -17
  62. package/dist/node.umd.cjs +0 -2
  63. package/dist/node.umd.cjs.map +0 -1
package/dist/node.d.ts CHANGED
@@ -1,2 +1,153 @@
1
- export * from './node/index.js';
2
- export {};
1
+ /**
2
+ * 获取环境变量
3
+ */
4
+ declare function getEnv(): {
5
+ [p: string]: string;
6
+ };
7
+
8
+ /**
9
+ * 判断路径是否是文件
10
+ */
11
+ declare function isFile(filePath: string): Promise<boolean>;
12
+ /**
13
+ * 判断文件是否存在
14
+ */
15
+ declare function existsFile(file: string, mode?: number): Promise<boolean>;
16
+ /**
17
+ * 确保目录存在
18
+ */
19
+ declare function ensureDirSync(dirPath: string): Promise<void>;
20
+ /**
21
+ * 确保目录存在
22
+ */
23
+ declare function ensureDir(dirPath: string): Promise<void>;
24
+ /**
25
+ * 判断错误是否为文件不存在
26
+ */
27
+ declare function isFileNotFoundError(error: unknown): boolean;
28
+
29
+ /**
30
+ * 删除指定目录下的所有文件和子目录(保留指定目录)
31
+ * @param dir 目标目录路径
32
+ * @return 成功删除的文件或目录路径数组
33
+ */
34
+ declare function emptyDirectory(dir: string): Promise<string[]>;
35
+ /**
36
+ * 删除文件(不删除目录)
37
+ * @param paths 文件路径列表
38
+ * @returns 成功删除的文件路径数组
39
+ */
40
+ declare function deleteFiles(paths: string[]): Promise<string[]>;
41
+
42
+ /**
43
+ * 下载文件
44
+ */
45
+ declare function downloadFile(url: string, filePath: string): Promise<void>;
46
+
47
+ /**
48
+ * 查找目录下符合条件的文件路径(不遍历子目录)
49
+ * @param dir 目标目录路径
50
+ * @param prefix 文件名前缀(需全字匹配)
51
+ * @param suffix 文件名后缀(需全字匹配,如 ".txt")
52
+ * @return 符合条件的文件完整路径的数组
53
+ */
54
+ declare function findFilesByPrefixAndSuffix(dir: string, prefix?: string, suffix?: string): Promise<string[]>;
55
+ /**
56
+ * 查找文件(包含子目录)
57
+ * @param dir 目录
58
+ * @param target 查找目标名称或者过滤函数
59
+ */
60
+ declare function findFiles(dir: string, target: string | ((fileName: string, fullPath?: string) => boolean)): Promise<string[]>;
61
+
62
+ /**
63
+ * 读取 JSON 文件
64
+ */
65
+ declare function readJSONFile<T>(filePath: string): Promise<T>;
66
+ /**
67
+ * 将数据原子写入 JSON 文件(先写临时文件再替换)
68
+ */
69
+ declare function writeJSONFile<T>(file: string, data: T): Promise<void>;
70
+ /**
71
+ * 读取 JSON 文件,修改后写回(原子操作)
72
+ */
73
+ declare function updateJSON<T>(file: string, updater: (oldData: T) => T): Promise<T>;
74
+ /**
75
+ * 从文件读取 JSON,若文件不存在则调用 initData 初始化并写入
76
+ *
77
+ * @param file 文件绝对路径或相对路径
78
+ * @param initData 返回要写入的数据的异步函数
79
+ * @returns 解析后的数据
80
+ */
81
+ declare function readOrInitJSON<T>(file: string, initData: () => Promise<T>): Promise<T>;
82
+
83
+ /**
84
+ * 将 KB 文件大小格式化为字符串
85
+ * @param sizeKB 文件大小(单位:KB)
86
+ * @param invalidText 输入无效时返回文本
87
+ */
88
+ declare function formatFileSizeFromKB(sizeKB: number, invalidText?: string): string;
89
+ /**
90
+ * 获取目录总大小(字节),递归统计所有子文件
91
+ * 符号链接:只计算链接文件本身的大小,不跟随指向目录
92
+ * 权限错误:跳过该文件/目录,大小计为 0
93
+ * @param dir 目录路径
94
+ * @returns 总字节数
95
+ */
96
+ declare function getDirSize(dir: string): Promise<number>;
97
+ /**
98
+ * 获取文件/文件夹大小
99
+ * @param filePath 文件/文件夹路径
100
+ */
101
+ declare function getFileSizeKB(filePath: string): Promise<number>;
102
+
103
+ /**
104
+ * 命令执行的选项
105
+ */
106
+ interface ExecOptions {
107
+ /**
108
+ * 判断结果码是否成功
109
+ * @param number 结果码
110
+ */
111
+ codeIsSuccess?: (number: number) => boolean;
112
+ /**
113
+ * 终止信号
114
+ */
115
+ signal?: AbortSignal;
116
+ }
117
+ /**
118
+ * 执行 windows 的命令
119
+ * @param cmd 命令
120
+ * @param options 执行选项
121
+ */
122
+ declare function execWinCmd(cmd: string, options?: ExecOptions): Promise<string>;
123
+
124
+ /**
125
+ * 文件拷贝工具,支持文件或文件夹
126
+ */
127
+ declare function copyFile(source: string, destination: string, signal?: AbortSignal): Promise<void>;
128
+
129
+ /**
130
+ * 打开资源管理器并定位到目录或者文件
131
+ * @param fileOrDir 定位的目录或文件
132
+ */
133
+ declare function showInExplorer(fileOrDir: string): Promise<void>;
134
+
135
+ /**
136
+ * 打开注册表
137
+ * @param path 显示的路径
138
+ */
139
+ declare function openRegedit(path: string): Promise<string>;
140
+ /**
141
+ * 导出注册表
142
+ * @param regPath 注册表路径
143
+ * @param filePath 导出的文件路径
144
+ */
145
+ declare function exportRegedit(regPath: string, filePath: string): Promise<void>;
146
+ /**
147
+ * 导入注册表
148
+ * @param regPath 注册表路径
149
+ * @param filePath 导入的文件路径
150
+ */
151
+ declare function importRegedit(regPath: string, filePath: string): Promise<void>;
152
+
153
+ export { copyFile, deleteFiles, downloadFile, emptyDirectory, ensureDir, ensureDirSync, execWinCmd, existsFile, exportRegedit, findFiles, findFilesByPrefixAndSuffix, formatFileSizeFromKB, getDirSize, getEnv, getFileSizeKB, importRegedit, isFile, isFileNotFoundError, openRegedit, readJSONFile, readOrInitJSON, showInExplorer, updateJSON, writeJSONFile };