From a649623a8b35b62553b36e41017d700db8095249 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sat, 6 Apr 2019 11:18:58 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#6) --- index.d.ts | 62 ++++++++++++++++++++++++++++++++----------------- index.js | 1 + index.test-d.ts | 14 ++++++----- package.json | 12 +++++----- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/index.d.ts b/index.d.ts index f0d1085..fc87019 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; diff --git a/index.js b/index.js index ef25fbe..5e41eaf 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/index.test-d.ts b/index.test-d.ts index e1eb962..bc8b98b 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,10 +1,12 @@ -import {expectType} from 'tsd-check'; -import terminalLink, {isSupported} from '.'; +import {expectType} from 'tsd'; +import terminalLink = require('.'); expectType(terminalLink('text', 'url')); -expectType(terminalLink('text', 'url', { - fallback: (text, url) => `[${text}](${url})` -})); +expectType( + terminalLink('text', 'url', { + fallback: (text, url) => `[${text}](${url})` + }) +); -expectType(isSupported); +expectType(terminalLink.isSupported); diff --git a/package.json b/package.json index 5f85df7..9d3836f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -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" } }