terminal-link
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -14,3 +14,3 @@ declare namespace terminalLink { | ||
/** | ||
Create a clickable link in the terminal. | ||
Create a clickable link in the terminal's stdout. | ||
@@ -34,3 +34,3 @@ [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) | ||
/** | ||
Check whether the terminal support links. | ||
Check whether the terminal supports links. | ||
@@ -41,6 +41,31 @@ Prefer just using the default fallback or the `fallback` option whenever possible. | ||
// TODO: Remove this for the next major release | ||
default: typeof terminalLink; | ||
readonly stderr: { | ||
/** | ||
Create a clickable link in the terminal's stderr. | ||
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) | ||
For unsupported terminals, the link will be printed in parens after the text: `My website (https://sindresorhus.com)`. | ||
@param text - Text to linkify. | ||
@param url - URL to link to. | ||
@example | ||
``` | ||
import terminalLink = require('terminal-link'); | ||
const link = terminalLink.stderr('My Website', 'https://sindresorhus.com'); | ||
console.error(link); | ||
``` | ||
*/ | ||
(text: string, url: string, options?: terminalLink.Options): string; | ||
/** | ||
Check whether the terminal's stderr supports links. | ||
Prefer just using the default fallback or the `fallback` option whenever possible. | ||
*/ | ||
readonly isSupported: boolean; | ||
} | ||
}; | ||
export = terminalLink; |
13
index.js
@@ -5,5 +5,5 @@ 'use strict'; | ||
module.exports = (text, url, options = {}) => { | ||
if (!supportsHyperlinks.stdout) { | ||
return options.fallback ? options.fallback(text, url) : `${text} (${url})`; | ||
const terminalLink = (text, url, {target = 'stdout', ...options} = {}) => { | ||
if (!supportsHyperlinks[target]) { | ||
return options.fallback ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)`; | ||
} | ||
@@ -14,4 +14,7 @@ | ||
// TODO: Remove this for the next major release | ||
module.exports.default = module.exports; | ||
module.exports = (text, url, options = {}) => terminalLink(text, url, options); | ||
module.exports.stderr = (text, url, options = {}) => terminalLink(text, url, {target: 'stderr', ...options}); | ||
module.exports.isSupported = supportsHyperlinks.stdout; | ||
module.exports.stderr.isSupported = supportsHyperlinks.stderr; |
{ | ||
"name": "terminal-link", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "Create clickable links in the terminal", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
@@ -35,11 +35,11 @@ "scripts": { | ||
"dependencies": { | ||
"ansi-escapes": "^3.2.0", | ||
"supports-hyperlinks": "^1.0.1" | ||
"ansi-escapes": "^4.2.1", | ||
"supports-hyperlinks": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"clear-module": "^3.1.0", | ||
"tsd": "^0.7.2", | ||
"ava": "^2.3.0", | ||
"clear-module": "^4.0.0", | ||
"tsd": "^0.7.4", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -27,4 +27,6 @@ # terminal-link [![Build Status](https://travis-ci.org/sindresorhus/terminal-link.svg?branch=master)](https://travis-ci.org/sindresorhus/terminal-link) | ||
### terminalLink(text, url, [options]) | ||
### terminalLink(text, url, options?) | ||
Create a link for use in stdout. | ||
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) | ||
@@ -48,3 +50,3 @@ | ||
Type: `Object` | ||
Type: `object` | ||
@@ -61,7 +63,21 @@ ##### fallback | ||
Check whether the terminal support links. | ||
Check whether the terminal's stdout supports links. | ||
Prefer just using the default fallback or the `fallback` option whenever possible. | ||
### terminalLink.stderr(text, url, options?) | ||
Create a link for use in stdout. | ||
Same arguments as `terminalLink()`. | ||
### terminalLink.stderr.isSupported | ||
Type: `boolean` | ||
Check whether the terminal's stderr supports links. | ||
Prefer just using the default fallback or the `fallback` option whenever possible. | ||
## Related | ||
@@ -72,6 +88,1 @@ | ||
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
6084
65
85
+ Addedansi-escapes@4.3.2(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsupports-hyperlinks@2.3.0(transitive)
+ Addedtype-fest@0.21.3(transitive)
- Removedansi-escapes@3.2.0(transitive)
- Removedhas-flag@2.0.03.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-hyperlinks@1.0.1(transitive)
Updatedansi-escapes@^4.2.1
Updatedsupports-hyperlinks@^2.0.0