index.d.ts 1.7 KB

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