npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@batchbird/geo

v1.0.5

Published

A lightweight Next.js package for fetching IP geolocation data from external APIs

Readme

@batchbird/geo

A lightweight Next.js package for fetching IP geolocation data and device information from Vercel headers and user agent parsing.

Features

  • Get complete IP geolocation data (IP, country, continent, city, region, timezone)
  • Device type detection based on screen dimensions
  • User agent parsing for browser, device, and OS information
  • Additional geolocation data (latitude, longitude, postal code, ISP, organization, ASN)
  • TypeScript support
  • Zero external API dependencies
  • Simple and easy to use

Installation

npm install @batchbird/geo
# or
yarn add @batchbird/geo
# or
pnpm add @batchbird/geo

Usage

Get Complete IP and Device Information

import { getGeo } from "@batchbird/geo";

// In a route handler
export async function GET(request: Request) {
  try {
    // Pass screen dimensions as a string (e.g., "1920x1080") or object
    const geoInfo = await getGeo(request, "1920x1080");
    return Response.json(geoInfo);
  } catch (error) {
    return Response.json({ error: "Failed to fetch IP info" }, { status: 500 });
  }
}

Get Device Type Only

import { getDeviceType } from "@batchbird/geo";

// Detect device type from screen dimensions
const deviceType = getDeviceType({ screen: "1920x1080" });
// Returns: "desktop", "laptop", "tablet", "mobile", "watch", or "ultra-wide-desktop"

The getGeo() function returns an object with the following properties:

Core IP Information

  • ip: IP address (from x-forwarded-for or x-real-ip headers)
  • country: Country code (from x-vercel-ip-country header)
  • continent: Continent name (derived from country code)
  • city: City name (from x-vercel-ip-city header)
  • region: Region/State name (from x-vercel-ip-country-region header)
  • timezone: Timezone identifier (from x-vercel-ip-timezone header)

Additional Geolocation Data

  • latitude: Latitude coordinate (from x-vercel-ip-latitude header)
  • longitude: Longitude coordinate (from x-vercel-ip-longitude header)
  • postalCode: Postal/ZIP code (from x-vercel-ip-postal-code header)
  • isp: Internet Service Provider (from x-vercel-ip-isp header)
  • org: Organization (from x-vercel-ip-org header)
  • asn: Autonomous System Number (from x-vercel-ip-asn header)

Device and Browser Information

  • userAgent: Raw user agent string
  • deviceType: Detected device type based on screen dimensions
  • browser: Browser name (parsed from user agent)
  • device: Device type (parsed from user agent)
  • os: Operating system (parsed from user agent)

Example Response

{
  "ip": "192.168.1.1",
  "country": "US",
  "continent": "North America",
  "city": "San Francisco",
  "region": "California",
  "timezone": "America/Los_Angeles",
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...",
  "deviceType": "desktop",
  "browser": "Chrome",
  "device": "desktop",
  "os": "Mac OS",
  "latitude": "37.7749",
  "longitude": "-122.4194",
  "postalCode": "94102",
  "isp": "Cloudflare, Inc.",
  "org": "Cloudflare, Inc.",
  "asn": "AS13335"
}

Screen Parameter Format

The screen parameter accepts multiple formats:

// String format: "widthxheight"
await getGeo(request, "1920x1080");
await getGeo(request, "375x667");

// Object format: { width: number, height: number }
await getGeo(request, { width: 1920, height: 1080 });
await getGeo(request, { width: 375, height: 667 });

Device Type Detection

The package automatically detects device types based on screen dimensions:

  • watch: ≤ 320x320
  • mobile: ≤ 900x480 (aspect ratio < 2.5)
  • tablet: ≤ 1200x1000 (aspect ratio < 1.7)
  • laptop: ≤ 1600x700 (aspect ratio < 2.0)
  • desktop: ≤ 2560x900 (aspect ratio < 2.5)
  • ultra-wide-desktop: > 2560x1440 or high aspect ratio

Error Handling

The function includes proper error handling for invalid screen inputs and missing data:

import { getGeo } from "@batchbird/geo";

export async function GET(request: Request) {
  try {
    const geoInfo = await getGeo(request, "1920x1080");
    return Response.json(geoInfo);
  } catch (error) {
    console.error("IP info fetch failed:", error);
    return Response.json(
      {
        error: "Failed to fetch IP information",
        details: error instanceof Error ? error.message : "Unknown error",
      },
      { status: 500 }
    );
  }
}

Requirements

  • Next.js 13 or later
  • Vercel deployment (for IP geolocation headers)
  • Node.js 18+ (for fetch API support)

Dependencies

  • ua-parser-js: For parsing user agent strings

License

MIT