| 1 | # terminal-link [](https://travis-ci.org/sindresorhus/terminal-link)
|
|---|
| 2 |
|
|---|
| 3 | > Create clickable links in the terminal
|
|---|
| 4 |
|
|---|
| 5 | <img src="screenshot.gif" width="301" height="148">
|
|---|
| 6 |
|
|---|
| 7 | ## Install
|
|---|
| 8 |
|
|---|
| 9 | ```
|
|---|
| 10 | $ npm install terminal-link
|
|---|
| 11 | ```
|
|---|
| 12 |
|
|---|
| 13 | ## Usage
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | const terminalLink = require('terminal-link');
|
|---|
| 17 |
|
|---|
| 18 | const link = terminalLink('My Website', 'https://sindresorhus.com');
|
|---|
| 19 | console.log(link);
|
|---|
| 20 | ```
|
|---|
| 21 |
|
|---|
| 22 | ## API
|
|---|
| 23 |
|
|---|
| 24 | ### terminalLink(text, url, options?)
|
|---|
| 25 |
|
|---|
| 26 | Create a link for use in stdout.
|
|---|
| 27 |
|
|---|
| 28 | [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
|
|---|
| 29 |
|
|---|
| 30 | For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`.
|
|---|
| 31 |
|
|---|
| 32 | #### text
|
|---|
| 33 |
|
|---|
| 34 | Type: `string`
|
|---|
| 35 |
|
|---|
| 36 | Text to linkify.
|
|---|
| 37 |
|
|---|
| 38 | #### url
|
|---|
| 39 |
|
|---|
| 40 | Type: `string`
|
|---|
| 41 |
|
|---|
| 42 | URL to link to.
|
|---|
| 43 |
|
|---|
| 44 | #### options
|
|---|
| 45 |
|
|---|
| 46 | Type: `object`
|
|---|
| 47 |
|
|---|
| 48 | ##### fallback
|
|---|
| 49 |
|
|---|
| 50 | Type: `Function | boolean`
|
|---|
| 51 |
|
|---|
| 52 | Override the default fallback. The function receives the `text` and `url` as parameters and is expected to return a string.
|
|---|
| 53 |
|
|---|
| 54 | If set to `false`, the fallback will be disabled when a terminal is unsupported.
|
|---|
| 55 |
|
|---|
| 56 | ### terminalLink.isSupported
|
|---|
| 57 |
|
|---|
| 58 | Type: `boolean`
|
|---|
| 59 |
|
|---|
| 60 | Check whether the terminal's stdout supports links.
|
|---|
| 61 |
|
|---|
| 62 | Prefer just using the default fallback or the `fallback` option whenever possible.
|
|---|
| 63 |
|
|---|
| 64 | ### terminalLink.stderr(text, url, options?)
|
|---|
| 65 |
|
|---|
| 66 | Create a link for use in stdout.
|
|---|
| 67 |
|
|---|
| 68 | Same arguments as `terminalLink()`.
|
|---|
| 69 |
|
|---|
| 70 | ### terminalLink.stderr.isSupported
|
|---|
| 71 |
|
|---|
| 72 | Type: `boolean`
|
|---|
| 73 |
|
|---|
| 74 | Check whether the terminal's stderr supports links.
|
|---|
| 75 |
|
|---|
| 76 | Prefer just using the default fallback or the `fallback` option whenever possible.
|
|---|
| 77 |
|
|---|
| 78 | ## Related
|
|---|
| 79 |
|
|---|
| 80 | - [terminal-link-cli](https://github.com/sindresorhus/terminal-link-cli) - CLI for this module
|
|---|
| 81 | - [ink-link](https://github.com/sindresorhus/ink-link) - Link component for Ink
|
|---|
| 82 | - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|---|