@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.
Files changed (51) hide show
  1. package/dist/cjs/index.cjs +564 -0
  2. package/dist/esm/index.js +551 -0
  3. package/dist/files-api.d.ts +44 -0
  4. package/dist/files-api.d.ts.map +1 -0
  5. package/dist/impl/index.d.ts +6 -0
  6. package/dist/impl/index.d.ts.map +1 -0
  7. package/dist/impl/mem-files-api.d.ts +13 -0
  8. package/dist/impl/mem-files-api.d.ts.map +1 -0
  9. package/dist/impl/node-files-api.d.ts +24 -0
  10. package/dist/impl/node-files-api.d.ts.map +1 -0
  11. package/dist/index.d.ts +11 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/types.d.ts +57 -0
  14. package/dist/types.d.ts.map +1 -0
  15. package/dist/utils/collect-stream.d.ts +16 -0
  16. package/dist/utils/collect-stream.d.ts.map +1 -0
  17. package/dist/utils/index.d.ts +7 -0
  18. package/dist/utils/index.d.ts.map +1 -0
  19. package/dist/utils/normalize-path.d.ts +21 -0
  20. package/dist/utils/normalize-path.d.ts.map +1 -0
  21. package/dist/utils/path-utils.d.ts +20 -0
  22. package/dist/utils/path-utils.d.ts.map +1 -0
  23. package/package.json +29 -31
  24. package/src/files-api.ts +167 -0
  25. package/src/impl/index.ts +6 -0
  26. package/src/impl/mem-files-api.ts +306 -0
  27. package/src/impl/node-files-api.ts +261 -0
  28. package/src/index.ts +35 -0
  29. package/src/types.ts +68 -0
  30. package/src/utils/collect-stream.ts +35 -0
  31. package/src/utils/index.ts +7 -0
  32. package/src/utils/normalize-path.ts +34 -0
  33. package/src/utils/path-utils.ts +46 -0
  34. package/CHANGELOG.md +0 -2
  35. package/README.md +0 -17
  36. package/dist/index-umd.js +0 -1054
  37. package/dist/index-umd.min.js +0 -2
  38. package/dist/index.js +0 -1033
  39. package/dist/index.min.js +0 -2
  40. package/index.js +0 -1
  41. package/src/BrowserFilesApi.js +0 -335
  42. package/src/FilesApi.js +0 -133
  43. package/src/MemFilesApi.js +0 -129
  44. package/src/NodeFilesApi.js +0 -222
  45. package/src/addFilesApiLogger.js +0 -25
  46. package/src/getMimeType.js +0 -19
  47. package/src/index.js +0 -10
  48. package/src/mimeTypes.js +0 -96
  49. package/src/normalizePath.js +0 -8
  50. package/src/notImplemented.js +0 -3
  51. 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
@@ -1,2 +0,0 @@
1
- # @statewalker/files
2
-
package/README.md DELETED
@@ -1,17 +0,0 @@
1
-
2
- # @statewalker/files
3
-
4
- Minimalistic cross-plateform files API implementation.
5
-
6
- ## Usage
7
-
8
- ```js
9
-
10
-
11
- ```
12
-
13
- ## Example
14
-
15
- ```js
16
-
17
- ```