index.d.ts 744 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. declare namespace ansiRegex {
  2. interface Options {
  3. /**
  4. Match only the first ANSI escape.
  5. @default false
  6. */
  7. onlyFirst: boolean;
  8. }
  9. }
  10. /**
  11. Regular expression for matching ANSI escape codes.
  12. @example
  13. ```
  14. import ansiRegex = require('ansi-regex');
  15. ansiRegex().test('\u001B[4mcake\u001B[0m');
  16. //=> true
  17. ansiRegex().test('cake');
  18. //=> false
  19. '\u001B[4mcake\u001B[0m'.match(ansiRegex());
  20. //=> ['\u001B[4m', '\u001B[0m']
  21. '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
  22. //=> ['\u001B[4m']
  23. '\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
  24. //=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
  25. ```
  26. */
  27. declare function ansiRegex(options?: ansiRegex.Options): RegExp;
  28. export = ansiRegex;