UNPKG

@pstdio/opfs-utils

Version:

Utilities for the browser's OPFS: ls, grep, safe file read, unified diff patching, and MIME helpers.

52 lines (51 loc) 2.38 kB
export interface LsEntry { /** POSIX-like path relative to the provided dir handle */ path: string; /** Basename of the entry */ name: string; /** "file" or "directory" */ kind: "file" | "directory"; /** Depth starting at 1 for direct children of the given dir handle */ depth: number; /** File size in bytes (only when stat: true and kind === "file") */ size?: number; /** Last modified time (epoch ms; only when stat: true and kind === "file") */ lastModified?: number; /** Blob type (MIME) from getFile(); optional */ type?: string; } export interface LsOptions { /** Maximum depth to descend (default 1 = only the directory itself). Use Infinity for full recursion. */ maxDepth?: number; /** Only include paths matching at least one of these globs. (Applied to files & dirs) */ include?: string[]; /** Exclude paths matching any of these globs. (Prunes dirs too) */ exclude?: string[]; /** Show entries whose *name* begins with "." (default: false, like `ls`) */ showHidden?: boolean; /** Which kinds to return (default: both) */ kinds?: Array<"file" | "directory">; /** Fetch size & mtime for files (default: false for speed) */ stat?: boolean; /** Concurrency limit for stat operations (default: 4) */ concurrency?: number; /** Optional cancellation signal */ signal?: AbortSignal; /** Optional streaming callback; called when an entry is ready (after stat for files) */ onEntry?: (e: LsEntry) => void | Promise<void>; /** Sort key (default: "name") */ sortBy?: "name" | "path" | "size" | "mtime"; /** Sort order (default: "asc") */ sortOrder?: "asc" | "desc"; /** Place directories before files (default: true) */ dirsFirst?: boolean; } export declare function ls(dirPath: string, opts?: LsOptions): Promise<LsEntry[]>; /** Human-friendly size (e.g., "12.3 MB"). */ export declare function formatSize(n?: number): string; /** YYYY-MM-DD HH:mm local (files only) */ export declare function formatMtime(ms?: number): string; /** Minimal “ls -l”-like output (permissions/owner not available in OPFS). */ export declare function formatLong(entries: LsEntry[]): string; /** Simple tree view (uses entries you already got; pass `maxDepth: Infinity`). */ export declare function formatTree(entries: LsEntry[]): string;