-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor TypeScript definition to CommonJS compatible export (#6)
- Loading branch information
1 parent
543f190
commit a649623
Showing
4 changed files
with
56 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
export interface Options { | ||
/** | ||
* Override the default fallback. | ||
* | ||
* @default `${text} (${url})` | ||
*/ | ||
fallback?: (text: string, url: string) => string; | ||
declare namespace terminalLink { | ||
interface Options { | ||
/** | ||
Override the default fallback. | ||
@default `${text} (${url})` | ||
*/ | ||
fallback?: (text: string, url: string) => string; | ||
} | ||
} | ||
|
||
/** | ||
* Create a clickable link in the terminal. | ||
* | ||
* [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)`. | ||
*/ | ||
export default function terminalLink(text: string, url: string, options?: Options): string; | ||
|
||
/** | ||
* Check whether the terminal support links. | ||
* | ||
* Prefer just using the default fallback or the `fallback` option whenever possible. | ||
*/ | ||
export const isSupported: boolean; | ||
declare const terminalLink: { | ||
/** | ||
Create a clickable link in the terminal. | ||
[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('My Website', 'https://sindresorhus.com'); | ||
console.log(link); | ||
``` | ||
*/ | ||
(text: string, url: string, options?: terminalLink.Options): string; | ||
|
||
/** | ||
Check whether the terminal support links. | ||
Prefer just using the default fallback or the `fallback` option whenever possible. | ||
*/ | ||
readonly isSupported: boolean; | ||
|
||
// TODO: Remove this for the next major release | ||
default: typeof terminalLink; | ||
}; | ||
|
||
export = terminalLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import {expectType} from 'tsd-check'; | ||
import terminalLink, {isSupported} from '.'; | ||
import {expectType} from 'tsd'; | ||
import terminalLink = require('.'); | ||
|
||
expectType<string>(terminalLink('text', 'url')); | ||
|
||
expectType<string>(terminalLink('text', 'url', { | ||
fallback: (text, url) => `[${text}](${url})` | ||
})); | ||
expectType<string>( | ||
terminalLink('text', 'url', { | ||
fallback: (text, url) => `[${text}](${url})` | ||
}) | ||
); | ||
|
||
expectType<boolean>(isSupported); | ||
expectType<boolean>(terminalLink.isSupported); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters