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

regex-helper-ease

v0.0.6

Published

A lightweight JavaScript library that helps structure regex quickly and easily. This library does not replace learning regex but assists in their usage by removing the concrete implementation of regex and focus on results instead.

Downloads

19

Readme

Regex-helper-ease

A lightweight JavaScript library that helps structure regex quickly and easily. This library does not replace learning regex but assists in their usage by removing the concrete implementation of regex and focus on results instead.

This library supports fuzzy search, ie. it still identify misspelled words, correct them, and run the provided regex.

Getting started

Package installation

Installation:

npm install regex-helper-ease

Documentation

Find the complete documentation here.

Example

const results = new RegexHelper()
  .query({
    // pre build regex (dd/mm/yyyy)
    regex: `${EUFullDate}`,
    // the name of your regex
    name: 'fullDate',
    // text to display if no value has been found
    valueIfNotFound: 'Date not found',
  })
  .query({
    regex: `has been paid`,
    name: 'isPaid',
    // test only for presence
    test: true,
  })
  .query({
    regex: `year :? (\\d+)`,
    name: 'yearSentence',
    // will not count as success
    countAsSuccess: false,
    // provide a validation function*
    capturingGroup: [{ name: 'year', index: 1, validation: validators.year }],
  })
  .query({
    regex: `article :? (${anyDigits})`,
    name: 'articleSentence',
    // this will capture the value of the first group (index: 1)
    capturingGroup: [{ name: 'article', index: 1 }],
    // it searchs for the given expression 'article', allowing deviation
    fuzzy: { expression: 'article' },
  })
  // the text where to perform searching (misspelled word 'artiicle').
  .findIn('The artiicle: 471 has been paid on 12/12/2021. Accounting of year: 2022 has been done.')
  // 'debug' | 'data' | 'general' | 'fuzzy'
  .get('data');

Results

The regex displays following results:

{
  fullDate: '12/12/2021',
  isPaid: 'true',
  yearSentence: 'year: 2022',
  year: '2022',
  articleSentence: 'article: 471',
  article: '471'
}

*Validation could be defined as:

// Simple validation, but it can be more complex with Zod, Joi, etc.
const validators = {
  year: (value: string) => +value > 2020,
};

Developer experience

This library comes with a serie of pre build regex. Special attention has been given on developer experience. Properties and methods are exhaustively documented and typed. Use your IDE's autocompletion or hover on properties and methods for help. Errors will be thrown with explicit messages.

File a bug, got a new idea, or want to contribute?

Feel free! Open a ticket.

Changelog

V0.0.2: [MINOR] Improved typescript return type of the results.

V0.0.3: [MINOR] Escaping empty regex at initialisation and adding a general success rate in percentage in the General interface. Bug corrections and adding tests.

V0.0.4: [MINOR] Adding fuzzy search possibility and tests.

V0.0.5: [MINOR] Improving fuzzy search and adding tests.

V0.0.6: [MINOR] Removing subQuery searchs (capturing groups is an alternative and offers a cleaner API), increase of the fuzzy threshold to decrease false positive (set to 0.75), improving fuzzy search, support for global search with capturing groups (flag g), addition of options (possibleValues, countAsSuccess, validation) and adding tests.

Discover others libraries

All libraries are permanently supported. Discover them here.