index.js 837 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const ansiEscapes = require('ansi-escapes');
  3. const supportsHyperlinks = require('supports-hyperlinks');
  4. const terminalLink = (text, url, {target = 'stdout', ...options} = {}) => {
  5. if (!supportsHyperlinks[target]) {
  6. // If the fallback has been explicitly disabled, don't modify the text itself.
  7. if (options.fallback === false) {
  8. return text;
  9. }
  10. return typeof options.fallback === 'function' ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)`;
  11. }
  12. return ansiEscapes.link(text, url);
  13. };
  14. module.exports = (text, url, options = {}) => terminalLink(text, url, options);
  15. module.exports.stderr = (text, url, options = {}) => terminalLink(text, url, {target: 'stderr', ...options});
  16. module.exports.isSupported = supportsHyperlinks.stdout;
  17. module.exports.stderr.isSupported = supportsHyperlinks.stderr;