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

@mountainpass/addressr-core

v0.7.0

Published

Framework-agnostic HATEOAS client and types for Australian address search via Addressr

Readme

@mountainpass/addressr-core

Framework-agnostic HATEOAS client for the Addressr Australian address API. Use this to build your own address search UI in any framework, or pair it with a framework package:

Install

npm install @mountainpass/addressr-core

Usage

import { createAddressrClient, parseHighlight } from '@mountainpass/addressr-core';

const client = createAddressrClient({
  apiUrl: 'https://api.addressr.io/',
  // Or use RapidAPI:
  // apiKey: 'your-rapidapi-key',
});

// Search
const page = await client.searchAddresses('1 george st');
console.log(page.results);   // AddressSearchResult[]
console.log(page.nextLink);  // Link | null

// Paginate
if (page.nextLink) {
  const page2 = await client.fetchNextPage(page.nextLink);
}

// Get full detail
const detail = await client.getAddressDetail('GANSW123');
console.log(detail.structured);  // { street, locality, state, postcode, ... }
console.log(detail.geocoding);   // { latitude, longitude, ... }

// Safe highlight rendering
const segments = parseHighlight('<em>1</em> <em>GEORGE</em> ST');
// [{ text: '1', highlighted: true }, { text: ' ', highlighted: false }, ...]

API

createAddressrClient(options)

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | -- | RapidAPI key. Omit for direct API access. | | apiUrl | string | "https://addressr.p.rapidapi.com/" | API root URL | | apiHost | string | "addressr.p.rapidapi.com" | RapidAPI host header | | retry | RetryOptions \| false | { maxRetries: 2, baseDelayMs: 500, maxDelayMs: 5000 } | Retry config, or false to disable | | fetchImpl | typeof fetch | globalThis.fetch | Custom fetch (for testing) |

Returns an AddressrClient with:

| Method | Returns | Description | |--------|---------|-------------| | searchAddresses(query, signal?) | Promise<SearchPage<AddressSearchResult>> | Search addresses. Returns results + HATEOAS next link. | | searchPostcodes(query, signal?) | Promise<SearchPage<PostcodeSearchResult>> | Search postcodes. | | searchLocalities(query, signal?) | Promise<SearchPage<LocalitySearchResult>> | Search suburbs/towns. | | searchStates(query, signal?) | Promise<SearchPage<StateSearchResult>> | Search states/territories. | | fetchNextPage(nextLink, signal?) | Promise<SearchPage<T>> | Follow a next-page link relation. | | getAddressDetail(pid, signal?, searchPage?, index?) | Promise<AddressDetail> | Get full address detail. Follows canonical link when search context provided. |

SearchPage<T>

Generic over the result type. Defaults to AddressSearchResult for backward compatibility.

{
  results: T[];           // Array of search results
  nextLink: Link | null;  // HATEOAS link to next page, or null
}

Postcode, locality, and state search

In addition to searchAddresses, the client exposes three narrower search methods for when a form needs only a postcode, suburb, or state. Each shares the same HATEOAS root discovery, retry behaviour, and abort semantics as searchAddresses.

Postcodes

const page = await client.searchPostcodes('2000');
// page.results[0] is { postcode: '2000', localities: [{ name: 'SYDNEY' }, ...] }

Localities

const page = await client.searchLocalities('sydney');
// page.results[0] is { name: 'SYDNEY', state: { abbreviation: 'NSW', name: 'NEW SOUTH WALES' }, postcode: '2000', score, pid }

States

const page = await client.searchStates('NSW');
// page.results[0] is { name: 'NEW SOUTH WALES', abbreviation: 'NSW' }

RetryOptions

{
  maxRetries?: number;   // Default: 2
  baseDelayMs?: number;  // Default: 500 — exponential backoff base
  maxDelayMs?: number;   // Default: 5000 — backoff cap
}

Failed requests are retried with exponential backoff and jitter. Only network errors and 5xx responses are retried -- 4xx errors fail immediately. Pass retry: false to disable.

parseHighlight(html)

Safely parses Elasticsearch <em> highlight tags into segments. No innerHTML, no XSS.

parseHighlight(html: string): HighlightSegment[]
// HighlightSegment = { text: string; highlighted: boolean }

Architecture

  • HATEOAS -- API root discovery via RFC 8288 Link headers, no hardcoded paths
  • Pagination -- follows next link relations, accumulates results across pages
  • Canonical links -- getAddressDetail follows canonical link from search results when available, falls back to URL construction
  • Root caching -- API root fetched once per client instance
  • Abort support -- all methods accept AbortSignal for cancellation

License

Apache-2.0