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

rematch-javascript

v1.2.2

Published

JavaScript bindings for REmatch, an information extraction focused regex library that uses constant delay algoirthms.

Downloads

122

Readme

REmatch-javascript: REmatch bindings for JavaScript

JavaScript bindings for REmatch, an information extraction focused regex library that uses constant delay algoirthms.

REmatch-javascript generated bindings were compiled directly from REmatch's C++ source code using the emscripten compiler.

Installation - npm

npm install rematch-javascript

Then you can import the REmatch initializer function with:

import initREmatch from 'rematch-javascript';

Installation

Make the initREmatch function available globally in browsers with:

<!-- Direct reference non-minified -->
<script src="./lib/index.umd.js"></script>
<!-- Direct reference minified -->
<script src="./lib/index.umd.min.js"></script>

<!-- unpkg CDN non-minified -->
<script src="https://unpkg.com/rematch-javascript@latest/lib/index.umd.js"></script>
<!-- unpkg CDN minified -->
<script src="https://unpkg.com/rematch-javascript@latest/lib/index.umd.min.js"></script>

<!-- jsDelivr CDN non-minified -->
<script src="https://cdn.jsdelivr.net/npm/rematch-javascript@latest/lib/index.umd.js"></script>
<!-- jsDelivr CDN minified -->
<script src="https://cdn.jsdelivr.net/npm/rematch-javascript@latest/lib/index.umd.min.js"></script>

For ESM modules:

// Direct reference
import initREmatch from './lib/index.esm.js';

// unpkg CDN
import initREmatch from 'https://unpkg.com/rematch-javascript@latest/lib/index.esm.js';

// jsDelivr CDN
import initREmatch from 'https://cdn.jsdelivr.net/npm/rematch-javascript@latest/lib/index.esm.js';

For CJS modules:

// Direct reference
const initREmatch = require('./lib/index.cjs');

// unpkg CDN
const initREmatch = require('https://unpkg.com/rematch-javascript@latest/lib/index.cjs');

// jsDelivr CDN
const initREmatch = require('https://cdn.jsdelivr.net/npm/rematch-javascript@latest/lib/index.cjs');

Usage

As said before, REmatch-javascript was built with emscripten, so it uses WebAssembly to run. The .wasm code is embedded directly into the library's code, so it is not needed to bundle or import it.

First you would need to load the REmatch module instance by importing the initREmatch function:

// Create a REmatch module instance
const REmatch = await initREmatch();

// Define the document and pattern to search for
const document = "[email protected]\[email protected]\[email protected]";
const pattern = String.raw`@!domain{(\w+\.)+\w+}(\n|$)`;

// Create a REQL query
const query = REmatch.reql(pattern);

// Execute the query and show the matches
const matchIterator = query.findIter(document);
for (const match of matchIterator) {
  console.log(`Match: ${match.toString()}`);

  // Current match will no longer be used
  match.free();
}

// Query and MatchIterator will no longer be used
query.free();
matchIterator.free();

As you notice in the previous snippet, due the lack of garbage collection in JavaScript, the bindings should be explicitly freed when you are done with them. Otherwise, it will lead to memory leaks.

Development

If you want to update the emscripten bindings, first make sure that you have the emscripten compiler installed. Then, if you want to the latest REmatch, do the following steps:

  1. Update the REmatch's submodule (at /REmatch) with the latest version
  2. Build the emscripten bindings with npm run build:bindings
  3. Build the project with npm run build