Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 18, 2019
1 parent b87e5d2 commit cee7633
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sudo: false
language: node_js
node_js:
- '6'
- '4'
- '10'
- '8'
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
declare namespace ipify {
interface Options {
/**
Custom API endpoint.
@default 'https://api.ipify.org'
*/
readonly endpoint?: string;
}
}

/**
Get your public IP address.
@returns The IP address.
@example
```
import ipify = require('ipify');
(async => {
console.log(await ipify());
//=> '82.142.31.236'
})();
```
*/
declare function ipify(options?: ipify.Options): Promise<string>;

export = ipify;
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
'use strict';
const got = require('got');

module.exports = endpoint => got(endpoint || 'https://api.ipify.org').then(res => res.body);
module.exports = async options => {
options = {
endpoint: 'https://api.ipify.org',
...options
};

const {body} = await got(options.endpoint);
return body;
};
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {expectType} from 'tsd';
import ipify = require('.');

const options: ipify.Options = {};
expectType<Promise<string>>(ipify());
expectType<Promise<string>>(ipify({endpoint: 'https://example.com'}));
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75 changes: 38 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
{
"name": "ipify",
"version": "2.0.0",
"description": "Get your public IP address",
"license": "MIT",
"repository": "sindresorhus/ipify",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"ip",
"ipv4",
"ipv6",
"address",
"public",
"external",
"own"
],
"dependencies": {
"got": "^6.7.1",
"meow": "^3.3.0"
},
"devDependencies": {
"ava": "*",
"is-ip": "^2.0.0",
"xo": "*"
}
"name": "ipify",
"version": "2.0.0",
"description": "Get your public IP address",
"license": "MIT",
"repository": "sindresorhus/ipify",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"ip",
"ipv4",
"ipv6",
"address",
"public",
"external",
"own"
],
"dependencies": {
"got": "^9.6.0"
},
"devDependencies": {
"ava": "^1.4.1",
"is-ip": "^3.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
18 changes: 11 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Using the [`ipify` API](https://www.ipify.org) or a [custom `ipify` instance](ht
## Install

```
$ npm install --save ipify
$ npm install ipify
```


Expand All @@ -17,23 +17,27 @@ $ npm install --save ipify
```js
const ipify = require('ipify');

ipify().then(ip => {
console.log(ip);
(async => {
console.log(await ipify());
//=> '82.142.31.236'
});
})();
```


## API

### ipify([endpoint])
### ipify([options])

Returns a `Promise` for the IP address.

#### endpoint
#### options

Type: `object`

##### endpoint

Type: `string`<br>
Default: `https://api.ipify.org`
Default: `'https://api.ipify.org'`

Custom API endpoint.

Expand Down
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import test from 'ava';
import isIp from 'is-ip';
import m from '.';
import ipify from '.';

test(async t => {
t.true(isIp(await m()));
t.true(isIp(await m('https://api.ipify.org')));
test('main', async t => {
t.true(isIp(await ipify()));
t.true(isIp(await ipify({endpoint: 'https://api.ipify.org'})));
});

0 comments on commit cee7633

Please sign in to comment.