Skip to content

Commit

Permalink
feat: Add processor cb type with function overloads (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
epicmet authored May 26, 2024
1 parent e90c51f commit fd16534
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

declare module 'replace-in-file' {
export function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>;
export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void;
export function replaceInFile(config: ReplaceInFileConfig & { from?: never, to?: never, processor: ReplaceInFileConfig["processor"] }): Promise<ReplaceResult[]>;
export function replaceInFile(config: ReplaceInFileConfig & { from?: never, to?: never, processor: ReplaceInFileConfig["processor"] }, cb: (error: Error, results: ReplaceResult[]) => void): void;

export function replaceInFile(config: ReplaceInFileConfig & { from: ReplaceInFileConfig["from"], to: ReplaceInFileConfig["to"], processor?: never }): Promise<ReplaceResult[]>;
export function replaceInFile(config: ReplaceInFileConfig & { from: ReplaceInFileConfig["from"], to: ReplaceInFileConfig["to"], processor?: never }, cb: (error: Error, results: ReplaceResult[]) => void): void;

export default replaceInFile;

export namespace replaceInFile {
Expand All @@ -20,14 +24,15 @@ declare module 'replace-in-file' {
export interface ReplaceInFileConfig {
files: string | string[];
ignore?: string | string[];
from: From | Array<From>;
to: To | Array<To>;
from?: From | Array<From>;
to?: To | Array<To>;
countMatches?: boolean;
allowEmptyPaths?: boolean,
disableGlobs?: boolean,
encoding?: string,
dry?:boolean
glob?:object
allowEmptyPaths?: boolean;
disableGlobs?: boolean;
encoding?: string;
dry?: boolean;
glob?: object;
processor?: ProcessorCallback | Array<ProcessorCallback>;
}

export interface ReplaceResult {
Expand All @@ -40,3 +45,4 @@ declare module 'replace-in-file' {

type FromCallback = (file: string) => string | RegExp | (RegExp | string)[];
type ToCallback = (match: string, file: string) => string | string[];
type ProcessorCallback = (input: string, file: string) => string;

0 comments on commit fd16534

Please sign in to comment.