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

@pfeiferio/message-resolver

v1.0.0

Published

Context-based message resolution with priority selectors

Readme

@pfeiferio/message-resolver

Resolve messages deterministically based on structured selectors and ordered priorities.

@pfeiferio/message-resolver is a small utility for selecting the best matching message from a set of candidates using attribute-based selectors and an explicit priority order.

It is designed for applications that need predictable message resolution logic without introducing a full rule engine or i18n framework.


Features

  • Attribute-based selectors (e.g. [type=email][scope=register])
  • Deterministic priority resolution
  • Fast selector matching using bit masks
  • Optional placeholder replacement
  • No side effects, no global state

Installation

npm install @pfeiferio/message-resolver

Basic usage

Define messages

const messages = {
  '[type=email]': {
    email: 'email error'
  },
  '[scope=register]': {
    email: 'register email error'
  }
}

Define priority order

const priorities = ['type', 'scope']

The order defines the relative priority of selector attributes. Attributes listed later have higher priority.


Create a resolver

import { MessageResolver } from '@pfeiferio/message-resolver'

const resolver = new MessageResolver(messages, priorities)

Resolving messages

const result = resolver.find(
  { type: 'email', scope: 'register' },
  'email'
)

console.log(result.message)
// → "register email error"

If no message matches, find() returns null.

If multiple selectors match, the resolver chooses the message with the highest priority based on the configured order.


Selector semantics

Selectors use a simple attribute syntax:

[type=email][scope=register]

A selector matches if all attributes are present in the identifier object.

selector.test({ type: 'email', scope: 'register' }) // true
selector.test({ type: 'email' })                    // false

Placeholder interpolation (optional)

@pfeiferio/message-resolver does not perform placeholder interpolation by itself.

If a resolved message contains placeholders, they can be interpolated explicitly using a separate library such as @pfeiferio/string-interpolate.

import { interpolate } from '@pfeiferio/string-interpolate'

const result = resolver.find({ type: 'email' }, 'email')
const message = interpolate(result.message, { type: 'email' })

Unresolved placeholders are left untouched.


What this package is not

  • ❌ Not a message broker
  • ❌ Not a logger
  • ❌ Not an i18n framework
  • ❌ Not a rule engine

This package focuses on deterministic message resolution only.


Mental model

Given a set of messages and a context, resolve exactly one message in a predictable way.


License

MIT