1import chalk from 'chalk'; 2import terminalLink from 'terminal-link'; 3 4/** 5 * Prints a link for given URL, using text if provided, otherwise text is just the URL. 6 * Format links as dim (unless disabled) and with an underline. 7 * 8 * @example https://expo.dev 9 */ 10export function link( 11 url: string, 12 { text = url, dim = true }: { text?: string; dim?: boolean } = {} 13): string { 14 let output: string; 15 // Links can be disabled via env variables https://github.com/jamestalmage/supports-hyperlinks/blob/master/index.js 16 if (terminalLink.isSupported) { 17 output = terminalLink(text, url); 18 } else { 19 output = `${text === url ? '' : text + ': '}${chalk.underline(url)}`; 20 } 21 return dim ? chalk.dim(output) : output; 22} 23 24/** 25 * Provide a consistent "Learn more" link experience. 26 * Format links as dim (unless disabled) with an underline. 27 * 28 * @example [Learn more](https://expo.dev) 29 * @example Learn more: https://expo.dev 30 */ 31export function learnMore( 32 url: string, 33 { 34 learnMoreMessage: maybeLearnMoreMessage, 35 dim = true, 36 }: { learnMoreMessage?: string; dim?: boolean } = {} 37): string { 38 return link(url, { text: maybeLearnMoreMessage ?? 'Learn more', dim }); 39} 40