ipquery
Version:
ipquery sdk for javascript
80 lines (49 loc) • 1.38 kB
Markdown
//ipquery.io/) for fetching information about IP addresses.
This package is not affiliated, associated neither endorsed by [IPQuery](https://github.com/ipqwery).
```bash
npm install ipquery
pnpm add ipquery
yarn add ipquery
```
```ts
import { ip } from 'ipquery'
const myself = async () => await ip.query("self")
```
```ts
import { ip } from 'ipquery'
const processPayment = async (customer: Customer) => {
const ipAddress = await ip.query(customer.ip)
const timezone = ip.location.timezone
...
}
```
```ts
import { ip } from 'ipquery'
const getUsersTimezones = async (users: User[]) => {
const ips = await ip.query(users.map(u => u.ip))
const timezones = ips.map(ip => ip.location.timezone)
return timezones
}
```
```ts
import { ip } from 'ipquery'
const getYamlIp = async (ipAddress: string) => {
const yamlText = await ip.query(ipAddress, { format: "yaml" })
return yamlText
}
```
By default, `ip.query` will cache no more than 100 items, and it will clear after 5 minutes.
You can config or opt out the caching by using `ip.config({ cache })` somewhere in your app.
A [very cool service](https: