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

@br-geo-kit/core

v1.0.0

Published

Shared contracts, types and helpers for br-geo-kit packages

Readme

@br-geo-kit/core

The contracts every other package in the kit implements. No data, no network.

pnpm add @br-geo-kit/core

You usually do not install this directly — @br-geo-kit/cep, @br-geo-kit/ibge and the providers depend on it and re-export what you need. Install it when you are writing a provider or a cache.


What is in it

The canonical Address. Every provider is normalized into this one shape. ProviderAddress is the same thing minus source and cached, which are the resolver's to set — a provider that could set source could lie about which provider answered.

CepProvider. Three outcomes, and keeping them apart is the contract: return a ProviderAddress, return null when the service says the CEP does not exist, and throw when it is down, rate-limited, or answered with something unreadable. See adding a provider.

CepCache, plus memoryCache (bounded, TTL'd, LRU, with negative entries) and noopCache.

The error hierarchy, all inheriting from BrGeoKitError so one catch distinguishes kit failures from unrelated ones. Each carries structured fields as well as a message.

CEP helpers.

normalizeCep('01.310-100')   // '01310100'
normalizeCep(1310100)        // '01310100' — the zero a spreadsheet dropped
normalizeCep('01310-100abc') // null — a data error, not a CEP
formatCep('01310100')        // '01310-100'
maskCep('013101')            // '01310-1' — progressive, for an input
assertCep('nope')            // throws InvalidCepError

State helpers.

toUF(' sp ')            // 'SP'
toUF('São Paulo')       // null — that is stateByName's job
stateByName('sao paulo')// 'SP'
stateCode('SP')         // '35'
stateByCode('35')       // 'SP'
stateRegion('SP')       // 'SE'

fetchJson, which does what a provider would otherwise repeat: uses the injected fetch and abort signal, maps the statuses you list to null, throws for everything else, re-throws an abort untouched so the resolver can label it a timeout, and throws rather than parsing an HTML error page served with a 200.

SearchIndex, normalizeText and tokenize — accent-, case- and punctuation-insensitive matching with AND semantics.

distanceBetween, haversine, in metres. Returns null rather than NaN for a missing or out-of-range point, because a NaN propagates through a sort and silently reorders a list of nearby stores.


Two entry points

import { normalizeCep } from '@br-geo-kit/core'        // browser-safe
import { loadFromDisk } from '@br-geo-kit/core/node'   // Node only

node:fs lives behind the /node subpath and nowhere else, so a bundler never has to follow an import it cannot resolve.


Conventions

Lookups answer, builders refuse: normalizeCep returns null, assertCep throws. null means "the source did not say" and is never a guess. Dataset tables are deep-frozen on load.

Full rules in API conventions.

Licence

MIT