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

matchlet

v0.0.3

Published

PHP-like pattern matching for TypeScript

Readme

matchlet

A TypeScript implementation of PHP-like pattern matching with type safety and additional features.

Why I Created This

I've always loved PHP's match expression and have been using my own TypeScript implementation of it for years in various projects. Recently, I wanted to enhance it with a PHP-style _default key functionality. After consulting with Claude AI about the implementation, the result turned out so well that I decided to make it my first open-source contribution.

This is my first open-source project, and I'm excited to share it with the community.

Installation

npm install matchlet

Usage

import { match } from 'matchlet';

// Basic usage with default value
const result1 = match('a', {
    a: 'value1',
    b: 'value2',
    _default: 'default value'
});

// Using with functions
const result2 = match('x', {
    a: () => 'value1',
    _default: () => 'not found'
});

// Without default (all keys required)
const result3 = match('a', {
    a: 'value1',
    b: 'value2'
});

// With specific types
interface User {
    name: string;
    age: number;
}

const userResult = match<string, User>('admin', {
    admin: { name: 'Admin', age: 30 },
    guest: { name: 'Guest', age: 0 },
    _default: { name: 'Unknown', age: -1 }
});

Features

  • TypeScript type safety
  • PHP-like pattern matching
  • Support for both values and functions
  • Optional default values with _default key
  • Generic type support

Type Safety

The library provides compile-time type checking:

  • When using _default, other keys are optional
  • Without _default, all keys are required
  • Supports both direct values and functions
  • Generic types for flexible usage

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.