Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fallback to be true #14

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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