@statewalker/webrun-files 0.3.1 → 0.5.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 (54) hide show
  1. package/README.md +188 -6
  2. package/dist/cjs/index.cjs +599 -0
  3. package/dist/esm/index.js +584 -0
  4. package/dist/files-api.d.ts +44 -0
  5. package/dist/files-api.d.ts.map +1 -0
  6. package/dist/impl/index.d.ts +6 -0
  7. package/dist/impl/index.d.ts.map +1 -0
  8. package/dist/impl/mem-files-api.d.ts +13 -0
  9. package/dist/impl/mem-files-api.d.ts.map +1 -0
  10. package/dist/impl/node-files-api.d.ts +24 -0
  11. package/dist/impl/node-files-api.d.ts.map +1 -0
  12. package/dist/index.d.ts +12 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/types.d.ts +67 -0
  15. package/dist/types.d.ts.map +1 -0
  16. package/dist/utils/collect-stream.d.ts +16 -0
  17. package/dist/utils/collect-stream.d.ts.map +1 -0
  18. package/dist/utils/file-info-utils.d.ts +10 -0
  19. package/dist/utils/file-info-utils.d.ts.map +1 -0
  20. package/dist/utils/index.d.ts +8 -0
  21. package/dist/utils/index.d.ts.map +1 -0
  22. package/dist/utils/normalize-path.d.ts +21 -0
  23. package/dist/utils/normalize-path.d.ts.map +1 -0
  24. package/dist/utils/path-utils.d.ts +20 -0
  25. package/dist/utils/path-utils.d.ts.map +1 -0
  26. package/package.json +30 -31
  27. package/src/files-api.ts +168 -0
  28. package/src/impl/index.ts +6 -0
  29. package/src/impl/mem-files-api.ts +323 -0
  30. package/src/impl/node-files-api.ts +271 -0
  31. package/src/index.ts +36 -0
  32. package/src/types.ts +79 -0
  33. package/src/utils/collect-stream.ts +35 -0
  34. package/src/utils/file-info-utils.ts +15 -0
  35. package/src/utils/index.ts +8 -0
  36. package/src/utils/normalize-path.ts +34 -0
  37. package/src/utils/path-utils.ts +46 -0
  38. package/CHANGELOG.md +0 -2
  39. package/dist/index-umd.js +0 -1054
  40. package/dist/index-umd.min.js +0 -2
  41. package/dist/index.js +0 -1033
  42. package/dist/index.min.js +0 -2
  43. package/index.js +0 -1
  44. package/src/BrowserFilesApi.js +0 -335
  45. package/src/FilesApi.js +0 -133
  46. package/src/MemFilesApi.js +0 -129
  47. package/src/NodeFilesApi.js +0 -222
  48. package/src/addFilesApiLogger.js +0 -25
  49. package/src/getMimeType.js +0 -19
  50. package/src/index.js +0 -10
  51. package/src/mimeTypes.js +0 -96
  52. package/src/normalizePath.js +0 -8
  53. package/src/notImplemented.js +0 -3
  54. package/src/openBrowserFilesApi.js +0 -67
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Stream collection utilities
3
+ */
4
+
5
+ /**
6
+ * Collects all values from an async generator into an array.
7
+ */
8
+ export async function collectGenerator<T>(generator: AsyncIterable<T>): Promise<T[]> {
9
+ const results: T[] = [];
10
+ for await (const item of generator) {
11
+ results.push(item);
12
+ }
13
+ return results;
14
+ }
15
+
16
+ /**
17
+ * Converts a synchronous iterable to an async iterable.
18
+ */
19
+ export async function* toAsyncIterable<T>(iterable: Iterable<T>): AsyncIterable<T> {
20
+ for (const item of iterable) {
21
+ yield item;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Normalizes BinaryStream to AsyncIterable<Uint8Array>.
27
+ */
28
+ export function toBinaryAsyncIterable(
29
+ data: AsyncIterable<Uint8Array> | Iterable<Uint8Array>,
30
+ ): AsyncIterable<Uint8Array> {
31
+ if (Symbol.asyncIterator in data) {
32
+ return data as AsyncIterable<Uint8Array>;
33
+ }
34
+ return toAsyncIterable(data as Iterable<Uint8Array>);
35
+ }
@@ -0,0 +1,15 @@
1
+ import type { FileInfo } from "../types.js";
2
+
3
+ /**
4
+ * Check if FileInfo represents a directory
5
+ */
6
+ export function isDirectory(info: FileInfo | undefined): boolean {
7
+ return info?.kind === "directory";
8
+ }
9
+
10
+ /**
11
+ * Check if FileInfo represents a file
12
+ */
13
+ export function isFile(info: FileInfo | undefined): boolean {
14
+ return info?.kind === "file";
15
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Utility functions
3
+ */
4
+
5
+ export * from "./collect-stream.js";
6
+ export * from "./file-info-utils.js";
7
+ export * from "./normalize-path.js";
8
+ export * from "./path-utils.js";
@@ -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
-