glob-capture-regex

1.0.3 • Public • Published

glob-capture-regex

Convert glob patterns to regular expressions, including the feature of capturing groups within the glob pattern.

Installation

$ npm i glob-capture-regex

Usage

const globCaptureRegex = require('glob-capture-regex');

const globWithGroups = 'my/gl(*)b/pattern/(**).js';
const path = 'my/glob/pattern/with/capture/groups.js';

const { glob, regex } = globCaptureRegex(globWithGroups).parse();

console.log(glob); // my/gl*b/pattern/**.js

console.log(regex.match(path)); 
// [
//    'my/glob/pattern/with/capture/groups.js', 
//    'o', 
//    'with/capture/groups'
// ];

API

globCaptureRegex(glob: string)

Converts a glob pattern to a regular expression with capture groups.

  • glob - (string) - The glob pattern to convert.

Returns: An object with the following properties:

{
    // A getter that returns the glob pattern without the capture groups.
    glob: Getter<string>,

    // A getter that returns the regular expression with capture groups
    regex: Getter<RegExp>, 
    
    // Function which return an object with both the `glob` and the `regex`
    parse: function
}

/glob-capture-regex/

    Package Sidebar

    Install

    npm i glob-capture-regex

    Weekly Downloads

    1

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    4.45 kB

    Total Files

    4

    Last publish

    Collaborators

    • hzisman