diff --git a/package.json b/package.json index 95addb5..5677b38 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ ], "main": "index.js", "bin": "./bin/cli.js", + "types": "./types/index.d.ts", "scripts": { "istanbul": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha lib/**/*.spec.js", "test": "npm run istanbul -s", diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..725b9b6 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,31 @@ + +declare module 'replace-in-file' { + function replaceInFile(config: ReplaceInFileConfig): Promise; + function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResults) => void): void; + export default replaceInFile; + + namespace replaceInFile { + export function sync(config: ReplaceInFileConfig): ReplaceResults; + } + + export interface ReplaceInFileConfig { + files: string | string[]; + from: string | RegExp | string[] | RegExp[] | FromCallback; + to: string | string[] | ToCallback; + countMatches?: boolean; + allowEmptyPaths?: boolean, + disableGlobs?: boolean, + encoding?: string, + dry?:boolean + } + + export interface ReplaceResults { + file: string; + hasChanged: boolean; + numMatches?: number, + numReplacements?: number, + } +} + +type FromCallback = (file: string) => string | RegExp | string[] | RegExp[]; +type ToCallback = (match: string, file: string) => string | string[];