Socket
Socket
Sign inDemoInstall

picomatch

Package Overview
Dependencies
0
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 2.0.4

8

CHANGELOG.md

@@ -35,2 +35,9 @@ # Release history

## [2.0.4] - 2019-04-10
### Fixed
- Readme link [fixed](https://github.com/micromatch/picomatch/pull/13/commits/a96ab3aa2b11b6861c23289964613d85563b05df) by @danez.
- `options.capture` now works as expected when fastpaths are enabled. See https://github.com/micromatch/picomatch/pull/12/commits/26aefd71f1cfaf95c37f1c1fcab68a693b037304. Thanks to @DrPizza.
## [2.0.0] - 2019-04-10

@@ -60,4 +67,5 @@

[2.0.4]: https://github.com/jonschlinkert/micromatch/compare/2.0.0...2.0.4
[2.0.0]: https://github.com/jonschlinkert/micromatch/compare/1.0.0...2.0.0
[1.0.0]: https://github.com/jonschlinkert/micromatch/compare/0.1.0...1.0.0
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog

22

lib/parse.js

@@ -22,6 +22,2 @@ 'use strict';

const syntaxError = (place, char) => {
return `Missing ${place}: "${char}" - use "\\\\${char}" to match literal characters`;
};
const expandRange = (args, options) => {

@@ -64,2 +60,10 @@ if (typeof options.expandRange === 'function') {

/**
* Create the message for a syntax error
*/
const syntaxError = (type, char) => {
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
};
/**
* Parse the given input string.

@@ -92,4 +96,4 @@ * @param {String} input

// create constants based on platform, for windows or posix
const chars = constants.globChars(win32);
const EXTGLOB_CHARS = constants.extglobChars(chars);
const PLATFORM_CHARS = constants.globChars(win32);
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);

@@ -109,3 +113,3 @@ const {

START_ANCHOR
} = chars;
} = PLATFORM_CHARS;

@@ -957,2 +961,6 @@ const globstar = (opts) => {

if (opts.capture) {
star = `(${star})`;
}
const globstar = (opts) => {

@@ -959,0 +967,0 @@ return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;

@@ -9,9 +9,11 @@ 'use strict';

/**
* Returns a matcher function from the given glob `pattern` and `options`.
* The returned function takes a string to match as its only argument and returns
* true if the string is a match.
* Creates a matcher function from one or more glob patterns. The
* returned function takes a string to match as its first argument,
* and returns true if the string is a match. The returned matcher
* function also takes a boolean as the second argument that, when true,
* returns an object with additional information.
*
* ```js
* const picomatch = require('picomatch');
* // picomatch(pattern[, options]);
* // picomatch(glob[, options]);
*

@@ -23,3 +25,3 @@ * const isMatch = picomatch('*.!(*a)');

* @name picomatch
* @param {String} `pattern` Glob pattern
* @param {String|Array} `globs` One or more glob patterns.
* @param {Object=} `options`

@@ -94,3 +96,3 @@ * @return {Function=} Returns a matcher function.

* Test `input` with the given `regex`. This is used by the main
* `picomatch()` function to
* `picomatch()` function to test the input string.
*

@@ -101,3 +103,3 @@ * ```js

*
* console.log(pm.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }

@@ -141,10 +143,19 @@ * ```

picomatch.matchBase = (input, pattern, options, posix = utils.isWindows(options)) => {
let regex = pattern instanceof RegExp ? pattern : picomatch.makeRe(pattern, options);
if (posix) {
input = path.posix.basename(input);
} else {
input = path.basename(input);
}
return regex.test(input);
/**
* Match the basename of a filepath.
*
* ```js
* const picomatch = require('picomatch');
* // picomatch.matchBase(input, glob[, options]);
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
* ```
* @param {String} `input` String to test.
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
* @return {Boolean}
* @api public
*/
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
let regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
return regex.test(path.basename(input));
};

@@ -156,7 +167,7 @@

* ```js
* const pm = require('picomatch');
* pm.isMatch(string, patterns[, options]);
* const picomatch = require('picomatch');
* // picomatch.isMatch(string, patterns[, options]);
*
* console.log(pm.isMatch('a.a', ['b.*', '*.a'])); //=> true
* console.log(pm.isMatch('a.a', 'b.*')); //=> false
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
* ```

@@ -177,12 +188,12 @@ * @param {String|Array} str The string to test.

* ```js
* const pm = require('picomatch');
* const state = pm.parse(pattern[, options]);
* const picomatch = require('picomatch');
* const result = picomatch.parse(glob[, options]);
* ```
* @param {String} `glob`
* @param {Object} `options`
* @return {Object} Returns an object with useful properties and output to be used as regex source string.
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
* @api public
*/
picomatch.parse = (input, options) => parse(input, options);
picomatch.parse = (glob, options) => parse(glob, options);

@@ -193,6 +204,15 @@ /**

* ```js
* const pm = require('picomatch');
* const state = pm.scan(pattern[, options]);
* const picomatch = require('picomatch');
* // picomatch.scan(input[, options]);
*
* const result = picomatch.scan('!./foo/*.js');
* console.log(result);
* // { prefix: '!./',
* // input: '!./foo/*.js',
* // base: 'foo',
* // glob: '*.js',
* // negated: true,
* // isGlob: true }
* ```
* @param {String} `pattern`
* @param {String} `input` Glob pattern to scan.
* @param {Object} `options`

@@ -206,12 +226,12 @@ * @return {Object} Returns an object with

/**
* Create a regular expression from the given glob `pattern`.
* Create a regular expression from a glob pattern.
*
* ```js
* const pm = require('picomatch');
* pm.makeRe(pattern[, options]);
* const picomatch = require('picomatch');
* // picomatch.makeRe(input[, options]);
*
* console.log(pm.makeRe('*.js'));
* //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
* console.log(picomatch.makeRe('*.js'));
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
* ```
* @param {String} `pattern` A glob pattern to convert to regex.
* @param {String} `input` A glob pattern to convert to regex.
* @param {Object} `options`

@@ -228,8 +248,12 @@ * @return {RegExp} Returns a regex created from the given pattern.

let opts = options || {};
let prefix = opts.contains ? '' : '^';
let suffix = opts.contains ? '' : '$';
let prepend = opts.contains ? '' : '^';
let append = opts.contains ? '' : '$';
let state = { negated: false, fastpaths: true };
let prefix = '';
let output;
if (input.startsWith('./')) input = input.slice(2);
if (input.startsWith('./')) {
input = input.slice(2);
prefix = state.prefix = './';
}

@@ -242,2 +266,3 @@ if (opts.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {

state = picomatch.parse(input, options);
state.prefix = prefix + (state.prefix || '');
output = state.output;

@@ -250,3 +275,3 @@ }

let source = `${prefix}(?:${output})${suffix}`;
let source = `${prepend}(?:${output})${append}`;
if (state && state.negated === true) {

@@ -265,6 +290,16 @@ source = `^(?!${source}).*$`;

/**
* Create a regular expression from the given source string.
* @param {String} source
* @param {Object} options
* Create a regular expression from the given regex source string.
*
* ```js
* const picomatch = require('picomatch');
* // picomatch.toRegex(source[, options]);
*
* const { output } = picomatch.parse('*.js');
* console.log(picomatch.toRegex(output));
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
* ```
* @param {String} `source` Regular expression source string.
* @param {Object} `options`
* @return {RegExp}
* @api public
*/

@@ -283,2 +318,9 @@

/**
* Picomatch constants.
* @return {Object}
*/
picomatch.constants = require('./constants');
/**
* Expose "picomatch"

@@ -285,0 +327,0 @@ */

@@ -23,10 +23,2 @@ 'use strict';

exports.findLastIndex = (arr, fn, limit = arr.length) => {
for (let i = arr.length - 1; i >= arr.length - limit; i--) {
if (fn(arr[i], i, arr) === true) {
return i;
}
}
};
exports.escapeLast = (input, char, lastIdx) => {

@@ -33,0 +25,0 @@ let idx = input.lastIndexOf(char, lastIdx);

{
"name": "picomatch",
"description": "Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.",
"version": "2.0.3",
"homepage": "https://github.com/folder/picomatch",
"version": "2.0.4",
"homepage": "https://github.com/micromatch/picomatch",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "folder/folder",
"repository": "micromatch/picomatch",
"bugs": {
"url": "https://github.com/folder/picomatch/issues"
"url": "https://github.com/micromatch/picomatch/issues"
},

@@ -11,0 +11,0 @@ "license": "MIT",

@@ -35,3 +35,3 @@ <h1 align="center">Picomatch</h1>

See the [feature comparison](#feature-comparison) to other libraries.
See the [library comparison](#library-comparisons) to other libraries.

@@ -67,2 +67,170 @@ <br>

## API
### [picomatch](lib/picomatch.js#L30)
Creates a matcher function from one or more glob patterns. The returned function takes a string to match as its first argument, and returns true if the string is a match. The returned matcher function also takes a boolean as the second argument that, when true, returns an object with additional information.
**Params**
* `globs` **{String|Array}**: One or more glob patterns.
* `options` **{Object=}**
* `returns` **{Function=}**: Returns a matcher function.
**Example**
```js
const picomatch = require('picomatch');
// picomatch(glob[, options]);
const isMatch = picomatch('*.!(*a)');
console.log(isMatch('a.a')); //=> false
console.log(isMatch('a.b')); //=> true
```
### [.test](lib/picomatch.js#L109)
Test `input` with the given `regex`. This is used by the main `picomatch()` function to test the input string.
**Params**
* `input` **{String}**: String to test.
* `regex` **{RegExp}**
* `returns` **{Object}**: Returns an object with matching info.
**Example**
```js
const picomatch = require('picomatch');
// picomatch.test(input, regex[, options]);
console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
// { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
```
### [.matchBase](lib/picomatch.js#L153)
Match the basename of a filepath.
**Params**
* `input` **{String}**: String to test.
* `glob` **{RegExp|String}**: Glob pattern or regex created by [.makeRe](#makeRe).
* `returns` **{Boolean}**
**Example**
```js
const picomatch = require('picomatch');
// picomatch.matchBase(input, glob[, options]);
console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
```
### [.isMatch](lib/picomatch.js#L175)
Returns true if **any** of the given glob `patterns` match the specified `string`.
**Params**
* **{String|Array}**: str The string to test.
* **{String|Array}**: patterns One or more glob patterns to use for matching.
* **{Object}**: See available [options](#options).
* `returns` **{Boolean}**: Returns true if any patterns match `str`
**Example**
```js
const picomatch = require('picomatch');
// picomatch.isMatch(string, patterns[, options]);
console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
```
### [.parse](lib/picomatch.js#L191)
Parse a glob pattern to create the source string for a regular expression.
**Params**
* `glob` **{String}**
* `options` **{Object}**
* `returns` **{Object}**: Returns an object with useful properties and output to be used as a regex source string.
**Example**
```js
const picomatch = require('picomatch');
const result = picomatch.parse(glob[, options]);
```
### [.scan](lib/picomatch.js#L215)
Scan a glob pattern to separate the pattern into segments.
**Params**
* `input` **{String}**: Glob pattern to scan.
* `options` **{Object}**
* `returns` **{Object}**: Returns an object with
**Example**
```js
const picomatch = require('picomatch');
// picomatch.scan(input[, options]);
const result = picomatch.scan('!./foo/*.js');
console.log(result);
// { prefix: '!./',
// input: '!./foo/*.js',
// base: 'foo',
// glob: '*.js',
// negated: true,
// isGlob: true }
```
### [.makeRe](lib/picomatch.js#L233)
Create a regular expression from a glob pattern.
**Params**
* `input` **{String}**: A glob pattern to convert to regex.
* `options` **{Object}**
* `returns` **{RegExp}**: Returns a regex created from the given pattern.
**Example**
```js
const picomatch = require('picomatch');
// picomatch.makeRe(input[, options]);
console.log(picomatch.makeRe('*.js'));
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
```
### [.toRegex](lib/picomatch.js#L294)
Create a regular expression from the given regex source string.
**Params**
* `source` **{String}**: Regular expression source string.
* `options` **{Object}**
* `returns` **{RegExp}**
**Example**
```js
const picomatch = require('picomatch');
// picomatch.toRegex(source[, options]);
const { output } = picomatch.parse('*.js');
console.log(picomatch.toRegex(output));
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
```
<br>
## Options

@@ -438,3 +606,3 @@

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2017-present, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc