@longmo-utils/node 1.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/dist/index.cjs ADDED
@@ -0,0 +1,515 @@
1
+ let node_fs = require("node:fs");
2
+ let node_path = require("node:path");
3
+ let node_url = require("node:url");
4
+
5
+ //#region src/fs/ensureDir.ts
6
+ /**
7
+ * 确保目录存在,如果不存在则创建
8
+ * @param dirPath - 目录路径
9
+ * @example
10
+ * ```ts
11
+ * await ensureDir('./dist')
12
+ * ```
13
+ * @public
14
+ */
15
+ async function ensureDir(dirPath) {
16
+ try {
17
+ await node_fs.promises.access(dirPath);
18
+ } catch {
19
+ await node_fs.promises.mkdir(dirPath, { recursive: true });
20
+ }
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/fs/copy.ts
25
+ /**
26
+ * 递归复制文件或目录
27
+ * @param src - 源路径
28
+ * @param dest - 目标路径
29
+ * @example
30
+ * ```ts
31
+ * await copy('./src', './dist')
32
+ * ```
33
+ * @public
34
+ */
35
+ async function copy(src, dest) {
36
+ if ((await node_fs.promises.stat(src)).isDirectory()) {
37
+ await ensureDir(dest);
38
+ const files = await node_fs.promises.readdir(src);
39
+ await Promise.all(files.map(async (file) => {
40
+ await copy((0, node_path.join)(src, file), (0, node_path.join)(dest, file));
41
+ }));
42
+ } else {
43
+ await node_fs.promises.mkdir((0, node_path.dirname)(dest), { recursive: true });
44
+ await node_fs.promises.copyFile(src, dest);
45
+ }
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/fs/exists.ts
50
+ /**
51
+ * 检查文件或目录是否存在
52
+ * @param filePath - 文件或目录路径
53
+ * @returns 是否存在
54
+ * @example
55
+ * ```ts
56
+ * const isExist = await exists('./config.json')
57
+ * ```
58
+ * @public
59
+ */
60
+ async function exists(filePath) {
61
+ try {
62
+ await node_fs.promises.access(filePath);
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/fs/getDirname.ts
71
+ /**
72
+ * 获取当前模块的目录名
73
+ * @param url - 模块的 URL
74
+ * @returns 目录名
75
+ * @example
76
+ * ```ts
77
+ * const __dirname = getDirname(import.meta.url)
78
+ * ```
79
+ * @public
80
+ */
81
+ function getDirname(url) {
82
+ return (0, node_path.dirname)((0, node_url.fileURLToPath)(url));
83
+ }
84
+
85
+ //#endregion
86
+ //#region src/fs/getFiles.ts
87
+ /**
88
+ * 递归获取目录下的所有文件
89
+ * @param dirPath - 目录路径
90
+ * @param extensions - 可选的文件扩展名过滤器
91
+ * @returns 文件路径数组
92
+ * @example
93
+ * ```ts
94
+ * const allFiles = await getFiles('./src')
95
+ * const tsFiles = await getFiles('./src', ['.ts', '.tsx'])
96
+ * ```
97
+ * @public
98
+ */
99
+ async function getFiles(dirPath, extensions) {
100
+ const files = [];
101
+ async function traverse(currentPath) {
102
+ const entries = await node_fs.promises.readdir(currentPath, { withFileTypes: true });
103
+ for (const entry of entries) {
104
+ const fullPath = (0, node_path.join)(currentPath, entry.name);
105
+ if (entry.isDirectory()) await traverse(fullPath);
106
+ else if (entry.isFile()) {
107
+ if (!extensions || extensions.some((ext) => entry.name.endsWith(ext))) files.push(fullPath);
108
+ }
109
+ }
110
+ }
111
+ await traverse(dirPath);
112
+ return files;
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/fs/readJson.ts
117
+ /**
118
+ * 读取 JSON 文件
119
+ * @param filePath - 文件路径
120
+ * @returns 解析后的 JSON 数据
121
+ * @example
122
+ * ```ts
123
+ * const data = await readJson('./config.json')
124
+ * ```
125
+ * @public
126
+ */
127
+ async function readJson(filePath) {
128
+ const content = await node_fs.promises.readFile(filePath, "utf-8");
129
+ return JSON.parse(content);
130
+ }
131
+
132
+ //#endregion
133
+ //#region src/fs/readFileOrDefault.ts
134
+ /**
135
+ * 如果文件存在则读取,否则返回默认值
136
+ * @param filePath - 文件路径
137
+ * @param defaultValue - 默认值
138
+ * @returns 文件内容或默认值
139
+ * @example
140
+ * ```ts
141
+ * const config = await readFileOrDefault('./config.json', { theme: 'light' })
142
+ * ```
143
+ * @public
144
+ */
145
+ async function readFileOrDefault(filePath, defaultValue) {
146
+ if (!await exists(filePath)) return defaultValue;
147
+ return readJson(filePath);
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/fs/remove.ts
152
+ /**
153
+ * 递归删除文件或目录
154
+ * @param filePath - 文件或目录路径
155
+ * @example
156
+ * ```ts
157
+ * await remove('./temp')
158
+ * ```
159
+ * @public
160
+ */
161
+ async function remove(filePath) {
162
+ try {
163
+ if ((await node_fs.promises.stat(filePath)).isDirectory()) {
164
+ const files = await node_fs.promises.readdir(filePath);
165
+ await Promise.all(files.map(async (file) => {
166
+ await remove((0, node_path.join)(filePath, file));
167
+ }));
168
+ await node_fs.promises.rmdir(filePath);
169
+ } else await node_fs.promises.unlink(filePath);
170
+ } catch {}
171
+ }
172
+
173
+ //#endregion
174
+ //#region src/fs/writeJson.ts
175
+ /**
176
+ * 将数据写入 JSON 文件
177
+ * @param filePath - 文件路径
178
+ * @param data - 要写入的数据
179
+ * @example
180
+ * ```ts
181
+ * await writeJson('./config.json', { name: 'test' })
182
+ * ```
183
+ * @public
184
+ */
185
+ async function writeJson(filePath, data) {
186
+ const content = JSON.stringify(data, null, 2);
187
+ await node_fs.promises.writeFile(filePath, content, "utf-8");
188
+ }
189
+
190
+ //#endregion
191
+ //#region src/env/getEnv.ts
192
+ /**
193
+ * 获取环境变量
194
+ * @param key - 环境变量键
195
+ * @param defaultValue - 默认值
196
+ * @returns 环境变量值
197
+ * @example
198
+ * ```ts
199
+ * const value = getEnv('API_URL', 'http://localhost:3000')
200
+ * ```
201
+ * @public
202
+ */
203
+ function getEnv(key, defaultValue) {
204
+ return process.env[key] || defaultValue || "";
205
+ }
206
+
207
+ //#endregion
208
+ //#region src/env/getEnvBool.ts
209
+ /**
210
+ * 获取布尔类型的环境变量
211
+ * @param key - 环境变量键
212
+ * @param defaultValue - 默认值(默认: false)
213
+ * @returns 布尔值
214
+ * @example
215
+ * ```ts
216
+ * const enabled = getEnvBool('DEBUG', false)
217
+ * // DEBUG=true 或 DEBUG=1 返回 true
218
+ * // DEBUG=false 或 DEBUG=0 返回 false
219
+ * ```
220
+ * @public
221
+ */
222
+ function getEnvBool(key, defaultValue = false) {
223
+ var _process$env$key;
224
+ const value = (_process$env$key = process.env[key]) === null || _process$env$key === void 0 ? void 0 : _process$env$key.toLowerCase();
225
+ if (value === "true" || value === "1") return true;
226
+ if (value === "false" || value === "0") return false;
227
+ return defaultValue;
228
+ }
229
+
230
+ //#endregion
231
+ //#region src/env/getEnvMode.ts
232
+ /**
233
+ * 获取当前环境模式(development、production、test)
234
+ * @returns 环境模式
235
+ * @example
236
+ * ```ts
237
+ * const mode = getEnvMode()
238
+ * console.log(mode) // 'development' | 'production' | 'test'
239
+ * ```
240
+ * @public
241
+ */
242
+ function getEnvMode() {
243
+ return process.env.NODE_ENV || "development";
244
+ }
245
+
246
+ //#endregion
247
+ //#region src/env/getEnvNumber.ts
248
+ /**
249
+ * 获取数字类型的环境变量
250
+ * @param key - 环境变量键
251
+ * @param defaultValue - 默认值(默认: 0)
252
+ * @returns 数字值
253
+ * @example
254
+ * ```ts
255
+ * const port = getEnvNumber('PORT', 3000)
256
+ * ```
257
+ * @public
258
+ */
259
+ function getEnvNumber(key, defaultValue = 0) {
260
+ const value = process.env[key];
261
+ const parsed = value ? parseInt(value, 10) : NaN;
262
+ return isNaN(parsed) ? defaultValue : parsed;
263
+ }
264
+
265
+ //#endregion
266
+ //#region src/env/hasEnv.ts
267
+ /**
268
+ * 检查环境变量是否已设置
269
+ * @param key - 环境变量键
270
+ * @returns 是否已设置
271
+ * @example
272
+ * ```ts
273
+ * if (hasEnv('API_KEY')) {
274
+ * console.log('API_KEY is set')
275
+ * }
276
+ * ```
277
+ * @public
278
+ */
279
+ function hasEnv(key) {
280
+ return typeof process.env[key] !== "undefined";
281
+ }
282
+
283
+ //#endregion
284
+ //#region src/env/isDevelopment.ts
285
+ /**
286
+ * 检查当前环境是否为开发环境
287
+ * @returns 是否为开发环境
288
+ * @example
289
+ * ```ts
290
+ * if (isDevelopment()) {
291
+ * console.log('Running in development mode')
292
+ * }
293
+ * ```
294
+ * @public
295
+ */
296
+ function isDevelopment() {
297
+ return getEnvMode() === "development";
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/env/isProduction.ts
302
+ /**
303
+ * 检查当前环境是否为生产环境
304
+ * @returns 是否为生产环境
305
+ * @example
306
+ * ```ts
307
+ * if (isProduction()) {
308
+ * console.log('Running in production mode')
309
+ * }
310
+ * ```
311
+ * @public
312
+ */
313
+ function isProduction() {
314
+ return getEnvMode() === "production";
315
+ }
316
+
317
+ //#endregion
318
+ //#region src/process/exit.ts
319
+ /**
320
+ * 退出当前进程
321
+ * @param code - 退出码(默认: 0)
322
+ * @returns never
323
+ * @example
324
+ * ```ts
325
+ * exit(0) // 正常退出
326
+ * exit(1) // 异常退出
327
+ * ```
328
+ * @public
329
+ */
330
+ function exit(code = 0) {
331
+ process.exit(code);
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/process/getCwd.ts
336
+ /**
337
+ * 获取当前工作目录
338
+ * @returns 当前工作目录路径
339
+ * @example
340
+ * ```ts
341
+ * const cwd = getCwd()
342
+ * console.log(cwd) // '/path/to/current/directory'
343
+ * ```
344
+ * @public
345
+ */
346
+ function getCwd() {
347
+ return process.cwd();
348
+ }
349
+
350
+ //#endregion
351
+ //#region src/process/getMemoryUsage.ts
352
+ /**
353
+ * 获取内存使用信息
354
+ * @returns 内存使用信息对象
355
+ * @example
356
+ * ```ts
357
+ * const usage = getMemoryUsage()
358
+ * console.log(usage)
359
+ * // {
360
+ * // rss: 12345678,
361
+ * // heapTotal: 8765432,
362
+ * // heapUsed: 4321098,
363
+ * // external: 123456,
364
+ * // arrayBuffers: 12345
365
+ * // }
366
+ * ```
367
+ * @public
368
+ */
369
+ function getMemoryUsage() {
370
+ return process.memoryUsage();
371
+ }
372
+
373
+ //#endregion
374
+ //#region src/process/getNodeVersion.ts
375
+ /**
376
+ * 获取 Node.js 版本
377
+ * @returns Node.js 版本字符串
378
+ * @example
379
+ * ```ts
380
+ * const version = getNodeVersion()
381
+ * console.log(version) // 'v18.0.0'
382
+ * ```
383
+ * @public
384
+ */
385
+ function getNodeVersion() {
386
+ return process.version;
387
+ }
388
+
389
+ //#endregion
390
+ //#region src/process/getPid.ts
391
+ /**
392
+ * 获取进程 ID
393
+ * @returns 进程 ID
394
+ * @example
395
+ * ```ts
396
+ * const pid = getPid()
397
+ * console.log(pid) // 12345
398
+ * ```
399
+ * @public
400
+ */
401
+ function getPid() {
402
+ return process.pid;
403
+ }
404
+
405
+ //#endregion
406
+ //#region src/process/getPlatform.ts
407
+ /**
408
+ * 获取当前平台
409
+ * @returns 平台名称(win32、darwin、linux 等)
410
+ * @example
411
+ * ```ts
412
+ * const platform = getPlatform()
413
+ * console.log(platform) // 'win32' | 'darwin' | 'linux'
414
+ * ```
415
+ * @public
416
+ */
417
+ function getPlatform() {
418
+ return process.platform;
419
+ }
420
+
421
+ //#endregion
422
+ //#region src/process/getUptime.ts
423
+ /**
424
+ * 获取进程运行时间(秒)
425
+ * @returns 运行时间(秒)
426
+ * @example
427
+ * ```ts
428
+ * const uptime = getUptime()
429
+ * console.log(uptime) // 3600
430
+ * ```
431
+ * @public
432
+ */
433
+ function getUptime() {
434
+ return process.uptime();
435
+ }
436
+
437
+ //#endregion
438
+ //#region src/process/isLinux.ts
439
+ /**
440
+ * 检查当前平台是否为 Linux
441
+ * @returns 是否为 Linux
442
+ * @example
443
+ * ```ts
444
+ * if (isLinux()) {
445
+ * console.log('Running on Linux')
446
+ * }
447
+ * ```
448
+ * @public
449
+ */
450
+ function isLinux() {
451
+ return process.platform === "linux";
452
+ }
453
+
454
+ //#endregion
455
+ //#region src/process/isMac.ts
456
+ /**
457
+ * 检查当前平台是否为 macOS
458
+ * @returns 是否为 macOS
459
+ * @example
460
+ * ```ts
461
+ * if (isMac()) {
462
+ * console.log('Running on macOS')
463
+ * }
464
+ * ```
465
+ * @public
466
+ */
467
+ function isMac() {
468
+ return process.platform === "darwin";
469
+ }
470
+
471
+ //#endregion
472
+ //#region src/process/isWindows.ts
473
+ /**
474
+ * 检查当前平台是否为 Windows
475
+ * @returns 是否为 Windows
476
+ * @example
477
+ * ```ts
478
+ * if (isWindows()) {
479
+ * console.log('Running on Windows')
480
+ * }
481
+ * ```
482
+ * @public
483
+ */
484
+ function isWindows() {
485
+ return process.platform === "win32";
486
+ }
487
+
488
+ //#endregion
489
+ exports.copy = copy;
490
+ exports.ensureDir = ensureDir;
491
+ exports.exists = exists;
492
+ exports.exit = exit;
493
+ exports.getCwd = getCwd;
494
+ exports.getDirname = getDirname;
495
+ exports.getEnv = getEnv;
496
+ exports.getEnvBool = getEnvBool;
497
+ exports.getEnvMode = getEnvMode;
498
+ exports.getEnvNumber = getEnvNumber;
499
+ exports.getFiles = getFiles;
500
+ exports.getMemoryUsage = getMemoryUsage;
501
+ exports.getNodeVersion = getNodeVersion;
502
+ exports.getPid = getPid;
503
+ exports.getPlatform = getPlatform;
504
+ exports.getUptime = getUptime;
505
+ exports.hasEnv = hasEnv;
506
+ exports.isDevelopment = isDevelopment;
507
+ exports.isLinux = isLinux;
508
+ exports.isMac = isMac;
509
+ exports.isProduction = isProduction;
510
+ exports.isWindows = isWindows;
511
+ exports.readFileOrDefault = readFileOrDefault;
512
+ exports.readJson = readJson;
513
+ exports.remove = remove;
514
+ exports.writeJson = writeJson;
515
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["fs","fs","fs","fs","fs","fs","fs"],"sources":["../src/fs/ensureDir.ts","../src/fs/copy.ts","../src/fs/exists.ts","../src/fs/getDirname.ts","../src/fs/getFiles.ts","../src/fs/readJson.ts","../src/fs/readFileOrDefault.ts","../src/fs/remove.ts","../src/fs/writeJson.ts","../src/env/getEnv.ts","../src/env/getEnvBool.ts","../src/env/getEnvMode.ts","../src/env/getEnvNumber.ts","../src/env/hasEnv.ts","../src/env/isDevelopment.ts","../src/env/isProduction.ts","../src/process/exit.ts","../src/process/getCwd.ts","../src/process/getMemoryUsage.ts","../src/process/getNodeVersion.ts","../src/process/getPid.ts","../src/process/getPlatform.ts","../src/process/getUptime.ts","../src/process/isLinux.ts","../src/process/isMac.ts","../src/process/isWindows.ts"],"sourcesContent":["import { promises as fs } from 'fs'\n\n/**\n * 确保目录存在,如果不存在则创建\n * @param dirPath - 目录路径\n * @example\n * ```ts\n * await ensureDir('./dist')\n * ```\n * @public\n */\nexport async function ensureDir(dirPath: string): Promise<void> {\n try {\n await fs.access(dirPath)\n } catch {\n await fs.mkdir(dirPath, { recursive: true })\n }\n}\n","import { promises as fs } from 'fs'\nimport { join, dirname } from 'path'\nimport { ensureDir } from './ensureDir'\n\n/**\n * 递归复制文件或目录\n * @param src - 源路径\n * @param dest - 目标路径\n * @example\n * ```ts\n * await copy('./src', './dist')\n * ```\n * @public\n */\nexport async function copy(src: string, dest: string): Promise<void> {\n const stat = await fs.stat(src)\n\n if (stat.isDirectory()) {\n await ensureDir(dest)\n const files = await fs.readdir(src)\n await Promise.all(\n files.map(async (file) => {\n const srcPath = join(src, file)\n const destPath = join(dest, file)\n await copy(srcPath, destPath)\n })\n )\n } else {\n await fs.mkdir(dirname(dest), { recursive: true })\n await fs.copyFile(src, dest)\n }\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 检查文件或目录是否存在\n * @param filePath - 文件或目录路径\n * @returns 是否存在\n * @example\n * ```ts\n * const isExist = await exists('./config.json')\n * ```\n * @public\n */\nexport async function exists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath)\n return true\n } catch {\n return false\n }\n}\n","import { dirname } from 'path'\nimport { fileURLToPath } from 'url'\n\n/**\n * 获取当前模块的目录名\n * @param url - 模块的 URL\n * @returns 目录名\n * @example\n * ```ts\n * const __dirname = getDirname(import.meta.url)\n * ```\n * @public\n */\nexport function getDirname(url: string): string {\n return dirname(fileURLToPath(url))\n}\n","import { promises as fs } from 'fs'\nimport { join } from 'path'\n\n/**\n * 递归获取目录下的所有文件\n * @param dirPath - 目录路径\n * @param extensions - 可选的文件扩展名过滤器\n * @returns 文件路径数组\n * @example\n * ```ts\n * const allFiles = await getFiles('./src')\n * const tsFiles = await getFiles('./src', ['.ts', '.tsx'])\n * ```\n * @public\n */\nexport async function getFiles(\n dirPath: string,\n extensions?: string[]\n): Promise<string[]> {\n const files: string[] = []\n\n async function traverse(currentPath: string) {\n const entries = await fs.readdir(currentPath, { withFileTypes: true })\n\n for (const entry of entries) {\n const fullPath = join(currentPath, entry.name)\n\n if (entry.isDirectory()) {\n await traverse(fullPath)\n } else if (entry.isFile()) {\n if (!extensions || extensions.some((ext) => entry.name.endsWith(ext))) {\n files.push(fullPath)\n }\n }\n }\n }\n\n await traverse(dirPath)\n return files\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 读取 JSON 文件\n * @param filePath - 文件路径\n * @returns 解析后的 JSON 数据\n * @example\n * ```ts\n * const data = await readJson('./config.json')\n * ```\n * @public\n */\nexport async function readJson<T = any>(filePath: string): Promise<T> {\n const content = await fs.readFile(filePath, 'utf-8')\n return JSON.parse(content)\n}\n","import { exists } from './exists'\nimport { readJson } from './readJson'\n\n/**\n * 如果文件存在则读取,否则返回默认值\n * @param filePath - 文件路径\n * @param defaultValue - 默认值\n * @returns 文件内容或默认值\n * @example\n * ```ts\n * const config = await readFileOrDefault('./config.json', { theme: 'light' })\n * ```\n * @public\n */\nexport async function readFileOrDefault<T>(\n filePath: string,\n defaultValue: T\n): Promise<T> {\n const isExist = await exists(filePath)\n if (!isExist) {\n return defaultValue\n }\n return readJson<T>(filePath)\n}\n","import { promises as fs } from 'fs'\nimport { join } from 'path'\n\n/**\n * 递归删除文件或目录\n * @param filePath - 文件或目录路径\n * @example\n * ```ts\n * await remove('./temp')\n * ```\n * @public\n */\nexport async function remove(filePath: string): Promise<void> {\n try {\n const stat = await fs.stat(filePath)\n if (stat.isDirectory()) {\n const files = await fs.readdir(filePath)\n await Promise.all(\n files.map(async (file) => {\n const fullPath = join(filePath, file)\n await remove(fullPath)\n })\n )\n await fs.rmdir(filePath)\n } else {\n await fs.unlink(filePath)\n }\n } catch {\n // File doesn't exist, ignore\n }\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 将数据写入 JSON 文件\n * @param filePath - 文件路径\n * @param data - 要写入的数据\n * @example\n * ```ts\n * await writeJson('./config.json', { name: 'test' })\n * ```\n * @public\n */\nexport async function writeJson(filePath: string, data: any): Promise<void> {\n const content = JSON.stringify(data, null, 2)\n await fs.writeFile(filePath, content, 'utf-8')\n}\n","/**\n * 获取环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值\n * @returns 环境变量值\n * @example\n * ```ts\n * const value = getEnv('API_URL', 'http://localhost:3000')\n * ```\n * @public\n */\nexport function getEnv(key: string, defaultValue?: string): string {\n return process.env[key] || defaultValue || ''\n}\n","/**\n * 获取布尔类型的环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值(默认: false)\n * @returns 布尔值\n * @example\n * ```ts\n * const enabled = getEnvBool('DEBUG', false)\n * // DEBUG=true 或 DEBUG=1 返回 true\n * // DEBUG=false 或 DEBUG=0 返回 false\n * ```\n * @public\n */\nexport function getEnvBool(key: string, defaultValue: boolean = false): boolean {\n const value = process.env[key]?.toLowerCase()\n if (value === 'true' || value === '1') return true\n if (value === 'false' || value === '0') return false\n return defaultValue\n}\n","/**\n * 获取当前环境模式(development、production、test)\n * @returns 环境模式\n * @example\n * ```ts\n * const mode = getEnvMode()\n * console.log(mode) // 'development' | 'production' | 'test'\n * ```\n * @public\n */\nexport function getEnvMode(): string {\n return process.env.NODE_ENV || 'development'\n}\n","/**\n * 获取数字类型的环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值(默认: 0)\n * @returns 数字值\n * @example\n * ```ts\n * const port = getEnvNumber('PORT', 3000)\n * ```\n * @public\n */\nexport function getEnvNumber(key: string, defaultValue: number = 0): number {\n const value = process.env[key]\n const parsed = value ? parseInt(value, 10) : NaN\n return isNaN(parsed) ? defaultValue : parsed\n}\n","/**\n * 检查环境变量是否已设置\n * @param key - 环境变量键\n * @returns 是否已设置\n * @example\n * ```ts\n * if (hasEnv('API_KEY')) {\n * console.log('API_KEY is set')\n * }\n * ```\n * @public\n */\nexport function hasEnv(key: string): boolean {\n return typeof process.env[key] !== 'undefined'\n}\n","import { getEnvMode } from './getEnvMode'\n\n/**\n * 检查当前环境是否为开发环境\n * @returns 是否为开发环境\n * @example\n * ```ts\n * if (isDevelopment()) {\n * console.log('Running in development mode')\n * }\n * ```\n * @public\n */\nexport function isDevelopment(): boolean {\n return getEnvMode() === 'development'\n}\n","import { getEnvMode } from './getEnvMode'\n\n/**\n * 检查当前环境是否为生产环境\n * @returns 是否为生产环境\n * @example\n * ```ts\n * if (isProduction()) {\n * console.log('Running in production mode')\n * }\n * ```\n * @public\n */\nexport function isProduction(): boolean {\n return getEnvMode() === 'production'\n}\n","/**\n * 退出当前进程\n * @param code - 退出码(默认: 0)\n * @returns never\n * @example\n * ```ts\n * exit(0) // 正常退出\n * exit(1) // 异常退出\n * ```\n * @public\n */\nexport function exit(code: number = 0): never {\n process.exit(code)\n}\n","/**\n * 获取当前工作目录\n * @returns 当前工作目录路径\n * @example\n * ```ts\n * const cwd = getCwd()\n * console.log(cwd) // '/path/to/current/directory'\n * ```\n * @public\n */\nexport function getCwd(): string {\n return process.cwd()\n}\n","/**\n * 获取内存使用信息\n * @returns 内存使用信息对象\n * @example\n * ```ts\n * const usage = getMemoryUsage()\n * console.log(usage)\n * // {\n * // rss: 12345678,\n * // heapTotal: 8765432,\n * // heapUsed: 4321098,\n * // external: 123456,\n * // arrayBuffers: 12345\n * // }\n * ```\n * @public\n */\nexport function getMemoryUsage(): NodeJS.MemoryUsage {\n return process.memoryUsage()\n}\n","/**\n * 获取 Node.js 版本\n * @returns Node.js 版本字符串\n * @example\n * ```ts\n * const version = getNodeVersion()\n * console.log(version) // 'v18.0.0'\n * ```\n * @public\n */\nexport function getNodeVersion(): string {\n return process.version\n}\n","/**\n * 获取进程 ID\n * @returns 进程 ID\n * @example\n * ```ts\n * const pid = getPid()\n * console.log(pid) // 12345\n * ```\n * @public\n */\nexport function getPid(): number {\n return process.pid\n}\n","/**\n * 获取当前平台\n * @returns 平台名称(win32、darwin、linux 等)\n * @example\n * ```ts\n * const platform = getPlatform()\n * console.log(platform) // 'win32' | 'darwin' | 'linux'\n * ```\n * @public\n */\nexport function getPlatform(): NodeJS.Platform {\n return process.platform\n}\n","/**\n * 获取进程运行时间(秒)\n * @returns 运行时间(秒)\n * @example\n * ```ts\n * const uptime = getUptime()\n * console.log(uptime) // 3600\n * ```\n * @public\n */\nexport function getUptime(): number {\n return process.uptime()\n}\n","/**\n * 检查当前平台是否为 Linux\n * @returns 是否为 Linux\n * @example\n * ```ts\n * if (isLinux()) {\n * console.log('Running on Linux')\n * }\n * ```\n * @public\n */\nexport function isLinux(): boolean {\n return process.platform === 'linux'\n}\n","/**\n * 检查当前平台是否为 macOS\n * @returns 是否为 macOS\n * @example\n * ```ts\n * if (isMac()) {\n * console.log('Running on macOS')\n * }\n * ```\n * @public\n */\nexport function isMac(): boolean {\n return process.platform === 'darwin'\n}\n","/**\n * 检查当前平台是否为 Windows\n * @returns 是否为 Windows\n * @example\n * ```ts\n * if (isWindows()) {\n * console.log('Running on Windows')\n * }\n * ```\n * @public\n */\nexport function isWindows(): boolean {\n return process.platform === 'win32'\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,eAAsB,UAAU,SAAgC;AAC9D,KAAI;AACF,QAAMA,iBAAG,OAAO,QAAQ;SAClB;AACN,QAAMA,iBAAG,MAAM,SAAS,EAAE,WAAW,MAAM,CAAC;;;;;;;;;;;;;;;;ACDhD,eAAsB,KAAK,KAAa,MAA6B;AAGnE,MAFa,MAAMC,iBAAG,KAAK,IAAI,EAEtB,aAAa,EAAE;AACtB,QAAM,UAAU,KAAK;EACrB,MAAM,QA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;;;;;;;;;;;;;ACFpB,SAAgB,SAAiB;AAC/B,QAAO,QAAQ,KAAK;;;;;;;;;;;;;;;;;;;;;;ACMtB,SAAgB,iBAAqC;AACnD,QAAO,QAAQ,aAAa;;;;;;;;;;;;;;;ACR9B,SAAgB,iBAAyB;AACvC,QAAO,QAAQ;;;;;;;;;;;;;;;ACDjB,SAAgB,SAAiB;AAC/B,QAAO,QAAQ;;;;;;;;;;;;;;;ACDjB,SAAgB,cAA+B;AAC7C,QAAO,QAAQ;;;;;;;;;;;;;;;ACDjB,SAAgB,YAAoB;AAClC,QAAO,QAAQ,QAAQ;;;;;;;;;;;;;;;;ACAzB,SAAgB,UAAmB;AACjC,QAAO,QAAQ,aAAa;;;;;;;;;;;;;;;;ACD9B,SAAgB,QAAiB;AAC/B,QAAO,QAAQ,aAAa;;;;;;;;;;;;;;;;ACD9B,SAAgB,YAAqB;AACnC,QAAO,QAAQ,aAAa"}
@@ -0,0 +1,80 @@
1
+ //#region src/fs/copy.d.ts
2
+ declare function copy(src: string, dest: string): Promise<void>;
3
+ //#endregion
4
+ //#region src/fs/ensureDir.d.ts
5
+ declare function ensureDir(dirPath: string): Promise<void>;
6
+ //#endregion
7
+ //#region src/fs/exists.d.ts
8
+ declare function exists(filePath: string): Promise<boolean>;
9
+ //#endregion
10
+ //#region src/fs/getDirname.d.ts
11
+ declare function getDirname(url: string): string;
12
+ //#endregion
13
+ //#region src/fs/getFiles.d.ts
14
+ declare function getFiles(dirPath: string, extensions?: string[]): Promise<string[]>;
15
+ //#endregion
16
+ //#region src/fs/readFileOrDefault.d.ts
17
+ declare function readFileOrDefault<T>(filePath: string, defaultValue: T): Promise<T>;
18
+ //#endregion
19
+ //#region src/fs/readJson.d.ts
20
+ declare function readJson<T = any>(filePath: string): Promise<T>;
21
+ //#endregion
22
+ //#region src/fs/remove.d.ts
23
+ declare function remove(filePath: string): Promise<void>;
24
+ //#endregion
25
+ //#region src/fs/writeJson.d.ts
26
+ declare function writeJson(filePath: string, data: any): Promise<void>;
27
+ //#endregion
28
+ //#region src/env/getEnv.d.ts
29
+ declare function getEnv(key: string, defaultValue?: string): string;
30
+ //#endregion
31
+ //#region src/env/getEnvBool.d.ts
32
+ declare function getEnvBool(key: string, defaultValue?: boolean): boolean;
33
+ //#endregion
34
+ //#region src/env/getEnvMode.d.ts
35
+ declare function getEnvMode(): string;
36
+ //#endregion
37
+ //#region src/env/getEnvNumber.d.ts
38
+ declare function getEnvNumber(key: string, defaultValue?: number): number;
39
+ //#endregion
40
+ //#region src/env/hasEnv.d.ts
41
+ declare function hasEnv(key: string): boolean;
42
+ //#endregion
43
+ //#region src/env/isDevelopment.d.ts
44
+ declare function isDevelopment(): boolean;
45
+ //#endregion
46
+ //#region src/env/isProduction.d.ts
47
+ declare function isProduction(): boolean;
48
+ //#endregion
49
+ //#region src/process/exit.d.ts
50
+ declare function exit(code?: number): never;
51
+ //#endregion
52
+ //#region src/process/getCwd.d.ts
53
+ declare function getCwd(): string;
54
+ //#endregion
55
+ //#region src/process/getMemoryUsage.d.ts
56
+ declare function getMemoryUsage(): NodeJS.MemoryUsage;
57
+ //#endregion
58
+ //#region src/process/getNodeVersion.d.ts
59
+ declare function getNodeVersion(): string;
60
+ //#endregion
61
+ //#region src/process/getPid.d.ts
62
+ declare function getPid(): number;
63
+ //#endregion
64
+ //#region src/process/getPlatform.d.ts
65
+ declare function getPlatform(): NodeJS.Platform;
66
+ //#endregion
67
+ //#region src/process/getUptime.d.ts
68
+ declare function getUptime(): number;
69
+ //#endregion
70
+ //#region src/process/isLinux.d.ts
71
+ declare function isLinux(): boolean;
72
+ //#endregion
73
+ //#region src/process/isMac.d.ts
74
+ declare function isMac(): boolean;
75
+ //#endregion
76
+ //#region src/process/isWindows.d.ts
77
+ declare function isWindows(): boolean;
78
+ //#endregion
79
+ export { copy, ensureDir, exists, exit, getCwd, getDirname, getEnv, getEnvBool, getEnvMode, getEnvNumber, getFiles, getMemoryUsage, getNodeVersion, getPid, getPlatform, getUptime, hasEnv, isDevelopment, isLinux, isMac, isProduction, isWindows, readFileOrDefault, readJson, remove, writeJson };
80
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/fs/copy.ts","../src/fs/ensureDir.ts","../src/fs/exists.ts","../src/fs/getDirname.ts","../src/fs/getFiles.ts","../src/fs/readFileOrDefault.ts","../src/fs/readJson.ts","../src/fs/remove.ts","../src/fs/writeJson.ts","../src/env/getEnv.ts","../src/env/getEnvBool.ts","../src/env/getEnvMode.ts","../src/env/getEnvNumber.ts","../src/env/hasEnv.ts","../src/env/isDevelopment.ts","../src/env/isProduction.ts","../src/process/exit.ts","../src/process/getCwd.ts","../src/process/getMemoryUsage.ts","../src/process/getNodeVersion.ts","../src/process/getPid.ts","../src/process/getPlatform.ts","../src/process/getUptime.ts","../src/process/isLinux.ts","../src/process/isMac.ts","../src/process/isWindows.ts"],"mappings":";iBAcsB,IAAA,CAAK,GAAA,UAAa,IAAA,WAAe,OAAA;;;iBCHjC,SAAA,CAAU,OAAA,WAAkB,OAAA;;;iBCC5B,MAAA,CAAO,QAAA,WAAmB,OAAA;;;iBCChC,UAAA,CAAW,GAAA;;;iBCEL,QAAA,CACpB,OAAA,UACA,UAAA,cACC,OAAA;;;iBCJmB,iBAAA,GAAA,CACpB,QAAA,UACA,YAAA,EAAc,CAAA,GACb,OAAA,CAAQ,CAAA;;;iBCLW,QAAA,SAAA,CAAkB,QAAA,WAAmB,OAAA,CAAQ,CAAA;;;iBCA7C,MAAA,CAAO,QAAA,WAAmB,OAAA;;;iBCA1B,SAAA,CAAU,QAAA,UAAkB,IAAA,QAAY,OAAA;;;iBCD9C,MAAA,CAAO,GAAA,UAAa,YAAA;;;iBCEpB,UAAA,CAAW,GAAA,UAAa,YAAA;;;iBCHxB,UAAA,CAAA;;;iBCCA,YAAA,CAAa,GAAA,UAAa,YAAA;;;iBCC1B,MAAA,CAAO,GAAA;;;iBCCP,aAAA,CAAA;;;iBCAA,YAAA,CAAA;;;iBCFA,IAAA,CAAK,IAAA;;;iBCDL,MAAA,CAAA;;;iBCOA,cAAA,CAAA,GAAkB,MAAA,CAAO,WAAA;;;iBCPzB,cAAA,CAAA;;;iBCAA,MAAA,CAAA;;;iBCAA,WAAA,CAAA,GAAe,MAAA,CAAO,QAAA;;;iBCAtB,SAAA,CAAA;;;iBCCA,OAAA,CAAA;;;iBCAA,KAAA,CAAA;;;iBCAA,SAAA,CAAA"}
@@ -0,0 +1,80 @@
1
+ //#region src/fs/copy.d.ts
2
+ declare function copy(src: string, dest: string): Promise<void>;
3
+ //#endregion
4
+ //#region src/fs/ensureDir.d.ts
5
+ declare function ensureDir(dirPath: string): Promise<void>;
6
+ //#endregion
7
+ //#region src/fs/exists.d.ts
8
+ declare function exists(filePath: string): Promise<boolean>;
9
+ //#endregion
10
+ //#region src/fs/getDirname.d.ts
11
+ declare function getDirname(url: string): string;
12
+ //#endregion
13
+ //#region src/fs/getFiles.d.ts
14
+ declare function getFiles(dirPath: string, extensions?: string[]): Promise<string[]>;
15
+ //#endregion
16
+ //#region src/fs/readFileOrDefault.d.ts
17
+ declare function readFileOrDefault<T>(filePath: string, defaultValue: T): Promise<T>;
18
+ //#endregion
19
+ //#region src/fs/readJson.d.ts
20
+ declare function readJson<T = any>(filePath: string): Promise<T>;
21
+ //#endregion
22
+ //#region src/fs/remove.d.ts
23
+ declare function remove(filePath: string): Promise<void>;
24
+ //#endregion
25
+ //#region src/fs/writeJson.d.ts
26
+ declare function writeJson(filePath: string, data: any): Promise<void>;
27
+ //#endregion
28
+ //#region src/env/getEnv.d.ts
29
+ declare function getEnv(key: string, defaultValue?: string): string;
30
+ //#endregion
31
+ //#region src/env/getEnvBool.d.ts
32
+ declare function getEnvBool(key: string, defaultValue?: boolean): boolean;
33
+ //#endregion
34
+ //#region src/env/getEnvMode.d.ts
35
+ declare function getEnvMode(): string;
36
+ //#endregion
37
+ //#region src/env/getEnvNumber.d.ts
38
+ declare function getEnvNumber(key: string, defaultValue?: number): number;
39
+ //#endregion
40
+ //#region src/env/hasEnv.d.ts
41
+ declare function hasEnv(key: string): boolean;
42
+ //#endregion
43
+ //#region src/env/isDevelopment.d.ts
44
+ declare function isDevelopment(): boolean;
45
+ //#endregion
46
+ //#region src/env/isProduction.d.ts
47
+ declare function isProduction(): boolean;
48
+ //#endregion
49
+ //#region src/process/exit.d.ts
50
+ declare function exit(code?: number): never;
51
+ //#endregion
52
+ //#region src/process/getCwd.d.ts
53
+ declare function getCwd(): string;
54
+ //#endregion
55
+ //#region src/process/getMemoryUsage.d.ts
56
+ declare function getMemoryUsage(): NodeJS.MemoryUsage;
57
+ //#endregion
58
+ //#region src/process/getNodeVersion.d.ts
59
+ declare function getNodeVersion(): string;
60
+ //#endregion
61
+ //#region src/process/getPid.d.ts
62
+ declare function getPid(): number;
63
+ //#endregion
64
+ //#region src/process/getPlatform.d.ts
65
+ declare function getPlatform(): NodeJS.Platform;
66
+ //#endregion
67
+ //#region src/process/getUptime.d.ts
68
+ declare function getUptime(): number;
69
+ //#endregion
70
+ //#region src/process/isLinux.d.ts
71
+ declare function isLinux(): boolean;
72
+ //#endregion
73
+ //#region src/process/isMac.d.ts
74
+ declare function isMac(): boolean;
75
+ //#endregion
76
+ //#region src/process/isWindows.d.ts
77
+ declare function isWindows(): boolean;
78
+ //#endregion
79
+ export { copy, ensureDir, exists, exit, getCwd, getDirname, getEnv, getEnvBool, getEnvMode, getEnvNumber, getFiles, getMemoryUsage, getNodeVersion, getPid, getPlatform, getUptime, hasEnv, isDevelopment, isLinux, isMac, isProduction, isWindows, readFileOrDefault, readJson, remove, writeJson };
80
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/fs/copy.ts","../src/fs/ensureDir.ts","../src/fs/exists.ts","../src/fs/getDirname.ts","../src/fs/getFiles.ts","../src/fs/readFileOrDefault.ts","../src/fs/readJson.ts","../src/fs/remove.ts","../src/fs/writeJson.ts","../src/env/getEnv.ts","../src/env/getEnvBool.ts","../src/env/getEnvMode.ts","../src/env/getEnvNumber.ts","../src/env/hasEnv.ts","../src/env/isDevelopment.ts","../src/env/isProduction.ts","../src/process/exit.ts","../src/process/getCwd.ts","../src/process/getMemoryUsage.ts","../src/process/getNodeVersion.ts","../src/process/getPid.ts","../src/process/getPlatform.ts","../src/process/getUptime.ts","../src/process/isLinux.ts","../src/process/isMac.ts","../src/process/isWindows.ts"],"mappings":";iBAcsB,IAAA,CAAK,GAAA,UAAa,IAAA,WAAe,OAAA;;;iBCHjC,SAAA,CAAU,OAAA,WAAkB,OAAA;;;iBCC5B,MAAA,CAAO,QAAA,WAAmB,OAAA;;;iBCChC,UAAA,CAAW,GAAA;;;iBCEL,QAAA,CACpB,OAAA,UACA,UAAA,cACC,OAAA;;;iBCJmB,iBAAA,GAAA,CACpB,QAAA,UACA,YAAA,EAAc,CAAA,GACb,OAAA,CAAQ,CAAA;;;iBCLW,QAAA,SAAA,CAAkB,QAAA,WAAmB,OAAA,CAAQ,CAAA;;;iBCA7C,MAAA,CAAO,QAAA,WAAmB,OAAA;;;iBCA1B,SAAA,CAAU,QAAA,UAAkB,IAAA,QAAY,OAAA;;;iBCD9C,MAAA,CAAO,GAAA,UAAa,YAAA;;;iBCEpB,UAAA,CAAW,GAAA,UAAa,YAAA;;;iBCHxB,UAAA,CAAA;;;iBCCA,YAAA,CAAa,GAAA,UAAa,YAAA;;;iBCC1B,MAAA,CAAO,GAAA;;;iBCCP,aAAA,CAAA;;;iBCAA,YAAA,CAAA;;;iBCFA,IAAA,CAAK,IAAA;;;iBCDL,MAAA,CAAA;;;iBCOA,cAAA,CAAA,GAAkB,MAAA,CAAO,WAAA;;;iBCPzB,cAAA,CAAA;;;iBCAA,MAAA,CAAA;;;iBCAA,WAAA,CAAA,GAAe,MAAA,CAAO,QAAA;;;iBCAtB,SAAA,CAAA;;;iBCCA,OAAA,CAAA;;;iBCAA,KAAA,CAAA;;;iBCAA,SAAA,CAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,490 @@
1
+ import { promises } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ //#region src/fs/ensureDir.ts
6
+ /**
7
+ * 确保目录存在,如果不存在则创建
8
+ * @param dirPath - 目录路径
9
+ * @example
10
+ * ```ts
11
+ * await ensureDir('./dist')
12
+ * ```
13
+ * @public
14
+ */
15
+ async function ensureDir(dirPath) {
16
+ try {
17
+ await promises.access(dirPath);
18
+ } catch {
19
+ await promises.mkdir(dirPath, { recursive: true });
20
+ }
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/fs/copy.ts
25
+ /**
26
+ * 递归复制文件或目录
27
+ * @param src - 源路径
28
+ * @param dest - 目标路径
29
+ * @example
30
+ * ```ts
31
+ * await copy('./src', './dist')
32
+ * ```
33
+ * @public
34
+ */
35
+ async function copy(src, dest) {
36
+ if ((await promises.stat(src)).isDirectory()) {
37
+ await ensureDir(dest);
38
+ const files = await promises.readdir(src);
39
+ await Promise.all(files.map(async (file) => {
40
+ await copy(join(src, file), join(dest, file));
41
+ }));
42
+ } else {
43
+ await promises.mkdir(dirname(dest), { recursive: true });
44
+ await promises.copyFile(src, dest);
45
+ }
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/fs/exists.ts
50
+ /**
51
+ * 检查文件或目录是否存在
52
+ * @param filePath - 文件或目录路径
53
+ * @returns 是否存在
54
+ * @example
55
+ * ```ts
56
+ * const isExist = await exists('./config.json')
57
+ * ```
58
+ * @public
59
+ */
60
+ async function exists(filePath) {
61
+ try {
62
+ await promises.access(filePath);
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/fs/getDirname.ts
71
+ /**
72
+ * 获取当前模块的目录名
73
+ * @param url - 模块的 URL
74
+ * @returns 目录名
75
+ * @example
76
+ * ```ts
77
+ * const __dirname = getDirname(import.meta.url)
78
+ * ```
79
+ * @public
80
+ */
81
+ function getDirname(url) {
82
+ return dirname(fileURLToPath(url));
83
+ }
84
+
85
+ //#endregion
86
+ //#region src/fs/getFiles.ts
87
+ /**
88
+ * 递归获取目录下的所有文件
89
+ * @param dirPath - 目录路径
90
+ * @param extensions - 可选的文件扩展名过滤器
91
+ * @returns 文件路径数组
92
+ * @example
93
+ * ```ts
94
+ * const allFiles = await getFiles('./src')
95
+ * const tsFiles = await getFiles('./src', ['.ts', '.tsx'])
96
+ * ```
97
+ * @public
98
+ */
99
+ async function getFiles(dirPath, extensions) {
100
+ const files = [];
101
+ async function traverse(currentPath) {
102
+ const entries = await promises.readdir(currentPath, { withFileTypes: true });
103
+ for (const entry of entries) {
104
+ const fullPath = join(currentPath, entry.name);
105
+ if (entry.isDirectory()) await traverse(fullPath);
106
+ else if (entry.isFile()) {
107
+ if (!extensions || extensions.some((ext) => entry.name.endsWith(ext))) files.push(fullPath);
108
+ }
109
+ }
110
+ }
111
+ await traverse(dirPath);
112
+ return files;
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/fs/readJson.ts
117
+ /**
118
+ * 读取 JSON 文件
119
+ * @param filePath - 文件路径
120
+ * @returns 解析后的 JSON 数据
121
+ * @example
122
+ * ```ts
123
+ * const data = await readJson('./config.json')
124
+ * ```
125
+ * @public
126
+ */
127
+ async function readJson(filePath) {
128
+ const content = await promises.readFile(filePath, "utf-8");
129
+ return JSON.parse(content);
130
+ }
131
+
132
+ //#endregion
133
+ //#region src/fs/readFileOrDefault.ts
134
+ /**
135
+ * 如果文件存在则读取,否则返回默认值
136
+ * @param filePath - 文件路径
137
+ * @param defaultValue - 默认值
138
+ * @returns 文件内容或默认值
139
+ * @example
140
+ * ```ts
141
+ * const config = await readFileOrDefault('./config.json', { theme: 'light' })
142
+ * ```
143
+ * @public
144
+ */
145
+ async function readFileOrDefault(filePath, defaultValue) {
146
+ if (!await exists(filePath)) return defaultValue;
147
+ return readJson(filePath);
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/fs/remove.ts
152
+ /**
153
+ * 递归删除文件或目录
154
+ * @param filePath - 文件或目录路径
155
+ * @example
156
+ * ```ts
157
+ * await remove('./temp')
158
+ * ```
159
+ * @public
160
+ */
161
+ async function remove(filePath) {
162
+ try {
163
+ if ((await promises.stat(filePath)).isDirectory()) {
164
+ const files = await promises.readdir(filePath);
165
+ await Promise.all(files.map(async (file) => {
166
+ await remove(join(filePath, file));
167
+ }));
168
+ await promises.rmdir(filePath);
169
+ } else await promises.unlink(filePath);
170
+ } catch {}
171
+ }
172
+
173
+ //#endregion
174
+ //#region src/fs/writeJson.ts
175
+ /**
176
+ * 将数据写入 JSON 文件
177
+ * @param filePath - 文件路径
178
+ * @param data - 要写入的数据
179
+ * @example
180
+ * ```ts
181
+ * await writeJson('./config.json', { name: 'test' })
182
+ * ```
183
+ * @public
184
+ */
185
+ async function writeJson(filePath, data) {
186
+ const content = JSON.stringify(data, null, 2);
187
+ await promises.writeFile(filePath, content, "utf-8");
188
+ }
189
+
190
+ //#endregion
191
+ //#region src/env/getEnv.ts
192
+ /**
193
+ * 获取环境变量
194
+ * @param key - 环境变量键
195
+ * @param defaultValue - 默认值
196
+ * @returns 环境变量值
197
+ * @example
198
+ * ```ts
199
+ * const value = getEnv('API_URL', 'http://localhost:3000')
200
+ * ```
201
+ * @public
202
+ */
203
+ function getEnv(key, defaultValue) {
204
+ return process.env[key] || defaultValue || "";
205
+ }
206
+
207
+ //#endregion
208
+ //#region src/env/getEnvBool.ts
209
+ /**
210
+ * 获取布尔类型的环境变量
211
+ * @param key - 环境变量键
212
+ * @param defaultValue - 默认值(默认: false)
213
+ * @returns 布尔值
214
+ * @example
215
+ * ```ts
216
+ * const enabled = getEnvBool('DEBUG', false)
217
+ * // DEBUG=true 或 DEBUG=1 返回 true
218
+ * // DEBUG=false 或 DEBUG=0 返回 false
219
+ * ```
220
+ * @public
221
+ */
222
+ function getEnvBool(key, defaultValue = false) {
223
+ var _process$env$key;
224
+ const value = (_process$env$key = process.env[key]) === null || _process$env$key === void 0 ? void 0 : _process$env$key.toLowerCase();
225
+ if (value === "true" || value === "1") return true;
226
+ if (value === "false" || value === "0") return false;
227
+ return defaultValue;
228
+ }
229
+
230
+ //#endregion
231
+ //#region src/env/getEnvMode.ts
232
+ /**
233
+ * 获取当前环境模式(development、production、test)
234
+ * @returns 环境模式
235
+ * @example
236
+ * ```ts
237
+ * const mode = getEnvMode()
238
+ * console.log(mode) // 'development' | 'production' | 'test'
239
+ * ```
240
+ * @public
241
+ */
242
+ function getEnvMode() {
243
+ return process.env.NODE_ENV || "development";
244
+ }
245
+
246
+ //#endregion
247
+ //#region src/env/getEnvNumber.ts
248
+ /**
249
+ * 获取数字类型的环境变量
250
+ * @param key - 环境变量键
251
+ * @param defaultValue - 默认值(默认: 0)
252
+ * @returns 数字值
253
+ * @example
254
+ * ```ts
255
+ * const port = getEnvNumber('PORT', 3000)
256
+ * ```
257
+ * @public
258
+ */
259
+ function getEnvNumber(key, defaultValue = 0) {
260
+ const value = process.env[key];
261
+ const parsed = value ? parseInt(value, 10) : NaN;
262
+ return isNaN(parsed) ? defaultValue : parsed;
263
+ }
264
+
265
+ //#endregion
266
+ //#region src/env/hasEnv.ts
267
+ /**
268
+ * 检查环境变量是否已设置
269
+ * @param key - 环境变量键
270
+ * @returns 是否已设置
271
+ * @example
272
+ * ```ts
273
+ * if (hasEnv('API_KEY')) {
274
+ * console.log('API_KEY is set')
275
+ * }
276
+ * ```
277
+ * @public
278
+ */
279
+ function hasEnv(key) {
280
+ return typeof process.env[key] !== "undefined";
281
+ }
282
+
283
+ //#endregion
284
+ //#region src/env/isDevelopment.ts
285
+ /**
286
+ * 检查当前环境是否为开发环境
287
+ * @returns 是否为开发环境
288
+ * @example
289
+ * ```ts
290
+ * if (isDevelopment()) {
291
+ * console.log('Running in development mode')
292
+ * }
293
+ * ```
294
+ * @public
295
+ */
296
+ function isDevelopment() {
297
+ return getEnvMode() === "development";
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/env/isProduction.ts
302
+ /**
303
+ * 检查当前环境是否为生产环境
304
+ * @returns 是否为生产环境
305
+ * @example
306
+ * ```ts
307
+ * if (isProduction()) {
308
+ * console.log('Running in production mode')
309
+ * }
310
+ * ```
311
+ * @public
312
+ */
313
+ function isProduction() {
314
+ return getEnvMode() === "production";
315
+ }
316
+
317
+ //#endregion
318
+ //#region src/process/exit.ts
319
+ /**
320
+ * 退出当前进程
321
+ * @param code - 退出码(默认: 0)
322
+ * @returns never
323
+ * @example
324
+ * ```ts
325
+ * exit(0) // 正常退出
326
+ * exit(1) // 异常退出
327
+ * ```
328
+ * @public
329
+ */
330
+ function exit(code = 0) {
331
+ process.exit(code);
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/process/getCwd.ts
336
+ /**
337
+ * 获取当前工作目录
338
+ * @returns 当前工作目录路径
339
+ * @example
340
+ * ```ts
341
+ * const cwd = getCwd()
342
+ * console.log(cwd) // '/path/to/current/directory'
343
+ * ```
344
+ * @public
345
+ */
346
+ function getCwd() {
347
+ return process.cwd();
348
+ }
349
+
350
+ //#endregion
351
+ //#region src/process/getMemoryUsage.ts
352
+ /**
353
+ * 获取内存使用信息
354
+ * @returns 内存使用信息对象
355
+ * @example
356
+ * ```ts
357
+ * const usage = getMemoryUsage()
358
+ * console.log(usage)
359
+ * // {
360
+ * // rss: 12345678,
361
+ * // heapTotal: 8765432,
362
+ * // heapUsed: 4321098,
363
+ * // external: 123456,
364
+ * // arrayBuffers: 12345
365
+ * // }
366
+ * ```
367
+ * @public
368
+ */
369
+ function getMemoryUsage() {
370
+ return process.memoryUsage();
371
+ }
372
+
373
+ //#endregion
374
+ //#region src/process/getNodeVersion.ts
375
+ /**
376
+ * 获取 Node.js 版本
377
+ * @returns Node.js 版本字符串
378
+ * @example
379
+ * ```ts
380
+ * const version = getNodeVersion()
381
+ * console.log(version) // 'v18.0.0'
382
+ * ```
383
+ * @public
384
+ */
385
+ function getNodeVersion() {
386
+ return process.version;
387
+ }
388
+
389
+ //#endregion
390
+ //#region src/process/getPid.ts
391
+ /**
392
+ * 获取进程 ID
393
+ * @returns 进程 ID
394
+ * @example
395
+ * ```ts
396
+ * const pid = getPid()
397
+ * console.log(pid) // 12345
398
+ * ```
399
+ * @public
400
+ */
401
+ function getPid() {
402
+ return process.pid;
403
+ }
404
+
405
+ //#endregion
406
+ //#region src/process/getPlatform.ts
407
+ /**
408
+ * 获取当前平台
409
+ * @returns 平台名称(win32、darwin、linux 等)
410
+ * @example
411
+ * ```ts
412
+ * const platform = getPlatform()
413
+ * console.log(platform) // 'win32' | 'darwin' | 'linux'
414
+ * ```
415
+ * @public
416
+ */
417
+ function getPlatform() {
418
+ return process.platform;
419
+ }
420
+
421
+ //#endregion
422
+ //#region src/process/getUptime.ts
423
+ /**
424
+ * 获取进程运行时间(秒)
425
+ * @returns 运行时间(秒)
426
+ * @example
427
+ * ```ts
428
+ * const uptime = getUptime()
429
+ * console.log(uptime) // 3600
430
+ * ```
431
+ * @public
432
+ */
433
+ function getUptime() {
434
+ return process.uptime();
435
+ }
436
+
437
+ //#endregion
438
+ //#region src/process/isLinux.ts
439
+ /**
440
+ * 检查当前平台是否为 Linux
441
+ * @returns 是否为 Linux
442
+ * @example
443
+ * ```ts
444
+ * if (isLinux()) {
445
+ * console.log('Running on Linux')
446
+ * }
447
+ * ```
448
+ * @public
449
+ */
450
+ function isLinux() {
451
+ return process.platform === "linux";
452
+ }
453
+
454
+ //#endregion
455
+ //#region src/process/isMac.ts
456
+ /**
457
+ * 检查当前平台是否为 macOS
458
+ * @returns 是否为 macOS
459
+ * @example
460
+ * ```ts
461
+ * if (isMac()) {
462
+ * console.log('Running on macOS')
463
+ * }
464
+ * ```
465
+ * @public
466
+ */
467
+ function isMac() {
468
+ return process.platform === "darwin";
469
+ }
470
+
471
+ //#endregion
472
+ //#region src/process/isWindows.ts
473
+ /**
474
+ * 检查当前平台是否为 Windows
475
+ * @returns 是否为 Windows
476
+ * @example
477
+ * ```ts
478
+ * if (isWindows()) {
479
+ * console.log('Running on Windows')
480
+ * }
481
+ * ```
482
+ * @public
483
+ */
484
+ function isWindows() {
485
+ return process.platform === "win32";
486
+ }
487
+
488
+ //#endregion
489
+ export { copy, ensureDir, exists, exit, getCwd, getDirname, getEnv, getEnvBool, getEnvMode, getEnvNumber, getFiles, getMemoryUsage, getNodeVersion, getPid, getPlatform, getUptime, hasEnv, isDevelopment, isLinux, isMac, isProduction, isWindows, readFileOrDefault, readJson, remove, writeJson };
490
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["fs","fs","fs","fs","fs","fs","fs"],"sources":["../src/fs/ensureDir.ts","../src/fs/copy.ts","../src/fs/exists.ts","../src/fs/getDirname.ts","../src/fs/getFiles.ts","../src/fs/readJson.ts","../src/fs/readFileOrDefault.ts","../src/fs/remove.ts","../src/fs/writeJson.ts","../src/env/getEnv.ts","../src/env/getEnvBool.ts","../src/env/getEnvMode.ts","../src/env/getEnvNumber.ts","../src/env/hasEnv.ts","../src/env/isDevelopment.ts","../src/env/isProduction.ts","../src/process/exit.ts","../src/process/getCwd.ts","../src/process/getMemoryUsage.ts","../src/process/getNodeVersion.ts","../src/process/getPid.ts","../src/process/getPlatform.ts","../src/process/getUptime.ts","../src/process/isLinux.ts","../src/process/isMac.ts","../src/process/isWindows.ts"],"sourcesContent":["import { promises as fs } from 'fs'\n\n/**\n * 确保目录存在,如果不存在则创建\n * @param dirPath - 目录路径\n * @example\n * ```ts\n * await ensureDir('./dist')\n * ```\n * @public\n */\nexport async function ensureDir(dirPath: string): Promise<void> {\n try {\n await fs.access(dirPath)\n } catch {\n await fs.mkdir(dirPath, { recursive: true })\n }\n}\n","import { promises as fs } from 'fs'\nimport { join, dirname } from 'path'\nimport { ensureDir } from './ensureDir'\n\n/**\n * 递归复制文件或目录\n * @param src - 源路径\n * @param dest - 目标路径\n * @example\n * ```ts\n * await copy('./src', './dist')\n * ```\n * @public\n */\nexport async function copy(src: string, dest: string): Promise<void> {\n const stat = await fs.stat(src)\n\n if (stat.isDirectory()) {\n await ensureDir(dest)\n const files = await fs.readdir(src)\n await Promise.all(\n files.map(async (file) => {\n const srcPath = join(src, file)\n const destPath = join(dest, file)\n await copy(srcPath, destPath)\n })\n )\n } else {\n await fs.mkdir(dirname(dest), { recursive: true })\n await fs.copyFile(src, dest)\n }\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 检查文件或目录是否存在\n * @param filePath - 文件或目录路径\n * @returns 是否存在\n * @example\n * ```ts\n * const isExist = await exists('./config.json')\n * ```\n * @public\n */\nexport async function exists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath)\n return true\n } catch {\n return false\n }\n}\n","import { dirname } from 'path'\nimport { fileURLToPath } from 'url'\n\n/**\n * 获取当前模块的目录名\n * @param url - 模块的 URL\n * @returns 目录名\n * @example\n * ```ts\n * const __dirname = getDirname(import.meta.url)\n * ```\n * @public\n */\nexport function getDirname(url: string): string {\n return dirname(fileURLToPath(url))\n}\n","import { promises as fs } from 'fs'\nimport { join } from 'path'\n\n/**\n * 递归获取目录下的所有文件\n * @param dirPath - 目录路径\n * @param extensions - 可选的文件扩展名过滤器\n * @returns 文件路径数组\n * @example\n * ```ts\n * const allFiles = await getFiles('./src')\n * const tsFiles = await getFiles('./src', ['.ts', '.tsx'])\n * ```\n * @public\n */\nexport async function getFiles(\n dirPath: string,\n extensions?: string[]\n): Promise<string[]> {\n const files: string[] = []\n\n async function traverse(currentPath: string) {\n const entries = await fs.readdir(currentPath, { withFileTypes: true })\n\n for (const entry of entries) {\n const fullPath = join(currentPath, entry.name)\n\n if (entry.isDirectory()) {\n await traverse(fullPath)\n } else if (entry.isFile()) {\n if (!extensions || extensions.some((ext) => entry.name.endsWith(ext))) {\n files.push(fullPath)\n }\n }\n }\n }\n\n await traverse(dirPath)\n return files\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 读取 JSON 文件\n * @param filePath - 文件路径\n * @returns 解析后的 JSON 数据\n * @example\n * ```ts\n * const data = await readJson('./config.json')\n * ```\n * @public\n */\nexport async function readJson<T = any>(filePath: string): Promise<T> {\n const content = await fs.readFile(filePath, 'utf-8')\n return JSON.parse(content)\n}\n","import { exists } from './exists'\nimport { readJson } from './readJson'\n\n/**\n * 如果文件存在则读取,否则返回默认值\n * @param filePath - 文件路径\n * @param defaultValue - 默认值\n * @returns 文件内容或默认值\n * @example\n * ```ts\n * const config = await readFileOrDefault('./config.json', { theme: 'light' })\n * ```\n * @public\n */\nexport async function readFileOrDefault<T>(\n filePath: string,\n defaultValue: T\n): Promise<T> {\n const isExist = await exists(filePath)\n if (!isExist) {\n return defaultValue\n }\n return readJson<T>(filePath)\n}\n","import { promises as fs } from 'fs'\nimport { join } from 'path'\n\n/**\n * 递归删除文件或目录\n * @param filePath - 文件或目录路径\n * @example\n * ```ts\n * await remove('./temp')\n * ```\n * @public\n */\nexport async function remove(filePath: string): Promise<void> {\n try {\n const stat = await fs.stat(filePath)\n if (stat.isDirectory()) {\n const files = await fs.readdir(filePath)\n await Promise.all(\n files.map(async (file) => {\n const fullPath = join(filePath, file)\n await remove(fullPath)\n })\n )\n await fs.rmdir(filePath)\n } else {\n await fs.unlink(filePath)\n }\n } catch {\n // File doesn't exist, ignore\n }\n}\n","import { promises as fs } from 'fs'\n\n/**\n * 将数据写入 JSON 文件\n * @param filePath - 文件路径\n * @param data - 要写入的数据\n * @example\n * ```ts\n * await writeJson('./config.json', { name: 'test' })\n * ```\n * @public\n */\nexport async function writeJson(filePath: string, data: any): Promise<void> {\n const content = JSON.stringify(data, null, 2)\n await fs.writeFile(filePath, content, 'utf-8')\n}\n","/**\n * 获取环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值\n * @returns 环境变量值\n * @example\n * ```ts\n * const value = getEnv('API_URL', 'http://localhost:3000')\n * ```\n * @public\n */\nexport function getEnv(key: string, defaultValue?: string): string {\n return process.env[key] || defaultValue || ''\n}\n","/**\n * 获取布尔类型的环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值(默认: false)\n * @returns 布尔值\n * @example\n * ```ts\n * const enabled = getEnvBool('DEBUG', false)\n * // DEBUG=true 或 DEBUG=1 返回 true\n * // DEBUG=false 或 DEBUG=0 返回 false\n * ```\n * @public\n */\nexport function getEnvBool(key: string, defaultValue: boolean = false): boolean {\n const value = process.env[key]?.toLowerCase()\n if (value === 'true' || value === '1') return true\n if (value === 'false' || value === '0') return false\n return defaultValue\n}\n","/**\n * 获取当前环境模式(development、production、test)\n * @returns 环境模式\n * @example\n * ```ts\n * const mode = getEnvMode()\n * console.log(mode) // 'development' | 'production' | 'test'\n * ```\n * @public\n */\nexport function getEnvMode(): string {\n return process.env.NODE_ENV || 'development'\n}\n","/**\n * 获取数字类型的环境变量\n * @param key - 环境变量键\n * @param defaultValue - 默认值(默认: 0)\n * @returns 数字值\n * @example\n * ```ts\n * const port = getEnvNumber('PORT', 3000)\n * ```\n * @public\n */\nexport function getEnvNumber(key: string, defaultValue: number = 0): number {\n const value = process.env[key]\n const parsed = value ? parseInt(value, 10) : NaN\n return isNaN(parsed) ? defaultValue : parsed\n}\n","/**\n * 检查环境变量是否已设置\n * @param key - 环境变量键\n * @returns 是否已设置\n * @example\n * ```ts\n * if (hasEnv('API_KEY')) {\n * console.log('API_KEY is set')\n * }\n * ```\n * @public\n */\nexport function hasEnv(key: string): boolean {\n return typeof process.env[key] !== 'undefined'\n}\n","import { getEnvMode } from './getEnvMode'\n\n/**\n * 检查当前环境是否为开发环境\n * @returns 是否为开发环境\n * @example\n * ```ts\n * if (isDevelopment()) {\n * console.log('Running in development mode')\n * }\n * ```\n * @public\n */\nexport function isDevelopment(): boolean {\n return getEnvMode() === 'development'\n}\n","import { getEnvMode } from './getEnvMode'\n\n/**\n * 检查当前环境是否为生产环境\n * @returns 是否为生产环境\n * @example\n * ```ts\n * if (isProduction()) {\n * console.log('Running in production mode')\n * }\n * ```\n * @public\n */\nexport function isProduction(): boolean {\n return getEnvMode() === 'production'\n}\n","/**\n * 退出当前进程\n * @param code - 退出码(默认: 0)\n * @returns never\n * @example\n * ```ts\n * exit(0) // 正常退出\n * exit(1) // 异常退出\n * ```\n * @public\n */\nexport function exit(code: number = 0): never {\n process.exit(code)\n}\n","/**\n * 获取当前工作目录\n * @returns 当前工作目录路径\n * @example\n * ```ts\n * const cwd = getCwd()\n * console.log(cwd) // '/path/to/current/directory'\n * ```\n * @public\n */\nexport function getCwd(): string {\n return process.cwd()\n}\n","/**\n * 获取内存使用信息\n * @returns 内存使用信息对象\n * @example\n * ```ts\n * const usage = getMemoryUsage()\n * console.log(usage)\n * // {\n * // rss: 12345678,\n * // heapTotal: 8765432,\n * // heapUsed: 4321098,\n * // external: 123456,\n * // arrayBuffers: 12345\n * // }\n * ```\n * @public\n */\nexport function getMemoryUsage(): NodeJS.MemoryUsage {\n return process.memoryUsage()\n}\n","/**\n * 获取 Node.js 版本\n * @returns Node.js 版本字符串\n * @example\n * ```ts\n * const version = getNodeVersion()\n * console.log(version) // 'v18.0.0'\n * ```\n * @public\n */\nexport function getNodeVersion(): string {\n return process.version\n}\n","/**\n * 获取进程 ID\n * @returns 进程 ID\n * @example\n * ```ts\n * const pid = getPid()\n * console.log(pid) // 12345\n * ```\n * @public\n */\nexport function getPid(): number {\n return process.pid\n}\n","/**\n * 获取当前平台\n * @returns 平台名称(win32、darwin、linux 等)\n * @example\n * ```ts\n * const platform = getPlatform()\n * console.log(platform) // 'win32' | 'darwin' | 'linux'\n * ```\n * @public\n */\nexport function getPlatform(): NodeJS.Platform {\n return process.platform\n}\n","/**\n * 获取进程运行时间(秒)\n * @returns 运行时间(秒)\n * @example\n * ```ts\n * const uptime = getUptime()\n * console.log(uptime) // 3600\n * ```\n * @public\n */\nexport function getUptime(): number {\n return process.uptime()\n}\n","/**\n * 检查当前平台是否为 Linux\n * @returns 是否为 Linux\n * @example\n * ```ts\n * if (isLinux()) {\n * console.log('Running on Linux')\n * }\n * ```\n * @public\n */\nexport function isLinux(): boolean {\n return process.platform === 'linux'\n}\n","/**\n * 检查当前平台是否为 macOS\n * @returns 是否为 macOS\n * @example\n * ```ts\n * if (isMac()) {\n * console.log('Running on macOS')\n * }\n * ```\n * @public\n */\nexport function isMac(): boolean {\n return process.platform === 'darwin'\n}\n","/**\n * 检查当前平台是否为 Windows\n * @returns 是否为 Windows\n * @example\n * ```ts\n * if (isWindows()) {\n * console.log('Running on Windows')\n * }\n * ```\n * @public\n */\nexport function isWindows(): boolean {\n return process.platform === 'win32'\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,eAAsB,UAAU,SAAgC;AAC9D,KAAI;AACF,QAAMA,SAAG,OAAO,QAAQ;SAClB;AACN,QAAMA,SAAG,MAAM,SAAS,EAAE,WAAW,MAAM,CAAC;;;;;;;;;;;;;;;;ACDhD,eAAsB,KAAK,KAAa,MAA6B;AAGnE,MAFa,MAAMC,SAAG,KAAK,IAAI,EAEtB,aAAa,EAAE;AACtB,QAAM,UAAU,KAAK;EACrB,MAAM,QAAQ,MAAMA,SAAG,QAAQ,IAAI;AACnC,QAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;AAGxB,SAAM,KAFU,KAAK,KAAK,KAAK,EACd,KAAK,MAAM,KAAK,CACJ;IAC7B,CACH;QACI;AACL,QAAMA,SAAG,MAAM,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAClD,QAAMA,SAAG,SAAS,KAAK,KAAK;;;;;;;;;;;;;;;;ACjBhC,eAAsB,OAAO,UAAoC;AAC/D,KAAI;AACF,QAAMC,SAAG,OAAO,SAAS;AACzB,SAAO;SACD;AACN,SAAO;;;;;;;;;;;;;;;;ACJX,SAAgB,WAAW,KAAqB;AAC9C,QAAO,QAAQ,cAAc,IAAI,CAAC;;;;;;;;;;;;;;;;;ACCpC,eAAsB,SACpB,SACA,YACmB;CACnB,MAAM,QAAkB,EAAE;CAE1B,eAAe,SAAS,aAAqB;EAC3C,MAAM,UAAU,MAAMC,SAAG,QAAQ,aAAa,EAAE,eAAe,MAAM,CA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
+ "name": "@longmo-utils/node",
3
+ "version": "1.0.0",
4
+ "description": "Node.js-specific utility functions with file system dependencies",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "engines": {
18
+ "node": ">=16"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "keywords": [
24
+ "utils",
25
+ "typescript",
26
+ "nodejs",
27
+ "filesystem"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "tsdown",
36
+ "dev": "tsdown --watch",
37
+ "clean": "rm -rf dist"
38
+ }
39
+ }