ipquery
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

🌐 ipquery-js

What is IPQuery?

A very cool service for fetching information about IP addresses.

Disclaimer

This package is not affiliated, associated neither endorsed by IPQuery.

Install

# npm
npm install ipquery

# pnpm
pnpm add ipquery

# yarn
yarn add ipquery

Usage

Fetching your own ip

import { ip } from 'ipquery'

const myself = async () => await ip.query("self")

Fetching an specific ip

import { ip } from 'ipquery'

const processPayment = async (customer: Customer) => {
    
    const ipAddress = await ip.query(customer.ip)

    const timezone = ip.location.timezone

    ...
}

Bulk requesting ips (up to 10k)

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
}

Response formatting

import { ip } from 'ipquery'

const getYamlIp = async (ipAddress: string) => {
    const yamlText = await ip.query(ipAddress, { format: "yaml" })

    return yamlText
}

Caching

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.

Package Sidebar

Install

npm i ipquery

Weekly Downloads

19

Version

0.0.2

License

MIT

Unpacked Size

8.96 kB

Total Files

5

Last publish

Collaborators

  • fernando_coelho