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

globrex

v0.1.2

Published

Glob to regular expression with support for extended globs

Downloads

13,507,410

Readme

Install

npm install globrex --save

Core Features

  • 💪 extended globbing: transform advance ExtGlob features
  • 📦 simple: no dependencies
  • 🛣️ paths: split paths into multiple RegExp segments

Usage

const globrex = require('globrex');

const result = globrex('p*uck')
// => { regex: /^p.*uck$/, string: '^p.*uck$', segments: [ /^p.*uck$/ ] }

result.regex.test('pluck'); // true

API

globrex(glob, options)

Type: function Returns: Object

Transform globs intp regular expressions. Returns object with the following properties:

regex

Type: RegExp

JavaScript RegExp instance.

Note: Read more about how to use RegExp on MDN.

path

This property only exists if the option filepath is true.

Note: filepath is false by default

path.segments

Type: Array

Array of RegExp instances seperated by /. This can be usable when working with file paths or urls.

Example array could be:

[ /^foo$/, /^bar$/, /^([^\/]*)$/, '^baz\\.(md|js|txt)$' ]

path.regex

Type: RegExp

JavaScript RegExp instance build for testign against paths. The regex have different path seperators depending on host OS.

glob

Type: String

Glob string to transform.

options.extended

Type: Boolean Default: false

Enable all advanced features from extglob.

Matching so called "extended" globs pattern like single character matching, matching ranges of characters, group matching, etc.

Note: Interprets [a-d] as [abcd]. To match a literal -, include it as first or last character.

options.globstar

Type: Boolean Default: false

When globstar is false globs like '/foo/*' are transformed to the following '^\/foo\/.*$' which will match any string beginning with '/foo/'.

When the globstar option is true, the same '/foo/*' glob is transformed to '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' that does not have a '/' to the right of it. '/foo/*' will match: '/foo/bar', '/foo/bar.txt' but not '/foo/bar/baz' or '/foo/bar/baz.txt'.

Note: When globstar is true, '/foo/**' is equivelant to '/foo/*' when globstar is false.

options.strict

Type: Boolean Default: false

Be forgiving about mutiple slashes, like /// and make everything after the first / optional. This is how bash glob works.

options.flags

Type: String Default: ''

RegExp flags (e.g. 'i' ) to pass to the RegExp constructor.

options.filepath

Type: Boolean Default: false

Parse input strings as it was a file path for special path related features. This feature only makes sense if the input is a POSIX path like /foo/bar/hello.js or URLs.

When true the returned object will have an additional path object.

  • segment: Array containing a RegExp object for each path segment.
  • regex: OS specific file path RegExp. Path seperator used is based on the operating system.
  • globstar: Regex string used to test for globstars.

Note: Please only use forward-slashes in file path glob expressions Though windows uses either / or \ as its path separator, only / characters are used by this glob implementation. You must use forward-slashes only in glob expressions. Back-slashes will always be interpreted as escape characters, not path separators.

References

Learn more about advanced globbing here

License

MIT © Terkel Gjervig