index.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. declare namespace cloneRegexp {
  2. interface Options {
  3. /**
  4. Modifies the [`source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source) property of the cloned `RegExp` instance.
  5. */
  6. source?: string;
  7. /**
  8. Modifies the [`global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global) property of the cloned `RegExp` instance.
  9. */
  10. global?: boolean;
  11. /**
  12. Modifies the [`ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase) property of the cloned `RegExp` instance.
  13. */
  14. ignoreCase?: boolean;
  15. /**
  16. Modifies the [`multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline) property of the cloned `RegExp` instance.
  17. */
  18. multiline?: boolean;
  19. /**
  20. Modifies the [`dotAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll) property of the cloned `RegExp` instance.
  21. */
  22. dotAll?: boolean;
  23. /**
  24. Modifies the [`sticky`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) property of the cloned `RegExp` instance.
  25. */
  26. sticky?: boolean;
  27. /**
  28. Modifies the [`unicode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) property of the cloned `RegExp` instance.
  29. */
  30. unicode?: boolean;
  31. /**
  32. Modifies the [`lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) property of the cloned `RegExp` instance.
  33. */
  34. lastIndex?: number;
  35. }
  36. }
  37. /**
  38. Clone and modify a [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance.
  39. @param regexp - Regex to clone.
  40. @example
  41. ```
  42. import cloneRegexp = require('clone-regexp');
  43. const regex = /[a-z]/gi;
  44. cloneRegexp(regex);
  45. //=> /[a-z]/gi
  46. cloneRegexp(regex) === regex;
  47. //=> false
  48. cloneRegexp(regex, {global: false});
  49. //=> /[a-z]/i
  50. cloneRegexp(regex, {multiline: true});
  51. //=> /[a-z]/gim
  52. cloneRegexp(regex, {source: 'unicorn'});
  53. //=> /unicorn/gi
  54. ```
  55. */
  56. declare function cloneRegexp(
  57. regexp: RegExp,
  58. options?: cloneRegexp.Options
  59. ): RegExp;
  60. export = cloneRegexp;