UNPKG

1.72 kBTypeScriptView Raw
1/// <reference types="node" />
2import File = require("vinyl");
3
4/**
5 * Represents options for `gulp-replace`.
6 */
7interface Options {
8 /**
9 * A value indicating whether binary files should be skipped.
10 */
11 skipBinary?: boolean
12}
13
14/**
15 * The context of the replacer-function.
16 */
17interface ReplacerContext {
18 /**
19 * The file being processed.
20 */
21 file: File
22}
23
24/**
25 * Represents a method for replacing contents of a vinyl-file.
26 */
27type Replacer = (this: ReplacerContext, match: string, ...args: any[]) => string;
28
29/**
30 * Searches and replaces a portion of text using a `string` or a `RegExp`.
31 *
32 * @param search The `string` or `RegExp` to search for.
33 *
34 * @param replacement The replacement string or a function for generating a replacement.
35 *
36 * If `replacement` is a function, it will be called once for each match and will be passed the string
37 * that is to be replaced. The value of `this.file` will be equal to the vinyl instance for the file
38 * being processed.
39 *
40 * Read more at [`String.prototype.replace()` at MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter").
41 *
42 * @param options `options.skipBinary` will be equal to `true` by default.
43 *
44 * Skip binary files. This option is `true` by default. If
45 * you want to replace content in binary files, you must explicitly set it to `false`.
46 */
47declare function replace(
48 search: string | RegExp,
49 replacement: string | Replacer,
50 options?: Options
51): NodeJS.ReadWriteStream;
52
53export = replace;