index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. declare namespace terminalLink {
  2. interface Options {
  3. /**
  4. Override the default fallback. If false, the fallback will be disabled.
  5. @default `${text} (${url})`
  6. */
  7. fallback?: ((text: string, url: string) => string) | boolean;
  8. }
  9. }
  10. declare const terminalLink: {
  11. /**
  12. Create a clickable link in the terminal's stdout.
  13. [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
  14. For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`,
  15. unless the fallback is disabled by setting the `fallback` option to `false`.
  16. @param text - Text to linkify.
  17. @param url - URL to link to.
  18. @example
  19. ```
  20. import terminalLink = require('terminal-link');
  21. const link = terminalLink('My Website', 'https://sindresorhus.com');
  22. console.log(link);
  23. ```
  24. */
  25. (text: string, url: string, options?: terminalLink.Options): string;
  26. /**
  27. Check whether the terminal supports links.
  28. Prefer just using the default fallback or the `fallback` option whenever possible.
  29. */
  30. readonly isSupported: boolean;
  31. readonly stderr: {
  32. /**
  33. Create a clickable link in the terminal's stderr.
  34. [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
  35. For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`.
  36. @param text - Text to linkify.
  37. @param url - URL to link to.
  38. @example
  39. ```
  40. import terminalLink = require('terminal-link');
  41. const link = terminalLink.stderr('My Website', 'https://sindresorhus.com');
  42. console.error(link);
  43. ```
  44. */
  45. (text: string, url: string, options?: terminalLink.Options): string;
  46. /**
  47. Check whether the terminal's stderr supports links.
  48. Prefer just using the default fallback or the `fallback` option whenever possible.
  49. */
  50. readonly isSupported: boolean;
  51. }
  52. };
  53. export = terminalLink;