Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 6, 2019
1 parent 543f190 commit a649623
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
62 changes: 41 additions & 21 deletions index.d.ts
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;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = (text, url, options = {}) => {
return ansiEscapes.link(text, url);
};

// TODO: Remove this for the next major release
module.exports.default = module.exports;
module.exports.isSupported = supportsHyperlinks.stdout;
14 changes: 8 additions & 6 deletions index.test-d.ts
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);
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -31,13 +31,13 @@
"command-line"
],
"dependencies": {
"ansi-escapes": "^3.1.0",
"ansi-escapes": "^3.2.0",
"supports-hyperlinks": "^1.0.1"
},
"devDependencies": {
"ava": "^1.0.1",
"clear-module": "^3.0.0",
"tsd-check": "^0.2.1",
"xo": "^0.23.0"
"ava": "^1.4.1",
"clear-module": "^3.1.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit a649623

Please sign in to comment.