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