Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 31, 2019
1 parent a12b4c8 commit 03c09de
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
33 changes: 26 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
/// <reference types="node"/>
import {IncomingMessage} from 'http';

/**
* Decompress a HTTP response if needed.
*
* @param response - The HTTP incoming stream with compressed data.
* @returns The decompressed HTTP response stream.
*/
export default function decompressResponse(response: IncomingMessage): IncomingMessage;
declare const decompressResponse: {
/**
Decompress a HTTP response if needed.
@param response - The HTTP incoming stream with compressed data.
@returns The decompressed HTTP response stream.
@example
```
import {http} from 'http';
import decompressResponse = require('decompress-response');
http.get('https://sindresorhus.com', response => {
response = decompressResponse(response);
});
```
*/
(response: IncomingMessage): IncomingMessage;

// TODO: remove this in the next major version, refactor the whole definition to:
// declare function decompressResponse(response: IncomingMessage): IncomingMessage;
// export = decompressResponse;
default: typeof decompressResponse;
};

export = decompressResponse;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ const decompressResponse = response => {
};

module.exports = decompressResponse;
// TODO: remove this in the next major version
module.exports.default = decompressResponse;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as http from 'http';
import {expectType} from 'tsd-check';
import decompressResponse from '.';
import {expectType} from 'tsd';
import decompressResponse = require('.');

http.get('localhost', response => {
expectType<http.IncomingMessage>(decompressResponse(response));
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 @@ -40,11 +40,11 @@
"mimic-response": "^2.0.0"
},
"devDependencies": {
"@types/node": "^11.10.5",
"ava": "^1.3.1",
"@types/node": "^11.12.2",
"ava": "^1.4.1",
"get-stream": "^5.0.0",
"pify": "^4.0.1",
"tsd-check": "^0.3.0",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit 03c09de

Please sign in to comment.