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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@momsfriendlydevco/match

v1.2.0

Published

Simple string matching / globbing / RegEx matching

Downloads

29

Readme

@MomsFriendlyDevCo/Match

Simple string matching / globbing / RegEx matching.

  • Isomorphic, "just works" functionality in the browser / node - already minified, upstream shims already applied
  • Works with arrays of patterns
  • Compatibility with *.globs / "/regexp/"
  • Returns a simple matcher function without object / classing overhead
  • Both ESM and CJS support

Why

I couldn't find a library that did what I wanted:

  • micromatch & picomatch - Both require shiming of process and path to work properly in the browser without screwing around with Webpack
  • nanomatch - Doens't support brace expansion
  • All of the above have hit-and-miss support for arrays of globs
  • None of them are out-of-the-box extendable to also cope with "/regexp/" strings as well as globs
import match from '@momsfriendlydevco/match';

// Simple string matching
match.isMatch('*.js', 'hello.js') //= true
match.isMatch(['*.js', '.txt'], 'hello.js') //= true
match.isMatch(/\.js$/, 'hello.js') //= true
match.isMatch('/\.js$/', 'hello.js') //= true


// Pre-compiled matcher
let matcher = match.compile(['*.js', '/\.txt$/']);
matcher('hello.js'); //= true
matcher('hello.txt'); //= true
matcher('hello.css'); //= false

API

In all cases patterns can be:

  • A single glob expression
  • A string surrounded by / indicating it should be treated as a RegExp match (with optional RegExp flags)
  • A raw RegEx
  • An array of any combination of the above

options for all API's are passed directly onto the picomatch library except for the following which are parsed then removed before being passed to picomatach:

| Option | Type | Default | Description | |--------|-----------|---------|---------------------------------------------------------------------------| | csv | boolean | false | If the input is a single string, split it using CSV rules, before parsing |

Match.isMatch(patterns, subject, options)

Return a simple boolean if the subject matches any of the given patterns. Options is any valid config for picomatch.

import match from '@momsfriendlydevco/match';
import {isMatch} from '@momsfriendlydevco/match'; // ... OR as spread export

match.isMatch('*.js', 'hello.js') //= true
match.isMatch(['*.js', '.txt'], 'hello.js') //= true
match.isMatch(/\.js$/, 'hello.js') //= true
match.isMatch('/\.js$/', 'hello.js') //= true

Match.compile(patterns, options)

Create a function which can be used to match against subsequent subjects. Options is any valid config for picomatch.

import match from '@momsfriendlydevco/match';
import {compile} from '@momsfriendlydevco/match'; // ... OR as spread export

let matcher = match.compile(['*.js', '/\.txt$/']);

matcher('hello.js'); //= true
matcher('hello.txt'); //= true
matcher('hello.css'); //= false