diff --git a/README.md b/README.md index 0764496..28d8c4c 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,17 @@ Compile a regular expression from the `state` object returned by the * `returnState` **{Boolean}**: Adds the state to a `state` property on the returned regex. Useful for implementors and debugging. * `returns` **{RegExp}** +**Example** + +```js +const picomatch = require('picomatch'); +const state = picomatch.parse('*.js'); +// picomatch.compileRe(state[, options]); + +console.log(picomatch.compileRe(state)); +//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ +``` + ### [.makeRe](lib/picomatch.js#L285) Create a regular expression from a parsed glob pattern. @@ -281,10 +292,10 @@ Create a regular expression from a parsed glob pattern. ```js const picomatch = require('picomatch'); -const state = picomatch.parse('*.js'); -// picomatch.compileRe(state[, options]); +// picomatch.makeRe(state[, options]); -console.log(picomatch.compileRe(state)); +const result = picomatch.makeRe('*.js'); +console.log(result); //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ ``` diff --git a/lib/picomatch.js b/lib/picomatch.js index d0ebd9f..fbb8b1c 100644 --- a/lib/picomatch.js +++ b/lib/picomatch.js @@ -233,6 +233,14 @@ picomatch.scan = (input, options) => scan(input, options); * Compile a regular expression from the `state` object returned by the * [parse()](#parse) method. * + * ```js + * const picomatch = require('picomatch'); + * const state = picomatch.parse('*.js'); + * // picomatch.compileRe(state[, options]); + * + * console.log(picomatch.compileRe(state)); + * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ + * ``` * @param {Object} `state` * @param {Object} `options` * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser. @@ -268,10 +276,10 @@ picomatch.compileRe = (state, options, returnOutput = false, returnState = false * * ```js * const picomatch = require('picomatch'); - * const state = picomatch.parse('*.js'); - * // picomatch.compileRe(state[, options]); + * // picomatch.makeRe(state[, options]); * - * console.log(picomatch.compileRe(state)); + * const result = picomatch.makeRe('*.js'); + * console.log(result); * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ * ``` * @param {String} `state` The object returned from the `.parse` method.