shfs 0.1.2 → 0.1.3

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.
@@ -19,4 +19,4 @@ interface FS {
19
19
  }
20
20
  //#endregion
21
21
  export { Stream as n, FS as t };
22
- //# sourceMappingURL=fs-D1tzq9TG.d.mts.map
22
+ //# sourceMappingURL=fs-rz7EnuDE.d.mts.map
package/dist/fs.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as Stream, t as FS } from "./fs-D1tzq9TG.mjs";
1
+ import { n as Stream, t as FS } from "./fs-rz7EnuDE.mjs";
2
2
 
3
3
  //#region src/fs/memory.d.ts
4
4
  declare class MemoryFS implements FS {
package/dist/fs.mjs CHANGED
@@ -1,12 +1,7 @@
1
+ import { t as normalizePath } from "./path-BR0nl4aX.mjs";
1
2
  import picomatch from "picomatch";
2
3
 
3
4
  //#region src/fs/memory.ts
4
- const TRAILING_SLASH_REGEX = /\/+$/;
5
- const MULTIPLE_SLASH_REGEX = /\/+/g;
6
- function normalizePath(path) {
7
- if (path === "" || path === "/") return "/";
8
- return path.replace(TRAILING_SLASH_REGEX, "").replace(MULTIPLE_SLASH_REGEX, "/");
9
- }
10
5
  var MemoryFS = class {
11
6
  files = /* @__PURE__ */ new Map();
12
7
  directories = /* @__PURE__ */ new Set();
@@ -74,7 +69,7 @@ var MemoryFS = class {
74
69
  }
75
70
  async *readdir(glob) {
76
71
  const isMatch = picomatch(glob, { dot: true });
77
- const paths = Array.from(this.files.keys()).filter((path) => isMatch(path)).sort();
72
+ const paths = [...Array.from(this.directories.keys()), ...Array.from(this.files.keys())].filter((path) => isMatch(path)).sort();
78
73
  for (const path of paths) yield path;
79
74
  }
80
75
  async mkdir(path, recursive = false) {
package/dist/fs.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fs.mjs","names":[],"sources":["../src/fs/memory.ts"],"sourcesContent":["import picomatch from 'picomatch';\nimport type { Stream } from '../stream';\nimport type { FS } from './fs';\n\nexport type { FS } from './fs';\n\nconst TRAILING_SLASH_REGEX = /\\/+$/;\nconst MULTIPLE_SLASH_REGEX = /\\/+/g;\n\nfunction normalizePath(path: string): string {\n\tif (path === '' || path === '/') {\n\t\treturn '/';\n\t}\n\treturn path\n\t\t.replace(TRAILING_SLASH_REGEX, '')\n\t\t.replace(MULTIPLE_SLASH_REGEX, '/');\n}\n\nexport class MemoryFS implements FS {\n\tprivate readonly files = new Map<string, Uint8Array>();\n\tprivate readonly directories = new Set<string>();\n\tprivate readonly fileMetadata = new Map<\n\t\tstring,\n\t\t{ mtime: Date; isDirectory: boolean }\n\t>();\n\n\tconstructor() {\n\t\t// Initialize root directory\n\t\tthis.directories.add('/');\n\t\tthis.fileMetadata.set('/', { mtime: new Date(), isDirectory: true });\n\t}\n\n\tsetFile(path: string, content: string | Uint8Array): void {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst encoded =\n\t\t\ttypeof content === 'string'\n\t\t\t\t? new TextEncoder().encode(content)\n\t\t\t\t: content;\n\t\tthis.files.set(normalizedPath, encoded);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync readFile(path: string): Promise<Uint8Array> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\treturn content;\n\t}\n\n\tasync *readLines(path: string): Stream<string> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tconst text = new TextDecoder().decode(content);\n\t\tconst lines = text\n\t\t\t.split('\\n')\n\t\t\t.filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === ''));\n\t\tyield* lines;\n\t}\n\n\tasync writeFile(path: string, content: Uint8Array): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tthis.files.set(normalizedPath, content);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync deleteFile(path: string): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (!this.files.has(normalizedPath)) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tthis.files.delete(normalizedPath);\n\t\tthis.fileMetadata.delete(normalizedPath);\n\t}\n\n\tasync deleteDirectory(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (normalizedPath === '/') {\n\t\t\tthrow new Error(\"rm: cannot remove '/'\");\n\t\t}\n\t\tif (!this.directories.has(normalizedPath)) {\n\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t}\n\n\t\tconst childPrefix = `${normalizedPath}/`;\n\t\tconst hasChildDirectories = Array.from(this.directories).some(\n\t\t\t(directory) =>\n\t\t\t\tdirectory !== normalizedPath &&\n\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t);\n\t\tconst hasChildFiles = Array.from(this.files.keys()).some((filePath) =>\n\t\t\tfilePath.startsWith(childPrefix)\n\t\t);\n\n\t\tif (!recursive && (hasChildDirectories || hasChildFiles)) {\n\t\t\tthrow new Error(`Directory not empty: ${path}`);\n\t\t}\n\n\t\tfor (const filePath of Array.from(this.files.keys())) {\n\t\t\tif (filePath.startsWith(childPrefix)) {\n\t\t\t\tthis.files.delete(filePath);\n\t\t\t\tthis.fileMetadata.delete(filePath);\n\t\t\t}\n\t\t}\n\n\t\tconst directoriesToDelete = Array.from(this.directories)\n\t\t\t.filter(\n\t\t\t\t(directory) =>\n\t\t\t\t\tdirectory === normalizedPath ||\n\t\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t\t)\n\t\t\t.sort((a, b) => b.length - a.length);\n\t\tfor (const directory of directoriesToDelete) {\n\t\t\tif (directory === '/') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.directories.delete(directory);\n\t\t\tthis.fileMetadata.delete(directory);\n\t\t}\n\t}\n\n\tasync *readdir(glob: string): Stream<string> {\n\t\tconst isMatch = picomatch(glob, { dot: true });\n\n\t\tconst paths = Array.from(this.files.keys())\n\t\t\t.filter((path) => isMatch(path))\n\t\t\t.sort();\n\n\t\tfor (const path of paths) {\n\t\t\tyield path;\n\t\t}\n\t}\n\n\tasync mkdir(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (\n\t\t\tthis.directories.has(normalizedPath) ||\n\t\t\tthis.files.has(normalizedPath)\n\t\t) {\n\t\t\tthrow new Error(`Directory already exists: ${path}`);\n\t\t}\n\n\t\tif (recursive) {\n\t\t\t// Create all parent directories\n\t\t\tconst parts = normalizedPath.split('/').filter(Boolean);\n\t\t\tlet current = '';\n\t\t\tfor (const part of parts) {\n\t\t\t\tcurrent += `/${part}`;\n\t\t\t\tif (\n\t\t\t\t\t!(this.directories.has(current) || this.files.has(current))\n\t\t\t\t) {\n\t\t\t\t\tthis.directories.add(current);\n\t\t\t\t\tthis.fileMetadata.set(current, {\n\t\t\t\t\t\tmtime: new Date(),\n\t\t\t\t\t\tisDirectory: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Check if parent directory exists\n\t\t\tconst parentPath =\n\t\t\t\tnormalizedPath.substring(0, normalizedPath.lastIndexOf('/')) ||\n\t\t\t\t'/';\n\t\t\tif (\n\t\t\t\tparentPath !== '/' &&\n\t\t\t\t!this.directories.has(parentPath) &&\n\t\t\t\t!this.files.has(parentPath)\n\t\t\t) {\n\t\t\t\tthrow new Error(`No such file or directory: ${parentPath}`);\n\t\t\t}\n\t\t\tthis.directories.add(normalizedPath);\n\t\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\t\tmtime: new Date(),\n\t\t\t\tisDirectory: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync stat(\n\t\tpath: string\n\t): Promise<{ isDirectory: boolean; size: number; mtime: Date }> {\n\t\t// Normalize path by removing trailing slash\n\t\tconst normalizedPath = normalizePath(path);\n\n\t\tif (this.directories.has(normalizedPath)) {\n\t\t\treturn {\n\t\t\t\tisDirectory: true,\n\t\t\t\tsize: 0,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tif (this.files.has(normalizedPath)) {\n\t\t\tconst content = this.files.get(normalizedPath);\n\t\t\tif (content === undefined) {\n\t\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tisDirectory: false,\n\t\t\t\tsize: content.byteLength,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tthrow new Error(`No such file or directory: ${path}`);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\treturn (\n\t\t\tthis.files.has(normalizedPath) ||\n\t\t\tthis.directories.has(normalizedPath)\n\t\t);\n\t}\n}\n"],"mappings":";;;AAMA,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,SAAS,cAAc,MAAsB;AAC5C,KAAI,SAAS,MAAM,SAAS,IAC3B,QAAO;AAER,QAAO,KACL,QAAQ,sBAAsB,GAAG,CACjC,QAAQ,sBAAsB,IAAI;;AAGrC,IAAa,WAAb,MAAoC;CACnC,AAAiB,wBAAQ,IAAI,KAAyB;CACtD,AAAiB,8BAAc,IAAI,KAAa;CAChD,AAAiB,+BAAe,IAAI,KAGjC;CAEH,cAAc;AAEb,OAAK,YAAY,IAAI,IAAI;AACzB,OAAK,aAAa,IAAI,KAAK;GAAE,uBAAO,IAAI,MAAM;GAAE,aAAa;GAAM,CAAC;;CAGrE,QAAQ,MAAc,SAAoC;EACzD,MAAM,iBAAiB,cAAc,KA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ources":["../src/fs/memory.ts"],"sourcesContent":["import picomatch from 'picomatch';\nimport type { Stream } from '../stream';\nimport { normalizePath } from '../util/path';\nimport type { FS } from './fs';\n\nexport type { FS } from './fs';\n\nexport class MemoryFS implements FS {\n\tprivate readonly files = new Map<string, Uint8Array>();\n\tprivate readonly directories = new Set<string>();\n\tprivate readonly fileMetadata = new Map<\n\t\tstring,\n\t\t{ mtime: Date; isDirectory: boolean }\n\t>();\n\n\tconstructor() {\n\t\t// Initialize root directory\n\t\tthis.directories.add('/');\n\t\tthis.fileMetadata.set('/', { mtime: new Date(), isDirectory: true });\n\t}\n\n\tsetFile(path: string, content: string | Uint8Array): void {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst encoded =\n\t\t\ttypeof content === 'string'\n\t\t\t\t? new TextEncoder().encode(content)\n\t\t\t\t: content;\n\t\tthis.files.set(normalizedPath, encoded);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync readFile(path: string): Promise<Uint8Array> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\treturn content;\n\t}\n\n\tasync *readLines(path: string): Stream<string> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tconst text = new TextDecoder().decode(content);\n\t\tconst lines = text\n\t\t\t.split('\\n')\n\t\t\t.filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === ''));\n\t\tyield* lines;\n\t}\n\n\tasync writeFile(path: string, content: Uint8Array): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tthis.files.set(normalizedPath, content);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync deleteFile(path: string): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (!this.files.has(normalizedPath)) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tthis.files.delete(normalizedPath);\n\t\tthis.fileMetadata.delete(normalizedPath);\n\t}\n\n\tasync deleteDirectory(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (normalizedPath === '/') {\n\t\t\tthrow new Error(\"rm: cannot remove '/'\");\n\t\t}\n\t\tif (!this.directories.has(normalizedPath)) {\n\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t}\n\n\t\tconst childPrefix = `${normalizedPath}/`;\n\t\tconst hasChildDirectories = Array.from(this.directories).some(\n\t\t\t(directory) =>\n\t\t\t\tdirectory !== normalizedPath &&\n\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t);\n\t\tconst hasChildFiles = Array.from(this.files.keys()).some((filePath) =>\n\t\t\tfilePath.startsWith(childPrefix)\n\t\t);\n\n\t\tif (!recursive && (hasChildDirectories || hasChildFiles)) {\n\t\t\tthrow new Error(`Directory not empty: ${path}`);\n\t\t}\n\n\t\tfor (const filePath of Array.from(this.files.keys())) {\n\t\t\tif (filePath.startsWith(childPrefix)) {\n\t\t\t\tthis.files.delete(filePath);\n\t\t\t\tthis.fileMetadata.delete(filePath);\n\t\t\t}\n\t\t}\n\n\t\tconst directoriesToDelete = Array.from(this.directories)\n\t\t\t.filter(\n\t\t\t\t(directory) =>\n\t\t\t\t\tdirectory === normalizedPath ||\n\t\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t\t)\n\t\t\t.sort((a, b) => b.length - a.length);\n\t\tfor (const directory of directoriesToDelete) {\n\t\t\tif (directory === '/') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.directories.delete(directory);\n\t\t\tthis.fileMetadata.delete(directory);\n\t\t}\n\t}\n\n\tasync *readdir(glob: string): Stream<string> {\n\t\tconst isMatch = picomatch(glob, { dot: true });\n\n\t\tconst allPaths = [\n\t\t\t...Array.from(this.directories.keys()),\n\t\t\t...Array.from(this.files.keys()),\n\t\t];\n\t\tconst paths = allPaths.filter((path) => isMatch(path)).sort();\n\n\t\tfor (const path of paths) {\n\t\t\tyield path;\n\t\t}\n\t}\n\n\tasync mkdir(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (\n\t\t\tthis.directories.has(normalizedPath) ||\n\t\t\tthis.files.has(normalizedPath)\n\t\t) {\n\t\t\tthrow new Error(`Directory already exists: ${path}`);\n\t\t}\n\n\t\tif (recursive) {\n\t\t\t// Create all parent directories\n\t\t\tconst parts = normalizedPath.split('/').filter(Boolean);\n\t\t\tlet current = '';\n\t\t\tfor (const part of parts) {\n\t\t\t\tcurrent += `/${part}`;\n\t\t\t\tif (\n\t\t\t\t\t!(this.directories.has(current) || this.files.has(current))\n\t\t\t\t) {\n\t\t\t\t\tthis.directories.add(current);\n\t\t\t\t\tthis.fileMetadata.set(current, {\n\t\t\t\t\t\tmtime: new Date(),\n\t\t\t\t\t\tisDirectory: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Check if parent directory exists\n\t\t\tconst parentPath =\n\t\t\t\tnormalizedPath.substring(0, normalizedPath.lastIndexOf('/')) ||\n\t\t\t\t'/';\n\t\t\tif (\n\t\t\t\tparentPath !== '/' &&\n\t\t\t\t!this.directories.has(parentPath) &&\n\t\t\t\t!this.files.has(parentPath)\n\t\t\t) {\n\t\t\t\tthrow new Error(`No such file or directory: ${parentPath}`);\n\t\t\t}\n\t\t\tthis.directories.add(normalizedPath);\n\t\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\t\tmtime: new Date(),\n\t\t\t\tisDirectory: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync stat(\n\t\tpath: string\n\t): Promise<{ isDirectory: boolean; size: number; mtime: Date }> {\n\t\t// Normalize path by removing trailing slash\n\t\tconst normalizedPath = normalizePath(path);\n\n\t\tif (this.directories.has(normalizedPath)) {\n\t\t\treturn {\n\t\t\t\tisDirectory: true,\n\t\t\t\tsize: 0,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tif (this.files.has(normalizedPath)) {\n\t\t\tconst content = this.files.get(normalizedPath);\n\t\t\tif (content === undefined) {\n\t\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tisDirectory: false,\n\t\t\t\tsize: content.byteLength,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tthrow new Error(`No such file or directory: ${path}`);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\treturn (\n\t\t\tthis.files.has(normalizedPath) ||\n\t\t\tthis.directories.has(normalizedPath)\n\t\t);\n\t}\n}\n"],"mappings":";;;;AAOA,IAAa,WAAb,MAAoC;CACnC,AAAiB,wBAAQ,IAAI,KAAyB;CACtD,AAAiB,8BAAc,IAAI,KAAa;CAChD,AAAiB,+BAAe,IAAI,KAGjC;CAEH,cAAc;AAEb,OAAK,YAAY,IAAI,IAAI;AACzB,OAAK,aAAa,IAAI,KAAK;GAAE,uBAAO,IAAI,MAAM;GAAE,aAAa;GAAM,CAAC;;CAGrE,QAAQ,MAAc,SAAoC;EACzD,MAAM,iBAAiB,cAAc,KAAK;EAC1C,MAAM,UACL,OAAO,YAAY,WAChB,IAAI,aAAa,CAAC,OAAO,QAAQ,GACjC;AACJ,OAAK,MAAM,IAAI,gBAAgB,QAAQ;AACvC,OAAK,aAAa,IAAI,gBAAgB;GACrC,uBAAO,IAAI,MAAM;GACjB,aAAa;GACb,CAAC;;CAGH,MAAM,SAAS,MAAmC;EACjD,MAAM,iBAAiB,cAAc,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Q;AAC7B,UAAK,aAAa,IAAI,SAAS;MAC9B,uBAAO,IAAI,MAAM;MACjB,aAAa;MACb,CAAC;;;SAGE;GAEN,MAAM,aACL,eAAe,UAAU,GAAG,eAAe,YAAY,IAAI,CAAC,IAC5D;AACD,OACC,eAAe,OACf,CAAC,KAAK,YAAY,IAAI,WAAW,IACjC,CAAC,KAAK,MAAM,IAAI,WAAW,CAE3B,OAAM,IAAI,MAAM,8BAA8B,aAAa;AAE5D,QAAK,YAAY,IAAI,eAAe;AACpC,QAAK,aAAa,IAAI,gBAAgB;IACrC,uBAAO,IAAI,MAAM;IACjB,aAAa;IACb,CAAC;;;CAIJ,MAAM,KACL,MAC+D;EAE/D,MAAM,iBAAiB,cAAc,KAAK;AAE1C,MAAI,KAAK,YAAY,IAAI,eAAe,CACvC,QAAO;GACN,aAAa;GACb,MAAM;GACN,OACC,KAAK,aAAa,IAAI,eAAe,EAAE,yBAAS,IAAI,MAAM;GAC3D;AAGF,MAAI,KAAK,MAAM,IAAI,eAAe,EAAE;GACnC,MAAM,UAAU,KAAK,MAAM,IAAI,eAAe;AAC9C,OAAI,YAAY,OACf,OAAM,IAAI,MAAM,8BAA8B,OAAO;AAEtD,UAAO;IACN,aAAa;IACb,MAAM,QAAQ;IACd,OACC,KAAK,aAAa,IAAI,eAAe,EAAE,yBAAS,IAAI,MAAM;IAC3D;;AAGF,QAAM,IAAI,MAAM,8BAA8B,OAAO;;CAGtD,MAAM,OAAO,MAAgC;EAC5C,MAAM,iBAAiB,cAAc,KAAK;AAC1C,SACC,KAAK,MAAM,IAAI,eAAe,IAC9B,KAAK,YAAY,IAAI,eAAe"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as FS } from "./fs-D1tzq9TG.mjs";
1
+ import { t as FS } from "./fs-rz7EnuDE.mjs";
2
2
 
3
3
  //#region src/record.d.ts
4
4
  interface FileRecord {
@@ -0,0 +1,12 @@
1
+ //#region src/util/path.ts
2
+ const TRAILING_SLASH_REGEX = /\/+$/;
3
+ const MULTIPLE_SLASH_REGEX = /\/+/g;
4
+ function normalizePath(path) {
5
+ if (path === "" || path === "/") return "/";
6
+ const normalized = path.replace(TRAILING_SLASH_REGEX, "").replace(MULTIPLE_SLASH_REGEX, "/");
7
+ return normalized.startsWith("/") ? normalized : `/${normalized}`;
8
+ }
9
+
10
+ //#endregion
11
+ export { normalizePath as t };
12
+ //# sourceMappingURL=path-BR0nl4aX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-BR0nl4aX.mjs","names":[],"sources":["../src/util/path.ts"],"sourcesContent":["const TRAILING_SLASH_REGEX = /\\/+$/;\nconst MULTIPLE_SLASH_REGEX = /\\/+/g;\n\nexport function normalizePath(path: string): string {\n\tif (path === '' || path === '/') {\n\t\treturn '/';\n\t}\n\tconst normalized = path\n\t\t.replace(TRAILING_SLASH_REGEX, '')\n\t\t.replace(MULTIPLE_SLASH_REGEX, '/');\n\treturn normalized.startsWith('/') ? normalized : `/${normalized}`;\n}\n"],"mappings":";AAAA,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAE7B,SAAgB,cAAc,MAAsB;AACnD,KAAI,SAAS,MAAM,SAAS,IAC3B,QAAO;CAER,MAAM,aAAa,KACjB,QAAQ,sBAAsB,GAAG,CACjC,QAAQ,sBAAsB,IAAI;AACpC,QAAO,WAAW,WAAW,IAAI,GAAG,aAAa,IAAI"}
@@ -0,0 +1,5 @@
1
+ //#region src/util/path.d.ts
2
+ declare function normalizePath(path: string): string;
3
+ //#endregion
4
+ export { normalizePath };
5
+ //# sourceMappingURL=path.d.mts.map
@@ -0,0 +1,3 @@
1
+ import { t as normalizePath } from "../path-BR0nl4aX.mjs";
2
+
3
+ export { normalizePath };
package/package.json CHANGED
@@ -20,6 +20,10 @@
20
20
  "./fs": {
21
21
  "import": "./dist/fs.mjs",
22
22
  "types": "./dist/fs.d.mts"
23
+ },
24
+ "./util/path": {
25
+ "import": "./dist/util/path.mjs",
26
+ "types": "./dist/util/path.d.mts"
23
27
  }
24
28
  },
25
29
  "files": [
@@ -50,5 +54,5 @@
50
54
  },
51
55
  "type": "module",
52
56
  "types": "./dist/index.d.mts",
53
- "version": "0.1.2"
57
+ "version": "0.1.3"
54
58
  }