@pstdio/opfs-utils
Version:
Utilities for the browser's OPFS: ls, grep, safe file read, unified diff patching, and MIME helpers.
59 lines (58 loc) • 2.14 kB
TypeScript
/**
* Shape of a single match.
*/
export interface GrepMatch {
/** POSIX-like path inside OPFS (e.g., "dir/file.txt"). */
file: string;
/** 1-based line number. */
line: number;
/** 1-based column (JS code unit index). */
column: number;
/** Matched substring. */
match: string;
/** Entire line content without trailing newline. */
lineText: string;
}
/**
* Options for grep().
*/
export interface GrepOptions {
/** Pattern to search for (string becomes a RegExp). */
pattern: string | RegExp;
/** Regex flags when `pattern` is a string (e.g., "i", "im"). "g" will be added if missing. */
flags?: string;
/** Include-only globs (e.g., ["**\/*.txt", "**\/*.log"]). If present, a path must match at least one. */
include?: string[];
/** Exclude globs (e.g., ["**\/node_modules\/**"]). */
exclude?: string[];
/** Skip files larger than this many bytes (default 20MB). */
maxFileSize?: number;
/** Max files processed in parallel (default 4). */
concurrency?: number;
/** TextDecoder encoding (default "utf-8"). */
encoding?: string;
/** Optional cancellation signal. */
signal?: AbortSignal;
/** Optional callback invoked for each match (streaming). */
onMatch?: (m: GrepMatch) => void | Promise<void>;
}
export declare function grep(dirPath: string, options: GrepOptions): Promise<GrepMatch[]>;
/**
* Ensure a *global* RegExp. If `pattern` is a string, build one with flags.
* If it's a RegExp, add 'g' if missing.
*/
export declare function toGlobalRegex(pat: string | RegExp, flags?: string): RegExp;
/**
* Apply include/exclude rules to a POSIX-like path.
*/
export declare function shouldSkip(path: string, includeREs: RegExp[], excludeREs: RegExp[]): boolean;
/**
* Convert a simple glob to RegExp. Supports **, *, ? tokens.
* - ** : match across path separators
* - * : match within a segment (no '/')
* - ? : match a single char (no '/')
*
* Note: Brace lists like {js,ts} are expanded by expandBraces() upstream
* before this converter runs.
*/
export { expandBraces, globToRegExp } from './glob';