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

oniguruma

v7.2.3

Published

oniguruma regular expression library

Downloads

71,876

Readme

Oniguruma Node module

CI

Native Node bindings to the Oniguruma regular expressions library.

Read all about Oniguruma regular expressions here.

Version 2.0 of this library added an asynchronous API, the old synchronous methods have been renamed to have a Sync suffix.

Installing

npm install oniguruma

Building

  • Clone the repository
  • Run npm install
  • Run npm test to run the specs

Using

{OnigRegExp, OnigScanner} = require 'oniguruma'

OnigScanner(patterns)

Create a new scanner with the given patterns.

patterns - An array of string patterns.

OnigScanner::findNextMatch(string, startPosition, callback)

Find the next match from a given position.

string - The string to search.

startPosition - The optional position to start at, defaults to 0.

callback - The (error, match) function to call when done, match will null when there is no match.

Example

scanner = new OnigScanner(['c', 'a(b)?'])
scanner.findNextMatch 'abc', (error, match) ->
  console.log match
  {
    index: 1,  # Index of the best pattern match
    captureIndices: [
      {index: 0, start: 0, end: 2, length: 2},  # Entire match
      {index: 1, start: 1, end: 2, length: 1}   # Match of first capture group
    ]
  }

OnigScanner::findNextMatchSync(string, startPosition)

Synchronously find the next match from a given position.

string - The string to search.

startPosition - The optional position to start at, defaults to 0.

Returns an object containing details about the match or null if no match.

Example

scanner = new OnigScanner(['c', 'a(b)?'])
match = scanner.findNextMatchSync('abc')
console.log match
{
  index: 1,  # Index of the best pattern match
  captureIndices: [
    {index: 0, start: 0, end: 2, length: 2},  # Entire match
    {index: 1, start: 1, end: 2, length: 1}   # Match of first capture group
  ]
}

OnigRegExp(pattern)

Create a new regex with the given pattern.

pattern - A string pattern.

OnigRegExp::search(string, startPosition, callback)

Search the string for a match starting at the given position.

string - The string to search.

startPosition - The optional position to start the search at, defaults to 0.

callback - The (error, match) function to call when done, match will be null if no matches were found. match will be an array of objects for each matched group on a successful search.

Example

regex = new OnigRegExp('a([b-d])c')
regex.search '!abcdef', (error, match) ->
  console.log match
  [
    {index: 0, start: 1, end: 4, match: 'abc', length: 3}, # Entire match
    {index: 1, start: 2, end: 3, match: 'b', length: 1}    # Match of first capture group
  ]

OnigRegExp::searchSync(string, startPosition)

Synchronously search the string for a match starting at the given position.

string - The string to search.

startPosition - The optional position to start the search at, defaults to 0.

Returns an array of objects for each matched group or null if no match was found.

Example

regex = new OnigRegExp('a([b-d])c')
match = regex.searchSync('!abcdef')
console.log match
[
  {index: 0, start: 1, end: 4, match: 'abc', length: 3}, # Entire match
  {index: 1, start: 2, end: 3, match: 'b', length: 1}    # Match of first capture group
]

OnigRegExp::test(string, callback)

Test if this regular expression matches the given string.

string - The string to test against.

callback - The (error, matches) function to call when done, matches will be true if at least one match is found, false otherwise.

Example

regex = new OnigRegExp('a([b-d])c')
regex.test 'abcdef', (error, matches) ->
  console.log matches # true

OnigRegExp::testSync(string)

Synchronously test if this regular expression matches the given string.

string - The string to test against.

Returns true if at least one match, false otherwise.

Example

regex = new OnigRegExp('a([b-d])c')
matches = regex.testSync('abcdef')
console.log matches # true