@statewalker/webrun-files 0.3.1 → 0.4.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/cjs/index.cjs +564 -0
- package/dist/esm/index.js +551 -0
- package/dist/files-api.d.ts +44 -0
- package/dist/files-api.d.ts.map +1 -0
- package/dist/impl/index.d.ts +6 -0
- package/dist/impl/index.d.ts.map +1 -0
- package/dist/impl/mem-files-api.d.ts +13 -0
- package/dist/impl/mem-files-api.d.ts.map +1 -0
- package/dist/impl/node-files-api.d.ts +24 -0
- package/dist/impl/node-files-api.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/collect-stream.d.ts +16 -0
- package/dist/utils/collect-stream.d.ts.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/normalize-path.d.ts +21 -0
- package/dist/utils/normalize-path.d.ts.map +1 -0
- package/dist/utils/path-utils.d.ts +20 -0
- package/dist/utils/path-utils.d.ts.map +1 -0
- package/package.json +29 -31
- package/src/files-api.ts +167 -0
- package/src/impl/index.ts +6 -0
- package/src/impl/mem-files-api.ts +306 -0
- package/src/impl/node-files-api.ts +261 -0
- package/src/index.ts +35 -0
- package/src/types.ts +68 -0
- package/src/utils/collect-stream.ts +35 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/normalize-path.ts +34 -0
- package/src/utils/path-utils.ts +46 -0
- package/CHANGELOG.md +0 -2
- package/README.md +0 -17
- package/dist/index-umd.js +0 -1054
- package/dist/index-umd.min.js +0 -2
- package/dist/index.js +0 -1033
- package/dist/index.min.js +0 -2
- package/index.js +0 -1
- package/src/BrowserFilesApi.js +0 -335
- package/src/FilesApi.js +0 -133
- package/src/MemFilesApi.js +0 -129
- package/src/NodeFilesApi.js +0 -222
- package/src/addFilesApiLogger.js +0 -25
- package/src/getMimeType.js +0 -19
- package/src/index.js +0 -10
- package/src/mimeTypes.js +0 -96
- package/src/normalizePath.js +0 -8
- package/src/notImplemented.js +0 -3
- package/src/openBrowserFilesApi.js +0 -67
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path normalization utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { FileRef } from "../types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes a file path to a consistent format.
|
|
9
|
+
* - Adds leading slash if missing
|
|
10
|
+
* - Removes trailing slash
|
|
11
|
+
* - Removes `.` segments
|
|
12
|
+
* - Collapses multiple slashes
|
|
13
|
+
*/
|
|
14
|
+
export function normalizePath(filePath: string): string {
|
|
15
|
+
const segments = filePath.split("/").filter((s) => !!s && s !== ".");
|
|
16
|
+
if (segments.length === 0) {
|
|
17
|
+
return "/";
|
|
18
|
+
}
|
|
19
|
+
return `/${segments.join("/")}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extracts path string from FileRef.
|
|
24
|
+
*/
|
|
25
|
+
export function toPath(file: FileRef): string {
|
|
26
|
+
return typeof file === "object" ? file.path : String(file);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Normalizes FileRef to a path string.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveFileRef(file: FileRef): string {
|
|
33
|
+
return normalizePath(toPath(file));
|
|
34
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path manipulation utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { normalizePath } from "./normalize-path.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Joins path segments with proper normalization.
|
|
9
|
+
*/
|
|
10
|
+
export function joinPath(...segments: string[]): string {
|
|
11
|
+
const combined = segments.join("/");
|
|
12
|
+
return normalizePath(combined);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the directory portion of a path.
|
|
17
|
+
*/
|
|
18
|
+
export function dirname(path: string): string {
|
|
19
|
+
const normalized = normalizePath(path);
|
|
20
|
+
const lastSlash = normalized.lastIndexOf("/");
|
|
21
|
+
if (lastSlash <= 0) return "/";
|
|
22
|
+
return normalized.substring(0, lastSlash);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns the filename portion of a path.
|
|
27
|
+
*/
|
|
28
|
+
export function basename(path: string, ext?: string): string {
|
|
29
|
+
const normalized = normalizePath(path);
|
|
30
|
+
const lastSlash = normalized.lastIndexOf("/");
|
|
31
|
+
const name = lastSlash === -1 ? normalized : normalized.substring(lastSlash + 1);
|
|
32
|
+
if (ext && name.endsWith(ext)) {
|
|
33
|
+
return name.substring(0, name.length - ext.length);
|
|
34
|
+
}
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the file extension including the dot.
|
|
40
|
+
*/
|
|
41
|
+
export function extname(path: string): string {
|
|
42
|
+
const name = basename(path);
|
|
43
|
+
const dotIndex = name.lastIndexOf(".");
|
|
44
|
+
if (dotIndex <= 0) return "";
|
|
45
|
+
return name.substring(dotIndex);
|
|
46
|
+
}
|
package/CHANGELOG.md
DELETED