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

@destinatlon/state-resolve

v1.0.3

Published

Always resolve a valid province/state code for an address. Waterfall: valid code → region name/alias → postcode derivation → country default. Supports DE, FR, AU, BE, AT, CH, SE, NO, FI, GB.

Downloads

456

Readme

@destinatlon/state-resolve

Always resolve a valid province/state code for an address, so orders never get rejected or mis-shipped because of a missing or free-text state field.

No third-party dependencies — plain Node (CommonJS), built-in path only.

Install

npm install @destinatlon/state-resolve

Usage

const { resolveStateCode } = require('@destinatlon/state-resolve');

const stateCode = resolveStateCode({
  country: 'DE',          // ISO-ish code or internal alias (UK, EN, CH-DE, BE-FR…)
  postalCode: '80331',    // used for derivation when state is missing/invalid
  city: 'München',        // only used in fallback log messages
  state: 'Bayern',        // raw state name OR code; may be empty
});
// → 'BY'

How it resolves

Given { country, postalCode, city, state }, the code is resolved via this waterfall:

  1. state is already a valid code → return it uppercased
  2. state matches a known region name/alias → return that code
  3. derive the code from postalCode (per-country logic)
  4. fall back to a per-country default (logs a warning)

Unsupported countries pass the given state through unchanged.

API

| Export | Signature | Description | |--------|-----------|-------------| | resolveStateCode | ({ country, postalCode, city, state }) => string | Main entry point. Always returns a valid code for supported countries. | | isValidCode | (country, code) => boolean | True if code is a valid province/state code for country. | | normCountry | (country) => string | Normalize a country alias to its vocabulary key. | | deriveByPostcode | (country, postalCode) => string \| null | Derive a region code from a postcode, or null. |

Behaviour notes

  • Country aliases are handled internally (UKGB, ENNL, CH-DECH, BE-FR/BE-NLBE) via normCountry, so locale/language codes can be passed directly.
  • For an unsupported country it returns whatever state you passed, untouched (and warns if empty).
  • For a supported country it never returns empty — worst case it logs a [stateResolver] fell back to default… warning and returns the country default. Watch your logs for those; they flag addresses that may mis-ship.
  • Supported derivation countries: DE, FR, AU, BE, AT, CH, SE, NO, FI, GB. To add another, add its vocabulary to data/state-codes.json and (optionally) a deriver function in src/postcodeRegion.js.

Data

  • data/state-codes.json — province/state vocabulary per country.
  • data/uk-outcodes.json — UK outcode → region lookup table.

Test

npm test

License

MIT © Destinatlon