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

srl

v0.2.3

Published

Simple Regex Language

Downloads

16

Readme

SRL-JavaScript

JavaScript implementation of Simple Regex :tada::tada::tada:

npm version Build Status codecov

Because of the JavaScript regex engine, there is something different from Simple Regex

  • Support as to assign capture name with CODE but not regex engine.
  • NOT support if already had/if not already had
  • NO first match and NO all lazy, since in JavaScript lazy means non-greedy (matching the fewest possible characters).

Installation

npm install srl

Usage

Class SRL accepts a Simple Regex Language string as input, and return the builder for the query.

The builder can agent test/exec method to the generated regex object. Or you can use get() to take the generated regex object.

const SRL = require('srl')
const query = new SRL('letter exactly 3 times')

query.isMatching('aaa') // true
query.getMatch('aaa') // [ 'aaa', index: 0, input: 'aaa' ]

query
    .digit()
    .neverOrMore()
    .mustEnd()
    .get() // /[a-z]{3}[0-9]*$/g

Required Node 8.0+ for the ES6 support, Or you can use Babel to support Node below 6.0.

Using Webpack and babel-loader to pack it if want to use in browsers.

Additional

In SRL-JavaScript we apply g flag as default to follow the Simple Regex "standard", so we provide more API to use regex conveniently.

  • isMatching - Validate if the expression matches the given string.

    const query = new SRL('starts with letter twice')
    query.isMatching(' aa') // false
    query.isMatching('bbb') // true
  • getMatch - Get first match of the given string, like run regex.exec once.

    const query = new SRL('capture (letter twice) as word whitespace')
    
    query.getMatch('aa bb cc dd') // [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ]
  • getMatches - Get all matches of the given string, like a loop to run regex.exec.

    const query = new SRL('capture (letter twice) as word whitespace')
      
    query.getMatches('aa bb cc dd')
    /**
     * [ 
     *     [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ],
     *     [ 'bb ', 'bb', index: 3, input: 'aa bb cc dd', word: 'bb' ],
     *     [ 'cc ', 'cc', index: 6, input: 'aa bb cc dd', word: 'cc' ] 
     * ]
     */
  • removeModifier - Remove specific flag.

    const query = new SRL('capture (letter twice) as word whitespace')
      
    query.removeModifier('g')
    query.get() // /([a-z]{2})\s/

Development

First, clone repo and init submodule for test.

SRL-JavaScript depends on Mocha and Istanbul to test code. You can use them like this:

npm install

npm test # test 
npm run coverage # Get coverage locally 

How to write Rules, see: Test-Rules.

License

SRL-JavaScript is published under the MIT license. See LICENSE for more information.