Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent c6c7145 commit 27ce0b6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
36 changes: 27 additions & 9 deletions index.d.ts
@@ -1,9 +1,27 @@
/**
* Copy text to the clipboard.
*
* Must be called in response to a user gesture event, like `click` or `keyup`.
*
* @param text - The text to copy to clipboard.
* @returns Whether it succeeded to copy the text.
*/
export default function copyTextToClipboard(text: string): boolean;
declare const copyTextToClipboard: {
/**
Copy text to the clipboard.
Must be called in response to a user gesture event, like `click` or `keyup`.
@param text - The text to copy to clipboard.
@returns Whether it succeeded to copy the text.
@example
```
import copy = require('copy-text-to-clipboard');
button.addEventListener('click', () => {
copy('🦄🌈');
});
```
*/
(text: string): boolean;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function copyTextToClipboard(text: string): boolean;
// export = copyTextToClipboard;
default: typeof copyTextToClipboard;
};

export = copyTextToClipboard;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -42,4 +42,5 @@ const copyTextToClipboard = input => {
};

module.exports = copyTextToClipboard;
// TODO: Remove this for the next major release
module.exports.default = copyTextToClipboard;
4 changes: 2 additions & 2 deletions index.test-d.ts
@@ -1,4 +1,4 @@
import {expectType} from 'tsd-check';
import copyTextToClipboard from '.';
import {expectType} from 'tsd';
import copyTextToClipboard = require('.');

expectType<boolean>(copyTextToClipboard('🦄🌈'));
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && tsd-check"
"test": "xo && tsd"
},
"files": [
"index.js",
Expand All @@ -28,7 +28,7 @@
"modern"
],
"devDependencies": {
"tsd-check": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"xo": {
Expand Down

0 comments on commit 27ce0b6

Please sign in to comment.