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

@gabrielrufino/matchjs

v1.1.3

Published

[![Black Tech by Gabriel Rufino](https://img.shields.io/badge/Black_Tech-by_Gabriel_Rufino_%F0%9F%96%A4-white?style=flat-square&labelColor=444444)](https://gabrielrufino.com) [![CI](https://github.com/gabrielrufino/matchjs/actions/workflows/ci.yml/badge.s

Readme

MatchJS

Black Tech by Gabriel Rufino CI CD Quality Gate Status

MatchJS is a flexible library that implements a value matching mechanism with support for custom cases, including special operators like include, exclude, object, and a fallback otherwise. It supports matching both primitive values and complex objects with deep equality comparison.

📦 Installation

Install the library using npm or yarn:

npm install @gabrielrufino/matchjs
# or
yarn add @gabrielrufino/matchjs

🚀 Usage

Import

import { exclude, include, match, object, otherwise } from '@gabrielrufino/matchjs'

Basic Example

const result = match('a')({
  a: () => 'Letter A',
  b: () => 'Letter B',
  [otherwise]: () => 'Other value'
})

console.log(result) // Output: "Letter A"

Using include

const result = match('a')({
  [include('a', 'b', 'c')]: () => 'In set A, B, or C',
  [otherwise]: () => 'Other value'
})

console.log(result) // Output: "In set A, B, or C"

Using exclude

const result = match('d')({
  [exclude('a', 'b', 'c')]: () => 'Not in A, B, or C',
  [otherwise]: () => 'Other value'
})

console.log(result) // Output: "Not in A, B, or C"

Using object

const user = { name: 'John', age: 30 }

const result = match(user)({
  [object({ name: 'John', age: 30 })]: () => 'Exact user match',
  [object({ name: 'Jane' })]: () => 'Different user',
  [otherwise]: () => 'Unknown user'
})

console.log(result) // Output: "Exact user match"

Complex Object Matching

const data = {
  user: { id: 1, profile: { name: 'Alice' } },
  settings: { theme: 'dark' }
}

const result = match(data)({
  [object({
    user: { id: 1, profile: { name: 'Alice' } },
    settings: { theme: 'dark' }
  })]: () => 'Complex match found',
  [otherwise]: () => 'No match'
})

console.log(result) // Output: "Complex match found"

🛠️ API

match(value)

Parameters

  • value: The value to be evaluated (string, number, symbol, or object).

Returns

A function that accepts an options object in the format { key: () => any }, where:

  • key can be:
    • An exact value to match (for primitive values).
    • An operator like include, exclude, or object.
    • The otherwise symbol as a fallback.

Examples

See the Usage section.


include(...values)

Defines a set of values. Returns true if the value is included in the set.


exclude(...values)

Defines a set of values. Returns true if the value is not included in the set.


object(value)

Defines an object pattern for deep equality matching. Returns true if the input value deeply equals the provided object.

Parameters

  • value: The object pattern to match against.

Example

const result = match({ a: 1, b: { c: 2 } })({
  [object({ a: 1, b: { c: 2 } })]: () => 'Deep match!',
  [otherwise]: () => 'No match'
})

otherwise

A special symbol used as a fallback for unmatched cases.

🧪 Testing

This project uses Vitest for testing.

To run the tests:

npm test

🛡️ Contribution

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your changes: git checkout -b my-feature.
  3. Make your changes and commit: git commit -m "My new feature".
  4. Push to your branch: git push origin my-feature.
  5. Open a Pull Request.

📄 License

This project is licensed under The Unlicense. See the LICENSE file for details.