UNPKG

replace-regex

Version:

TS compatible modern nodeJS find-and-replace in files with Regex & Glob support

28 lines (27 loc) 900 B
import fastGlob from 'fast-glob'; type MaybeArr<T> = T | T[]; export type ReplaceRegexOptions = { files: MaybeArr<string>; from: string | RegExp | string[] | RegExp[] | ((file: string) => string | RegExp); to: string | ((match: string, file: string) => string); dry?: boolean; ignore?: string[]; disableGlobs?: boolean; fastGlobOptions?: Parameters<typeof fastGlob>[1]; /** * when passing a `string` to `from` you can make it ignore case with this flag. * otherwise, you need to embed `i` into your regex */ ignoreCase?: boolean; }; export type ReplaceRegexResult = { file: string; matchCount: number; replaceCount: number; changed: boolean; }; /** * Uses fast-glob to find and replace text in files. Supports RegExp. */ export declare function replaceRegex(options: ReplaceRegexOptions): Promise<ReplaceRegexResult[]>; export {};