Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jun 16, 2019
1 parent a6d6a69 commit e4aa60c
Show file tree
Hide file tree
Showing 6 changed files with 3,707 additions and 2,210 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- '7'
- '6'
- '8'
27 changes: 15 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
'use strict'

// Packages
const got = require('got')

module.exports = () =>
got('https://ipinfo.io/json')
.then(res => {
const json = JSON.parse(res.body)
const lat = json.loc.split(',')[0]
const long = json.loc.split(',')[1]
const data = Object.assign({}, json, { lat, long })
const wer = async () => {
try {
const { body } = await got('https://ipinfo.io/json')
const json = JSON.parse(body)
const lat = json.loc.split(',')[0]
const long = json.loc.split(',')[1]
const data = Object.assign({}, json, { lat, long })

return data
} catch (error) {
throw new TypeError(error)
}
}

return data
})
.catch(err => err)
module.exports = wer
43 changes: 31 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,49 @@
"version": "1.0.0",
"description": "Get your geolocation information",
"main": "index.js",
"repository": "git@github.com:bukinoshita/wer.git",
"repository": "bukinoshita/wer",
"author": "Bu Kinoshita <bukinoshita@gmail.com>",
"license": "MIT",
"dependencies": {
"got": "^6.7.1"
},
"devDependencies": {
"ava": "^0.19.1",
"eslint-config-prettier": "^2.6.0",
"xo": "^0.18.1"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"wer",
"where",
"location",
"geolocation",
"ip"
],
"scripts": {
"test": "ava",
"lint": "xo"
},
"dependencies": {
"got": "^9.6.0"
},
"devDependencies": {
"ava": "^2.1.0",
"eslint-config-prettier": "^5.0.0",
"husky": "^2.4.1",
"lint-staged": "^8.2.1",
"prettier": "^1.18.2",
"xo": "^0.24.0"
},
"xo": {
"extends": [
"prettier"
]
},
"lint-staged": {
"*.js": [
"prettier --semi false --single-quote --write",
"yarn lint",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
10 changes: 2 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,43 @@

> Get your geolocation information :round_pushpin:

## Install

```
$ yarn add wer
```


## Usage

```js
const wer = require('wer')

wer().then(res => res)
await wer()

/*{
ip: '<ip>',
hostname: '<hostname>',
city: '<city>',
region: '<region>',
country: '<country>',
loc: '<loc>',
hostname: '<hostname>',
org: '<org>',
postal: '<postal>',
lat: '<lat>',
long: '<long>'
}*/
```


## API

### wer()

Returns a promise


## Related

- [starbucks-cli](https://github.com/bukinoshita/starbucks-cli) — Starbucks on Command Line
- [has-uber-cli](https://github.com/bukinoshita/has-uber-cli) — Check if Uber is available in your city with CLI


## License

MIT © [Bu Kinoshita](https://bukinoshita.io)
20 changes: 6 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
'use strict'

// Packages
import test from 'ava'

// Root
import wer from '.'

test(async t => {
const result = await wer().then(res => res)
const { ip, hostname, city, region, country, org, postal, lat, long } = result
test('it should get ip', async t => {
const result = await wer()

t.truthy(ip)
t.truthy(hostname)
t.truthy(city)
t.truthy(region)
t.truthy(org)
t.truthy(country)
t.truthy(postal)
t.truthy(lat)
t.truthy(long)
t.truthy(result)
})
Loading

0 comments on commit e4aa60c

Please sign in to comment.