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 7548b77 commit 31ab056
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
60 changes: 34 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare namespace internalIp {
interface v6 {
/**
* @returns The IPv6 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
Expand All @@ -7,19 +7,20 @@ declare namespace internalIp {
* console.log(await internalIp.v6());
* //=> 'fe80::1'
*/
export function v6(): Promise<string>;
export namespace v6 {
/**
* @returns The IPv6 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v6.sync());
* //=> 'fe80::1'
*/
function sync(): string;
}
(): Promise<string>;

/**
* @returns The IPv6 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v6.sync());
* //=> 'fe80::1'
*/
sync(): string;
}

interface v4 {
/**
* @returns The IPv4 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
Expand All @@ -28,18 +29,25 @@ declare namespace internalIp {
* console.log(await internalIp.v4())
* //=> '10.0.0.79'
*/
export function v4(): Promise<string>;
export namespace v4 {
/**
* @returns The IPv4 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v4.sync())
* //=> '10.0.0.79'
*/
function sync(): string;
}
(): Promise<string>;

/**
* @returns The IPv4 address of the internet-facing interface, as determined from the default gateway. When the address cannot be determined for any reason, `null` will be returned.
*
* @example
*
* console.log(internalIp.v4.sync())
* //=> '10.0.0.79'
*/
sync(): string;
}

export default internalIp;
declare const internalIp: {
v6: v6;
v4: v4;

// TODO: Remove this for the next major release
default: typeof internalIp;
};

export = internalIp;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ internalIp.v6.sync = () => sync('v6');
internalIp.v4.sync = () => sync('v4');

module.exports = internalIp;
// TODO: Remove this for the next major release
module.exports.default = internalIp;
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 internalIp from '.';
import {expectType} from 'tsd';
import internalIp = require('.');

expectType<string>(await internalIp.v4());
expectType<string>(await internalIp.v6());
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": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -32,12 +32,12 @@
"gateway"
],
"dependencies": {
"default-gateway": "^4.0.1",
"default-gateway": "^4.2.0",
"ipaddr.js": "^1.9.0"
},
"devDependencies": {
"ava": "^1.2.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit 31ab056

Please sign in to comment.