Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(proposal): renovate to version 3 #28

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./demo
40 changes: 17 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,45 @@ module.exports = {
env: {
browser: true,
es6: true,
node: true
node: true,
},
extends: [
'airbnb-base',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: path.resolve(__dirname, './tsconfig.json')
project: path.resolve(__dirname, './tsconfig.json'),
},
plugins: [
'@typescript-eslint'
],
plugins: ['@typescript-eslint'],
rules: {
'lines-between-class-members': 'off'
'lines-between-class-members': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'import/prefer-default-export': 'off',
'import/extensions': 'off',
},
overrides: [
{
extends: [
'plugin:jest/recommended',
'plugin:jest/style'
],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
files: ['**/*.test.js', '**/*.test.ts'],
rules: {
// Import
'import/no-extraneous-dependencies': 'off'
'import/no-extraneous-dependencies': 'off',
},
env: {
jest: true
jest: true,
},
parserOptions: {
project: path.resolve(__dirname, './tsconfig.test.json')
project: path.resolve(__dirname, './tsconfig.test.json'),
},
}
},
],
settings: {
'import/resolver': {
node: {
extensions: [
'.js',
'.ts'
]
}
}
}
extensions: ['.js', '.ts'],
},
},
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ node_modules

# Build directory
lib

# IDE tools
.vscode
.idea
70 changes: 41 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ const IPData = require('ipdata').default;

Create an instance of the `IPData` class and pass your api key for IPData as the first parameter.

> Note: If using a .env file, set the `APIDATA_API_KEY=` variable for auto-detection.

```js
const ipdata = new IPData('<apiKey>');
```

The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second paramenter.
The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second parameter.

```js
const cacheConfig = {
max: 1000, // max size
maxAge: 10 * 60 * 1000, // max age in ms (i.e. 10 minutes)
max: 1000, // max size
maxAge: 10 * 60 * 1000, // max age in ms (i.e. 10 minutes)
};
const ipdata = new IPData('<apiKey>', cacheConfig);
```
Expand All @@ -57,7 +59,7 @@ const ipdata = new IPData('<apiKey>', cacheConfig);

```js
const cacheConfig = {
maxAge: -1, // disable the cache
maxAge: -1, // disable the cache
};
const ipdata = new IPData('<apiKey>', cacheConfig);
```
Expand All @@ -68,44 +70,44 @@ The library will lookup the ip address of the host computer if no ip address is

```js
ipdata.lookup()
.then(function(info) {
// info.ip === '<hostcomputerip>'
// ...
});
.then(function (info) {
// info.ip === '<hostcomputerip>'
// ...
});
```

You can pass an ip address as the first parameter to the `lookup()` method to lookup information about the ip address using IPData.

```js
const ip = '1.1.1.1';
ipdata.lookup(ip)
.then(function(info) {
// info.ip === 1.1.1.1
// ...
});
.then(function (info) {
// info.ip === 1.1.1.1
// ...
});
```

You can specify only a select field to be returned when looking up an ip address by passing a field as the second parameter to the `lookup()` method.

```js
const ip = '1.1.1.1';
const selectField = 'ip';
ipdata.lookup(ip, selectField)
.then(function(info) {
// info.select_field === 1.1.1.1
// ...
});
ipdata.lookup({ ip, selectField })
.then(function (info) {
// info.select_field === 1.1.1.1
// ...
});
```

You can specify only certain fields to be returned when looking up an ip address by passing an array of fields as the third parameter to the `lookup()` method.

```js
const ip = '1.1.1.1';
const fields = ['ip', 'city'];
ipdata.lookup(ip, null, fields)
.then(function(info) {
// ...
});
ipdata.lookup({ ip, fields })
.then(function (info) {
// ...
});
```

### Bulk Lookup
Expand All @@ -115,19 +117,29 @@ You can lookup multiple ip addresses with one API call using the `bulkLookup()`
```js
const ips = ['1.1.1.1', '1.0.0.1'];
ipdata.bulkLookup(ips)
.then(function(info) {
// info[0].ip === 1.1.1.1
// ...
});
.then(function (info) {
// info[0].ip === 1.1.1.1
// ...
});
```

You can specify only certain fields to be returned when looking up multiple ip addresses by passing an array of fields as the second parameter to the `bulkLookup()` method.

```js
const ips = ['1.1.1.1', '1.0.0.1'];
const fields = ['ip', 'city'];
ipdata.bulkLookup(ips, fields)
.then(function(info) {
// ...
});
ipdata.bulkLookup({ ips, fields })
.then(function (info) {
// ...
});
```

## Executable

An `lookup` executable is provided which can be accessed by running `npm link` on the project directory.

```bash
$ npm link
$ lookup 1.1.1.1 <API-KEY> # If not using .env file.
$ lookup 1.1.1.1 # If using .env file.
```
11 changes: 11 additions & 0 deletions bin/lookup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

(async () => {
const args = process.argv.slice(2)
const { IPData } = require("../lib/ipdata")
const ip = args[0] || undefined
const apiKey = args[1] || undefined
const ipdata = await new IPData(apiKey)
const lookup = await ipdata.lookup(ip)
console.log(`IPData lookup result: `, lookup)
})()
3 changes: 3 additions & 0 deletions bin/lookup.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\lookup" %*
Loading