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

simple-matcher

v1.0.0

Published

Simple text matching for strings, regular expressions and functions.

Readme

simple-matcher

A very simple tool to work easily with matchings.

Specifically, string, regular expressions and functional matchings.

1. Installation

Simply, run:

npm install -s simple-matcher

For Node.js, you should:

const SimpleMatcher = require("simple-matcher");

For browsers, you should import the source code (src/simple-matcher.js):

<script src="node_modules/simple-matcher/src/simple-matcher.js"></script>

...and you will already find the global object exposing all the API at:

window.SimpleMatcher // in browsers

global.SimpleMatcher // in node.js

2 Get started

The SimpleMatcher library is very simple.

Start, for example, with:

const stringMatch = SimpleMatcher.for("This is some text").first("This is");
const regexpMatch = SimpleMatcher.for("This is some text").first(/THIS IS/gi);
const funcMatch = SimpleMatcher.for("This is some text").first((text,offset) => {index:text.substr(0,offset).substr(4) !== "This" ? -1 : 4});

If you want to differ between errors and correct data:

if(stringMatch.error) {
  // Handle error
}
if(regexpMatch.error) {
  // Handle error
}
if(funcMatch.error) {
  // Handle error, but this one will depend on the manual implementation of the matcher we provide
}

Once we get the data back, we can obtain:

· ...the `index` (integer with the last position of the match, or -1 if failed)
· ...the `found` (string with the match)
· ...the `type` (with basically one out of "text", "regexp" and "function").

3. API

The object SimpleMatcher exposes all the API.

SimpleMatcher.for(String:text)

Returns: SimpleMatcher.classes.Object

The text parameter (a String) is the text to be matched.

{SimpleMatcher.classes.Object}.first(...)

Returns: SimpleMatcher.classes.Data | SimpleMatcher.classes.Error

This method will give info about the first (string/regexp/functional) match in the text.

Optionally, we have a second parameter, an offset (integer) of the text from which to start matching.

{SimpleMatcher.classes.Object}.first(String:text[, Integer:offset])

Returns: SimpleMatcher.classes.Data | SimpleMatcher.classes.Error

This version will compare string against string, crudely.

{SimpleMatcher.classes.Object}.first(RegExp:pattern[, Integer:offset])

Returns: SimpleMatcher.classes.Data | SimpleMatcher.classes.Error

This version will compare regexp against strnig.

{SimpleMatcher.classes.Object}.first(Function:matcher[, Integer:offset])

Returns: SimpleMatcher.classes.Data | SimpleMatcher.classes.Error

This version will use the provided function as matcher. That function receives 2 parameters:

1. text(:String): base text.

2. offset(:Integer): position of the text from which to start working on.

SimpleMatcher.classes.Data (~Object~)

Depending on the context, this type of objects will have:

type: (String) "text" | "regexp" | "function"

index: (Integer) final position of the index

found: (String) text matched

SimpleMatcher.classes.Error (~Object~)

Depending on the context, this type of objects will have:

type: (String) "error"

index: (Integer) -1

error: (String) message of the error, typically.

4. Conclusion

It is not very complex right now, but I felt that I had to start some project to shorten this topic...