Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 6, 2019
1 parent a6ded92 commit 2256dca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
40 changes: 31 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import {Options} from 'filenamify';
import {Options as FilenamifyOptions} from 'filenamify';

/**
* Convert a URL to a valid filename.
*
* @param input - A URL to convert to a valid filename.
* @returns A valid filename for `input`.
*/
export default function filenamifyUrl(input: string, options?: Options): string;
declare namespace filenamifyUrl {
type Options = FilenamifyOptions;
}

export {Options} from 'filenamify';
declare const filenamifyUrl: {
/**
Convert a URL to a valid filename.
@param input - A URL to convert to a valid filename.
@returns A valid filename for `input`.
@example
```
import filenamifyUrl = require('filenamify-url');
filenamifyUrl('http://sindresorhus.com/foo?bar=baz');
//=> 'sindresorhus.com!foo!bar=baz'
filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'});
//=> 'sindresorhus.com🐴foo'
```
*/
(input: string, options?: filenamifyUrl.Options): string;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function filenamifyUrl(input: string, options?: Options): string;
// export = filenamifyUrl;
default: typeof filenamifyUrl;
};

export = filenamifyUrl;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const filenamifyUrl = (string, options) => {
};

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

expectType<string>(filenamifyUrl('http://sindresorhus.com/foo?bar=baz'));
expectType<string>(
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -31,12 +31,12 @@
"uri"
],
"dependencies": {
"filenamify": "^3.0.0",
"filenamify": "^4.0.0",
"humanize-url": "^2.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit 2256dca

Please sign in to comment.