@pstdio/opfs-utils
Version:
Utilities for the browser's OPFS: ls, grep, safe file read, unified diff patching, and MIME helpers.
40 lines (39 loc) • 1.77 kB
TypeScript
export interface GlobPath {
/** Return an absolute-like path string (OPFS-style). */
fullpath(): string;
/** Milliseconds since epoch (file last modified). */
mtimeMs?: number;
}
export interface OpfsGlobOptions {
/** Glob pattern (supports **, *, ?, [..], and one-level {a,b,c}). */
pattern: string;
/** Subdirectory within the OPFS root to search (like cwd). Default: "" (root). */
path?: string;
/** Case sensitivity. Default: false (case-insensitive). */
caseSensitive?: boolean;
/** Include dotfiles. Default: true. */
dot?: boolean;
/** Additional ignore globs (always applied). Default: ['**\/node_modules/**','**\/.git/**'] */
ignore?: string[];
/** Respect .gitignore rules at the search root. Default: true. (simplified semantics) */
respectGitIgnore?: boolean;
/** Collect file stats (mtime) for recency sorting. Default: true. */
stat?: boolean;
/** Abort signal to cancel mid-search. */
signal?: AbortSignal;
}
export interface GlobResult {
/** Matched files (files only). */
entries: GlobPath[];
/** Count of files that were filtered due to .gitignore (approximate). */
gitIgnored: number;
/** A human-readable message similar to your tool’s summary. */
summary: string;
}
export declare function opfsGlob(_root: FileSystemDirectoryHandle, opts: OpfsGlobOptions): Promise<GlobResult>;
/**
* Sorts file entries based on recency and then alphabetically.
* Recent files (modified within recencyThresholdMs) are listed first, newest to oldest.
* Older files are listed after recent ones, sorted alphabetically by path.
*/
export declare function sortFileEntries(entries: GlobPath[], nowTimestamp: number, recencyThresholdMs: number): GlobPath[];