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

@leadertechie/regional-config-resolver

v0.1.0-alpha.4

Published

Logic-only engine for hierarchical configuration resolution. Storage-agnostic, hierarchy-agnostic (uses Dependency Injection for standards like UN-M49).

Downloads

23

Readme

@leadertechie/regional-config-resolver

Logic-only engine for hierarchical configuration resolution. Storage-agnostic (no KV/R2 dependency) and hierarchy-agnostic (uses Dependency Injection for standards like UN-M49).

Resolves region-specific config values by walking a hierarchy: exact key → manual fallback → hierarchy provider (e.g. UN-M49) → prefix step-down → wildcard *.

Zero runtime dependencies (except optional @leadertechie/geo-hierarchy-un-m49). Works in browser, Node, edge workers.


Installation

npm install @leadertechie/regional-config-resolver

Quick Start

import { RegionalConfigResolver } from '@leadertechie/regional-config-resolver';

const data = {
  'AU': 'dark-mode',
  'US': 'light-mode',
  '*':  'system-mode',
};

const resolver = new RegionalConfigResolver(data);
resolver.resolve('AU-PER'); // → "dark-mode"  (prefix step-down: AU-PER → AU)
resolver.resolve('US-CA');  // → "light-mode" (prefix step-down: US-CA → US)
resolver.resolve('JP');     // → "system-mode" (wildcard fallback)

With UN-M49 Hierarchy

import { getParent } from '@leadertechie/geo-hierarchy-un-m49';
import { RegionalConfigResolver } from '@leadertechie/regional-config-resolver';

const data = {
  'Oceania': 'oceania-theme',
  '*':       'default-theme',
};

const resolver = new RegionalConfigResolver(data, getParent);
resolver.resolve('AU'); // → "oceania-theme" (AU → Oceania)
resolver.resolve('US'); // → "default-theme" (US → Americas → World → *)

Resolution Strategy

When you call resolver.resolve(key), it walks this chain:

1. Exact key match in data       → return value
2. Config object with `value`    → return value
3. Config object with `fallback` → jump to fallback key, repeat
4. HierarchyProvider (e.g. UN-M49) → ask for parent key, repeat
5. Prefix step-down (hyphen split) → e.g. "AU-WA-PER" → "AU-WA"
6. Wildcard `*`                  → return global fallback
7. Nothing found                 → return undefined

Circular references are detected and return undefined.


API

RegionalConfigResolver<T>

constructor(data: Record<string, ConfigEntry<T>>, provider?: HierarchyProvider)

| Param | Type | Description | |-------|------|-------------| | data | Record<string, ConfigEntry<T>> | Flat map of keys to values | | provider | HierarchyProvider (optional) | Function that returns parent key for a given key |

resolve(key: string): T | undefined

Resolve a value by walking the hierarchy.


Types

type HierarchyProvider = (key: string) => string | undefined;

type ConfigEntry<T> = T | { value?: T; fallback?: string };
  • Raw value: 'dark-mode' — returned directly on match
  • Config object: { value: 'dark-mode' } — explicit value
  • Config object with fallback: { fallback: 'AU' } — jump to another key
  • Both: { value: 'dark-mode', fallback: 'World' }value wins

Hierarchy Helpers

import { composeProviders, fromMap } from '@leadertechie/regional-config-resolver';

composeProviders(...providers: HierarchyProvider[]): HierarchyProvider

Merge multiple providers. First non-undefined result wins.

const provider = composeProviders(getParent, customProvider);

fromMap(map: Record<string, string>): HierarchyProvider

Create a provider from a static map. Useful for tests.

const provider = fromMap({ 'AU-PER': 'AU', 'AU': 'Oceania' });

Usage with @leadertechie/geo-hierarchy-un-m49

import { getParent } from '@leadertechie/geo-hierarchy-un-m49';
import { RegionalConfigResolver } from '@leadertechie/regional-config-resolver';

const resolver = new RegionalConfigResolver(kvData, getParent);
const mode = resolver.resolve('AU-PER');
// Walks: AU-PER → AU → Australia and New Zealand → Oceania → World → *

Edge Cases

| Scenario | Behavior | |----------|----------| | Exact match | Returns value immediately | | Missing key | Walks hierarchy up to * or returns undefined | | Circular fallback | Detected via visited set, returns undefined | | Circular provider | Detected via visited set, returns undefined | | No provider | Uses prefix step-down + wildcard only | | No wildcard | Returns undefined if nothing matches | | Arrays | Not treated as config objects (returned as-is) | | null value | Returned as-is (not undefined) |


Exports

// Core
export { RegionalConfigResolver } from './index';
export type { HierarchyProvider, ConfigEntry } from './index';

// Helpers
export { composeProviders, fromMap } from './hierarchy';

License

MIT