Skip to content

Commit

Permalink
Allow fallback to be true (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinking authored and sindresorhus committed Dec 18, 2019
1 parent 0ae83a2 commit 25ba62a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare namespace terminalLink {
@default `${text} (${url})`
*/
fallback?: ((text: string, url: string) => string) | false;
fallback?: ((text: string, url: string) => string) | boolean;
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const terminalLink = (text, url, {target = 'stdout', ...options} = {}) => {
return text;
}

return options.fallback ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)`;
return typeof options.fallback === 'function' ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)`;
}

return ansiEscapes.link(text, url);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Type: `object`

##### fallback

Type: `Function | false`
Type: `Function | boolean`

Override the default fallback. The function receives the `text` and `url` as parameters and is expected to return a string.

Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ test('disabled fallback', t => {
t.is(actual, 'My Website');
});

test('explicitly enabled fallback', t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = require('.');

const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: true
});
console.log(actual);
t.is(actual, 'My Website (\u200Bhttps://sindresorhus.com\u200B)');
});

test('stderr default fallback', t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = require('.');
Expand Down

0 comments on commit 25ba62a

Please sign in to comment.