vvvfs 0.1.5 → 0.1.7

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 (4) hide show
  1. package/README.md +224 -34
  2. package/index.ts +217 -0
  3. package/package.json +33 -33
  4. package/types/index.d.ts +111 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  一个使用Dexie.js,基于IndexedDB的轻量、简单的浏览器中的Linux虚拟文件系统
4
4
 
5
+ GitHub仓库: https://github.com/IFTC-XLKJ/vvvfs
6
+
5
7
  ## 快速开始
6
8
 
7
9
  1. 安装依赖
@@ -31,7 +33,8 @@ const VVVFS = require("vvvfs"); // CommonJS
31
33
 
32
34
  ```javascript
33
35
  const vvvfs = new VVVFS("vvvfs", {
34
- throwError: true, // 设置为true后,操作文件失败时,不会返回false,而是会抛出错误
36
+ throwError: true, // 设置为true后,操作文件失败时,不会返回false,而是会抛出错误
37
+ init: "IFTC", // 自动初始化,用户名为 IFTC
35
38
  }); // 创建一个名为vvvfs的虚拟文件系统
36
39
  ```
37
40
 
@@ -40,34 +43,40 @@ const vvvfs = new VVVFS("vvvfs", {
40
43
  ```javascript
41
44
  // 所有操作都是异步的
42
45
  (async function () {
43
- await vvvfs.reset(); // 重置文件系统
44
- await vvvfs.init("UserName"); // 初始化文件系统
45
- vvvfs.watch("/home/user/Desktop/test.txt", (type) => {
46
- console.log(type); // 打印文件操作的类型
47
- return true; // 返回true或false,表示是否取消该操作
48
- });
49
- await vvvfs.lock("/home/user/Desktop/test.txt"); // 锁定文件,防止其他代码访问该文件
50
- await vvvfs.unlock("/home/user/Desktop/test.txt"); // 解锁文件
51
- await vvvfs.createDir("/home/user/Desktop"); // 创建目录,返回true和false
52
- await vvvfs.writeText("/home/user/Desktop/test.txt", "Hello World!"); // 写入文本文件,写入文件还包括write(path: string, content: Blob)和writeJson(path: string, content: Record<string, any>)方法,返回true和false
53
- await vvvfs.appendText("/home/user/Desktop/test.txt", "Hello World!"); // 追加文本文件,返回true和false
54
- console.log(await vvvfs.readText("/home/user/Desktop/test.txt")); // 读取文本文件,读取文件还包括read(path: string): Blob | null和readJson(path: string): Record<string, any> | null方法
55
- console.log(await vvvfs.readChunkText("/home/user/Desktop/test.txt", 0, 5)); // 读取文件块,返回string | null
56
- await vvvfs.delete("/home/user/Desktop/test.txt"); // 删除文件,返回true和false
57
- if (await vvvfs.exists("/home/user/Desktop")) {
58
- // 判断文件或目录是否存在
59
- }
60
- console.log(await vvvfs.list("/home/user/Desktop")); // 列出目录下的文件,返回string[] | null
61
- if (await vvvfs.isDir("/home/user/Desktop")) {
62
- // 判断是否为目录
63
- }
64
- if (await vvvfs.isFile("/home/user/Desktop/test.txt")) {
65
- // 判断是否为文件
66
- }
67
- await vvvfs.rename("/home/user/Desktop/test.txt", "test2.txt"); // 重命名文件,返回true和false
68
- await vvvfs.move("/home/user/Desktop/test2.txt", "/home/user/Desktop/test.txt"); // 移动文件,返回true和false
69
- await vvvfs.copy("/home/user/Desktop/test.txt", "/home/user/Desktop/test2.txt"); // 复制文件,返回true和false
70
- await vvvfs.search("/home/user/Desktop", "test.txt"); // 搜索文件,返回string[] | null
46
+ await vvvfs.reset(); // 重置文件系统
47
+ await vvvfs.init("UserName"); // 初始化文件系统
48
+ vvvfs.watch("/home/user/Desktop/test.txt", (type) => {
49
+ console.log(type); // 打印文件操作的类型
50
+ return true; // 返回true或false,表示是否取消该操作
51
+ });
52
+ await vvvfs.lock("/home/user/Desktop/test.txt"); // 锁定文件,防止其他代码访问该文件
53
+ await vvvfs.unlock("/home/user/Desktop/test.txt"); // 解锁文件
54
+ await vvvfs.createDir("/home/user/Desktop"); // 创建目录,返回true和false
55
+ await vvvfs.writeText("/home/user/Desktop/test.txt", "Hello World!"); // 写入文本文件,写入文件还包括write(path: string, content: Blob)和writeJson(path: string, content: Record<string, any>)方法,返回true和false
56
+ await vvvfs.appendText("/home/user/Desktop/test.txt", "Hello World!"); // 追加文本文件,返回true和false
57
+ console.log(await vvvfs.readText("/home/user/Desktop/test.txt")); // 读取文本文件,读取文件还包括read(path: string): Blob | null和readJson(path: string): Record<string, any> | null方法
58
+ console.log(await vvvfs.readChunkText("/home/user/Desktop/test.txt", 0, 5)); // 读取文件块,返回string | null
59
+ await vvvfs.delete("/home/user/Desktop/test.txt"); // 删除文件,返回true和false
60
+ if (await vvvfs.exists("/home/user/Desktop")) {
61
+ // 判断文件或目录是否存在
62
+ }
63
+ console.log(await vvvfs.list("/home/user/Desktop")); // 列出目录下的文件,返回string[] | null
64
+ if (await vvvfs.isDir("/home/user/Desktop")) {
65
+ // 判断是否为目录
66
+ }
67
+ if (await vvvfs.isFile("/home/user/Desktop/test.txt")) {
68
+ // 判断是否为文件
69
+ }
70
+ await vvvfs.rename("/home/user/Desktop/test.txt", "test2.txt"); // 重命名文件,返回true和false
71
+ await vvvfs.move(
72
+ "/home/user/Desktop/test2.txt",
73
+ "/home/user/Desktop/test.txt",
74
+ ); // 移动文件,返回true和false
75
+ await vvvfs.copy(
76
+ "/home/user/Desktop/test.txt",
77
+ "/home/user/Desktop/test2.txt",
78
+ ); // 复制文件,返回true和false
79
+ await vvvfs.search("/home/user/Desktop", "test.txt"); // 搜索文件,返回string[] | null
71
80
  })();
72
81
  ```
73
82
 
@@ -75,17 +84,25 @@ const vvvfs = new VVVFS("vvvfs", {
75
84
 
76
85
  ```javascript
77
86
  (async function () {
78
- const file = new VVVFS.File("/home/user/Desktop/test.txt");
79
- // file.options.throwError = true;
80
- await file.writeText("Hello World!");
81
- console.log(await file.readText());
82
- await file.delete();
87
+ const file = new VVVFS.File("/home/user/Desktop/test.txt");
88
+ // file.options.throwError = true;
89
+ await file.writeText("Hello World!");
90
+ console.log(await file.readText());
91
+ await file.delete();
83
92
  })();
84
93
  // 用法与 vvvfs 相当
85
94
  ```
86
95
 
87
96
  ## 更新日志
88
97
 
98
+ ### 0.1.7
99
+
100
+ - 新增 `init` 选项,用于是否自动初始化,传入字符串时,则为初始化的用户名,传入true时,则为默认用户名。
101
+
102
+ ### 0.1.6
103
+
104
+ - 新增 `VVVFS.path` ,用法与 NodeJS 的 `path` 模块类似。
105
+
89
106
  ### 0.1.5
90
107
 
91
108
  - 重新 `lock` 和 `unlock` 方法
@@ -149,3 +166,176 @@ const vvvfs = new VVVFS("vvvfs", {
149
166
  ### 0.0.1
150
167
 
151
168
  - 发布正式版
169
+
170
+ ---
171
+
172
+ # English
173
+
174
+ # VVVFS
175
+
176
+ A lightweight and simple Linux virtual file system in the browser, based on IndexedDB, built with Dexie.js
177
+
178
+ GitHub repository: https://github.com/IFTC-XLKJ/vvvfs
179
+
180
+ ## Quick Start
181
+
182
+ 1. Install the dependency
183
+
184
+ ```bash
185
+ npm install vvvfs
186
+ ```
187
+
188
+ 2. Import
189
+
190
+ ```javascript
191
+ import VVVFS from "vvvfs"; // ES6
192
+ ```
193
+
194
+ ```javascript
195
+ const VVVFS = require("vvvfs"); // CommonJS
196
+ ```
197
+
198
+ ```html
199
+ <script src="dist/vvvfs.min.js"></script>
200
+ <script src="https://cdn.jsdelivr.net/npm/vvvfs@latest/dist/vvvfs.min.js"></script>
201
+ <script src="https://unpkg.com/vvvfs@latest/dist/vvvfs.min.js"></script>
202
+ <!-- Browser -->
203
+ ```
204
+
205
+ 3. Initialize
206
+
207
+ ```javascript
208
+ const vvvfs = new VVVFS("vvvfs", {
209
+ throwError: true, // When set to true, failed file operations throw an error instead of returning false
210
+ init: "IFTC", // Automatically initialize with the username IFTC
211
+ }); // Create a virtual file system named vvvfs
212
+ ```
213
+
214
+ 4. Usage
215
+
216
+ ```javascript
217
+ // All operations are asynchronous
218
+ (async function () {
219
+ await vvvfs.reset(); // Reset the file system
220
+ await vvvfs.init("UserName"); // Initialize the file system
221
+ vvvfs.watch("/home/user/Desktop/test.txt", (type) => {
222
+ console.log(type); // Log the type of the file operation
223
+ return true; // Return true or false to indicate whether to cancel the operation
224
+ });
225
+ await vvvfs.lock("/home/user/Desktop/test.txt"); // Lock the file to prevent other code from accessing it
226
+ await vvvfs.unlock("/home/user/Desktop/test.txt"); // Unlock the file
227
+ await vvvfs.createDir("/home/user/Desktop"); // Create a directory, returns true and false
228
+ await vvvfs.writeText("/home/user/Desktop/test.txt", "Hello World!"); // Write a text file. Writing also includes write(path: string, content: Blob) and writeJson(path: string, content: Record<string, any>), returns true and false
229
+ await vvvfs.appendText("/home/user/Desktop/test.txt", "Hello World!"); // Append text to a file, returns true and false
230
+ console.log(await vvvfs.readText("/home/user/Desktop/test.txt")); // Read a text file. Reading also includes read(path: string): Blob | null and readJson(path: string): Record<string, any> | null
231
+ console.log(await vvvfs.readChunkText("/home/user/Desktop/test.txt", 0, 5)); // Read a file chunk, returns string | null
232
+ await vvvfs.delete("/home/user/Desktop/test.txt"); // Delete a file, returns true and false
233
+ if (await vvvfs.exists("/home/user/Desktop")) {
234
+ // Check whether a file or directory exists
235
+ }
236
+ console.log(await vvvfs.list("/home/user/Desktop")); // List the files in a directory, returns string[] | null
237
+ if (await vvvfs.isDir("/home/user/Desktop")) {
238
+ // Check whether it is a directory
239
+ }
240
+ if (await vvvfs.isFile("/home/user/Desktop/test.txt")) {
241
+ // Check whether it is a file
242
+ }
243
+ await vvvfs.rename("/home/user/Desktop/test.txt", "test2.txt"); // Rename a file, returns true and false
244
+ await vvvfs.move(
245
+ "/home/user/Desktop/test2.txt",
246
+ "/home/user/Desktop/test.txt",
247
+ ); // Move a file, returns true and false
248
+ await vvvfs.copy(
249
+ "/home/user/Desktop/test.txt",
250
+ "/home/user/Desktop/test2.txt",
251
+ ); // Copy a file, returns true and false
252
+ await vvvfs.search("/home/user/Desktop", "test.txt"); // Search for files, returns string[] | null
253
+ })();
254
+ ```
255
+
256
+ Using the `VVVFS.File` class:
257
+
258
+ ```javascript
259
+ (async function () {
260
+ const file = new VVVFS.File("/home/user/Desktop/test.txt");
261
+ // file.options.throwError = true;
262
+ await file.writeText("Hello World!");
263
+ console.log(await file.readText());
264
+ await file.delete();
265
+ })();
266
+ // The usage is equivalent to vvvfs
267
+ ```
268
+
269
+ ## Changelog
270
+
271
+ ### 0.1.7
272
+
273
+ - Added the `init` option to control automatic initialization: when passed a string, it is used as the username for initialization; when passed `true`, the default username is used.
274
+
275
+ ### 0.1.6
276
+
277
+ - Added `VVVFS.path`, which works in a similar way to the `path` module in NodeJS.
278
+
279
+ ### 0.1.5
280
+
281
+ - Redesigned the `lock` and `unlock` methods
282
+
283
+ ### 0.1.4
284
+
285
+ - Optimized the code with AI
286
+
287
+ ### 0.1.3
288
+
289
+ - Added the `lock` and `unlock` methods, which can lock files to prevent other code from accessing them
290
+
291
+ ### 0.1.2
292
+
293
+ - Added the `readChunk` and `readChunkText` methods for reading file chunks
294
+
295
+ ### 0.1.1
296
+
297
+ - Added the `append` and `appendText` methods for appending content
298
+
299
+ ### 0.1.0
300
+
301
+ - Fixed `init` rewriting existing files and directories when initialized repeatedly
302
+
303
+ ### 0.0.9
304
+
305
+ - Updated the `watch` method: while watching, returning `true` cancels the operation
306
+
307
+ ### 0.0.8
308
+
309
+ - Added the `watch` method (this is an experimental feature and may change in the future)
310
+
311
+ ### 0.0.7
312
+
313
+ - Optimized a bit with AI
314
+
315
+ ### 0.0.6
316
+
317
+ - Added the `dbname` and `options` properties to the `VVVFS.File` class
318
+ - Added the `defaultDBName` property to `VVVFS`
319
+
320
+ ### 0.0.5
321
+
322
+ - Added the `VVVFS.File` class
323
+
324
+ ### 0.0.4
325
+
326
+ - Fixed IndexedDB spamming a bunch of warnings
327
+ - Fixed a bug in `search`
328
+
329
+ ### 0.0.3
330
+
331
+ - Added maximum length limits: 4096 characters for full paths and 255 characters for file names
332
+ - Added the `init` method for initializing Linux files and directories
333
+ - Fixed a bug where `list` returned an empty string (the root directory itself) in the array when listing the root directory
334
+
335
+ ### 0.0.2
336
+
337
+ - Added the `throwError` option, which defaults to `false`
338
+
339
+ ### 0.0.1
340
+
341
+ - Initial release
package/index.ts CHANGED
@@ -37,9 +37,11 @@ export interface VVVFSDatabase extends Dexie {
37
37
  /**
38
38
  * 虚拟文件系统配置项
39
39
  * @param throwError 是否抛出错误
40
+ * @param init 是否自动初始化,传入字符串时,为用户名,传入true时,使用默认用户名
40
41
  */
41
42
  export interface VVVFSOptions {
42
43
  throwError: boolean;
44
+ init: boolean | string;
43
45
  }
44
46
 
45
47
  /**
@@ -274,6 +276,215 @@ class VVVFSFile {
274
276
  }
275
277
  }
276
278
 
279
+ /**
280
+ * path类(类似于NodeJS中的path模块)
281
+ */
282
+ class Path {
283
+ /**
284
+ * 路径分隔符
285
+ */
286
+ static readonly sep = "/";
287
+ /**
288
+ * 环境变量PATH的分隔符
289
+ */
290
+ static readonly delimiter = ":";
291
+ /**
292
+ * 内部存储的路径
293
+ */
294
+ private _path: string;
295
+ /**
296
+ * 构造函数
297
+ * @param paths 路径片段
298
+ */
299
+ constructor(...paths: string[]) {
300
+ this._path = Path.resolve(...paths);
301
+ }
302
+ /**
303
+ * 获取路径
304
+ */
305
+ get path() {
306
+ return this._path;
307
+ }
308
+ /**
309
+ * 设置路径
310
+ * @param path 路径
311
+ */
312
+ set path(path: string) {
313
+ this._path = Path.resolve(path);
314
+ }
315
+ /**
316
+ * 获取文件名
317
+ */
318
+ get name() {
319
+ return Path.basename(this._path);
320
+ }
321
+ /**
322
+ * 获取文件所在目录
323
+ */
324
+ get parent() {
325
+ return Path.dirname(this._path);
326
+ }
327
+ /**
328
+ * 获取文件扩展名
329
+ */
330
+ get ext() {
331
+ return Path.extname(this._path);
332
+ }
333
+ /**
334
+ * 获取根目录("/"或"")
335
+ */
336
+ get root() {
337
+ return Path.parse(this._path).root;
338
+ }
339
+ /**
340
+ * 判断路径是否为绝对路径
341
+ */
342
+ isAbsolute() {
343
+ return Path.isAbsolute(this._path);
344
+ }
345
+ /**
346
+ * 合并路径
347
+ * @param paths 路径片段
348
+ */
349
+ join(...paths: string[]) {
350
+ return Path.join(this._path, ...paths);
351
+ }
352
+ /**
353
+ * 转换为字符串
354
+ */
355
+ toString() {
356
+ return this._path;
357
+ }
358
+ /**
359
+ * 合并路径
360
+ * @param paths 路径片段
361
+ */
362
+ static join(...paths: string[]) {
363
+ return joinPath(...paths);
364
+ }
365
+ /**
366
+ * 解析路径为绝对路径
367
+ * @param paths 路径片段
368
+ */
369
+ static resolve(...paths: string[]) {
370
+ return paths.length === 0 ? "/" : joinPath(...paths);
371
+ }
372
+ /**
373
+ * 规范化路径(清除"."、解析"..")
374
+ * @param path 路径
375
+ */
376
+ static normalize(path: string) {
377
+ if (path.length === 0) return ".";
378
+ const isAbsolute = path.startsWith("/");
379
+ const trailingSlash = path.length > 1 && path.endsWith("/");
380
+ const stack: string[] = [];
381
+ for (const part of path.split("/")) {
382
+ if (part === "" || part === ".") {
383
+ continue;
384
+ } else if (part === "..") {
385
+ if (stack.length > 0 && stack[stack.length - 1] !== "..") {
386
+ stack.pop();
387
+ } else if (!isAbsolute) {
388
+ stack.push("..");
389
+ }
390
+ } else {
391
+ stack.push(part);
392
+ }
393
+ }
394
+ let result = stack.join("/");
395
+ if (isAbsolute) {
396
+ result = "/" + result;
397
+ } else if (result.length === 0) {
398
+ result = ".";
399
+ }
400
+ if (trailingSlash && result !== "/" && result !== "." && !result.endsWith("/")) {
401
+ result += "/";
402
+ }
403
+ return result;
404
+ }
405
+ /**
406
+ * 判断路径是否为绝对路径
407
+ * @param path 路径
408
+ */
409
+ static isAbsolute(path: string) {
410
+ return path.length > 0 && path.startsWith("/");
411
+ }
412
+ /**
413
+ * 获取文件名(可去除后缀)
414
+ * @param path 路径
415
+ * @param suffix 后缀(如扩展名)
416
+ */
417
+ static basename(path: string, suffix?: string) {
418
+ if (path.length === 0) return "";
419
+ const normalized = Path.normalize(path);
420
+ if (normalized === "/") return "/";
421
+ let base = normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
422
+ base = base.slice(base.lastIndexOf("/") + 1);
423
+ if (suffix && base !== suffix && base.endsWith(suffix)) {
424
+ base = base.slice(0, base.length - suffix.length);
425
+ }
426
+ return base;
427
+ }
428
+ /**
429
+ * 获取文件所在目录
430
+ * @param path 路径
431
+ */
432
+ static dirname(path: string) {
433
+ const normalized = Path.normalize(path);
434
+ if (normalized === "/" || normalized === ".") return normalized;
435
+ const parts = normalized.split("/");
436
+ parts.pop();
437
+ const result = parts.join("/");
438
+ if (result.length === 0) {
439
+ return Path.isAbsolute(normalized) ? "/" : ".";
440
+ }
441
+ return result;
442
+ }
443
+ /**
444
+ * 获取文件扩展名
445
+ * @param path 路径
446
+ */
447
+ static extname(path: string) {
448
+ const base = Path.basename(path);
449
+ const lastDot = base.lastIndexOf(".");
450
+ if (lastDot <= 0) return "";
451
+ return base.slice(lastDot);
452
+ }
453
+ /**
454
+ * 解析路径
455
+ * @param path 路径
456
+ */
457
+ static parse(path: string) {
458
+ const base = Path.basename(path);
459
+ const ext = Path.extname(base);
460
+ return {
461
+ root: Path.isAbsolute(path) ? "/" : "",
462
+ dir: Path.dirname(path),
463
+ base,
464
+ ext,
465
+ name: ext.length > 0 ? base.slice(0, base.length - ext.length) : base,
466
+ };
467
+ }
468
+ /**
469
+ * 计算从from到to的相对路径
470
+ * @param from 起始路径
471
+ * @param to 目标路径
472
+ */
473
+ static relative(from: string, to: string) {
474
+ const fromParts = Path.resolve(from).split("/").filter((part) => part.length > 0);
475
+ const toParts = Path.resolve(to).split("/").filter((part) => part.length > 0);
476
+ let i = 0;
477
+ while (i < fromParts.length && i < toParts.length && fromParts[i] === toParts[i]) {
478
+ i++;
479
+ }
480
+ const up = new Array<string>(Math.max(0, fromParts.length - i)).fill("..").join("/");
481
+ const down = toParts.slice(i).join("/");
482
+ if (up.length > 0 && down.length > 0) return up + "/" + down;
483
+ if (up.length > 0) return up;
484
+ return down;
485
+ }
486
+ }
487
+
277
488
  const version = packageJson.version;
278
489
 
279
490
  class VVVFS {
@@ -288,6 +499,10 @@ class VVVFS {
288
499
  * 虚拟文件系统文件类
289
500
  */
290
501
  static File = VVVFSFile;
502
+ /**
503
+ * path类(类似于NodeJS中的path模块)
504
+ */
505
+ static path = Path;
291
506
  /**
292
507
  * 虚拟文件系统监听器
293
508
  */
@@ -369,6 +584,7 @@ class VVVFS {
369
584
  name?: string,
370
585
  options = {
371
586
  throwError: false,
587
+ init: false,
372
588
  },
373
589
  ) {
374
590
  this.options = options;
@@ -386,6 +602,7 @@ class VVVFS {
386
602
  }
387
603
  });
388
604
  });
605
+ this.options.init ? this.init(this.options.init == true ? "root" : this.options.init) : void 0;
389
606
  } catch (error) {
390
607
  console.error("创建数据库失败", error);
391
608
  throw new VVVFSError("CreateDatabase", "创建数据库失败");
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
- {
2
- "name": "vvvfs",
3
- "version": "0.1.5",
4
- "description": "一个使用IndexDB实现的虚拟文件系统",
5
- "keywords": [
6
- "Virtual",
7
- "File",
8
- "System",
9
- "IFTC",
10
- "VV",
11
- "File",
12
- "System",
13
- "vfs",
14
- "fs"
15
- ],
16
- "license": "MIT",
17
- "author": "IFTC",
18
- "type": "module",
19
- "main": "index.js",
20
- "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1",
22
- "build": "node esbuild.config.js"
23
- },
24
- "dependencies": {
25
- "dexie": "^4.3.0",
26
- "esbuild": "^0.27.3",
27
- "mime": "^4.1.0"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "https://github.com/IFTC-XLKJ/vvvfs.git"
32
- }
33
- }
1
+ {
2
+ "name": "vvvfs",
3
+ "version": "0.1.7",
4
+ "description": "一个使用IndexDB实现的虚拟文件系统",
5
+ "keywords": [
6
+ "Virtual",
7
+ "File",
8
+ "System",
9
+ "IFTC",
10
+ "VV",
11
+ "File",
12
+ "System",
13
+ "vfs",
14
+ "fs"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "IFTC",
18
+ "type": "module",
19
+ "main": "index.js",
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "node esbuild.config.js"
23
+ },
24
+ "dependencies": {
25
+ "dexie": "^4.3.0",
26
+ "esbuild": "^0.27.3",
27
+ "mime": "^4.1.0"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/IFTC-XLKJ/vvvfs.git"
32
+ }
33
+ }
package/types/index.d.ts CHANGED
@@ -44,9 +44,11 @@ declare interface VVVFSDatabase extends Dexie {
44
44
  /**
45
45
  * 虚拟文件系统配置项
46
46
  * @param throwError 是否抛出错误
47
+ * @param init 是否自动初始化,传入字符串时,为用户名,传入true时,使用默认用户名
47
48
  */
48
- declare interface VVVFSOptions {
49
+ export interface VVVFSOptions {
49
50
  throwError: boolean;
51
+ init: boolean | string;
50
52
  }
51
53
 
52
54
  /**
@@ -203,6 +205,110 @@ declare class VVVFSFile {
203
205
  isLocked(): Promise<boolean>;
204
206
  }
205
207
 
208
+ /**
209
+ * path类(类似于NodeJS中的path模块)
210
+ */
211
+ declare class Path {
212
+ /**
213
+ * 路径分隔符
214
+ */
215
+ static readonly sep: string;
216
+ /**
217
+ * 环境变量PATH的分隔符
218
+ */
219
+ static readonly delimiter: string;
220
+ /**
221
+ * 构造函数
222
+ * @param paths 路径片段
223
+ */
224
+ constructor(...paths: string[]);
225
+ /**
226
+ * 获取路径
227
+ */
228
+ get path(): string;
229
+ /**
230
+ * 设置路径
231
+ * @param path 路径
232
+ */
233
+ set path(path: string);
234
+ /**
235
+ * 获取文件名
236
+ */
237
+ get name(): string;
238
+ /**
239
+ * 获取文件所在目录
240
+ */
241
+ get parent(): string;
242
+ /**
243
+ * 获取文件扩展名
244
+ */
245
+ get ext(): string;
246
+ /**
247
+ * 获取根目录("/"或"")
248
+ */
249
+ get root(): string;
250
+ /**
251
+ * 判断路径是否为绝对路径
252
+ */
253
+ isAbsolute(): boolean;
254
+ /**
255
+ * 合并路径
256
+ * @param paths 路径片段
257
+ */
258
+ join(...paths: string[]): string;
259
+ /**
260
+ * 转换为字符串
261
+ */
262
+ toString(): string;
263
+ /**
264
+ * 合并路径
265
+ * @param paths 路径片段
266
+ */
267
+ static join(...paths: string[]): string;
268
+ /**
269
+ * 解析路径为绝对路径
270
+ * @param paths 路径片段
271
+ */
272
+ static resolve(...paths: string[]): string;
273
+ /**
274
+ * 规范化路径(清除"."、解析"..")
275
+ * @param path 路径
276
+ */
277
+ static normalize(path: string): string;
278
+ /**
279
+ * 判断路径是否为绝对路径
280
+ * @param path 路径
281
+ */
282
+ static isAbsolute(path: string): boolean;
283
+ /**
284
+ * 获取文件名(可去除后缀)
285
+ * @param path 路径
286
+ * @param suffix 后缀(如扩展名)
287
+ */
288
+ static basename(path: string, suffix?: string): string;
289
+ /**
290
+ * 获取文件所在目录
291
+ * @param path 路径
292
+ */
293
+ static dirname(path: string): string;
294
+ /**
295
+ * 获取文件扩展名
296
+ * @param path 路径
297
+ */
298
+ static extname(path: string): string;
299
+ /**
300
+ * 解析路径
301
+ * @param path 路径
302
+ */
303
+ static parse(path: string): { root: string; dir: string; base: string; ext: string; name: string };
304
+ /**
305
+ * 计算从from到to的相对路径
306
+ * @param from 起始路径
307
+ * @param to 目标路径
308
+ */
309
+ static relative(from: string, to: string): string;
310
+ }
311
+
206
312
  /**
207
313
  * 虚拟文件系统
208
314
  * @author IFTC
@@ -222,6 +328,10 @@ declare class VVVFS {
222
328
  * 虚拟文件系统文件类
223
329
  */
224
330
  static File: typeof VVVFSFile;
331
+ /**
332
+ * path类(类似于NodeJS中的path模块)
333
+ */
334
+ static path: typeof Path;
225
335
 
226
336
  options: VVVFSOptions;
227
337