Socket
Socket
Sign inDemoInstall

picomatch

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picomatch - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

lib/.DS_Store

7

CHANGELOG.md

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

## 2.2.0 (2020-01-04)
* Disable fastpaths mode for the parse method ([5b8d33f](https://github.com/micromatch/picomatch/commit/5b8d33f))
* Add `tokens`, `slashes`, and `parts` to the object returned by `picomatch.scan()`.
## 2.1.0 (2019-10-31)

@@ -99,2 +104,2 @@

[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog

42

lib/parse.js

@@ -126,2 +126,3 @@ 'use strict';

quotes: 0,
globstar: false,
tokens

@@ -212,2 +213,3 @@ };

prev.value += tok.value;
prev.output = (prev.output || '') + tok.value;
return;

@@ -246,3 +248,3 @@ }

if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
output = token.close = ')$))' + extglobStar;
output = token.close = `)$))${extglobStar}`;
}

@@ -292,3 +294,3 @@

}
return esc ? m : '\\' + m;
return esc ? m : `\\${m}`;
});

@@ -402,7 +404,7 @@

if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
value = '\\' + value;
value = `\\${value}`;
}
if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
value = '\\' + value;
value = `\\${value}`;
}

@@ -479,3 +481,3 @@

value = '\\' + value;
value = `\\${value}`;
} else {

@@ -491,3 +493,3 @@ increment('brackets');

if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
push({ type: 'text', value, output: '\\' + value });
push({ type: 'text', value, output: `\\${value}` });
continue;

@@ -501,3 +503,3 @@ }

push({ type: 'text', value, output: '\\' + value });
push({ type: 'text', value, output: `\\${value}` });
continue;

@@ -510,3 +512,3 @@ }

if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
value = '/' + value;
value = `/${value}`;
}

@@ -673,3 +675,3 @@

if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
output = '\\' + value;
output = `\\${value}`;
}

@@ -703,3 +705,3 @@

if (opts.nonegate !== true && state.index === 0) {
negate(state);
negate();
continue;

@@ -753,3 +755,3 @@ }

if (value === '$' || value === '^') {
value = '\\' + value;
value = `\\${value}`;
}

@@ -777,2 +779,3 @@

state.backtrack = true;
state.globstar = true;
consume(value);

@@ -826,2 +829,3 @@ continue;

state.output = prev.output;
state.globstar = true;
consume(value);

@@ -833,3 +837,3 @@ continue;

state.output = state.output.slice(0, -(prior.output + prev.output).length);
prior.output = '(?:' + prior.output;
prior.output = `(?:${prior.output}`;

@@ -839,3 +843,3 @@ prev.type = 'globstar';

prev.value += value;
state.globstar = true;
state.output += prior.output + prev.output;

@@ -850,3 +854,3 @@ consume(value);

state.output = state.output.slice(0, -(prior.output + prev.output).length);
prior.output = '(?:' + prior.output;
prior.output = `(?:${prior.output}`;

@@ -858,5 +862,7 @@ prev.type = 'globstar';

state.output += prior.output + prev.output;
state.globstar = true;
consume(value + advance());
push({ type: 'slash', value, output: '' });
push({ type: 'slash', value: '/', output: '' });
continue;

@@ -870,4 +876,5 @@ }

state.output = prev.output;
state.globstar = true;
consume(value + advance());
push({ type: 'slash', value, output: '' });
push({ type: 'slash', value: '/', output: '' });
continue;

@@ -886,2 +893,3 @@ }

state.output += prev.output;
state.globstar = true;
consume(value);

@@ -1044,3 +1052,3 @@ continue;

const source = create(match[1], options);
const source = create(match[1]);
if (!source) return;

@@ -1047,0 +1055,0 @@

@@ -8,2 +8,3 @@ 'use strict';

const constants = require('./constants');
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);

@@ -35,3 +36,3 @@ /**

const fns = glob.map(input => picomatch(input, options, returnState));
return str => {
const arrayMatcher = str => {
for (const isMatch of fns) {

@@ -43,5 +44,8 @@ const state = isMatch(str);

};
return arrayMatcher;
}
if (typeof glob !== 'string' || glob === '') {
const isState = isObject(glob) && glob.tokens && glob.input;
if (glob === '' || (typeof glob !== 'string' && !isState)) {
throw new TypeError('Expected pattern to be a non-empty string');

@@ -52,3 +56,6 @@ }

const posix = utils.isWindows(options);
const regex = picomatch.makeRe(glob, options, false, true);
const regex = isState
? picomatch.compileRe(glob, options)
: picomatch.makeRe(glob, options, false, true);
const state = regex.state;

@@ -141,3 +148,3 @@ delete regex.state;

return { isMatch: !!match, match, output };
return { isMatch: Boolean(match), match, output };
};

@@ -189,5 +196,5 @@

* const picomatch = require('picomatch');
* const result = picomatch.parse(glob[, options]);
* const result = picomatch.parse(pattern[, options]);
* ```
* @param {String} `glob`
* @param {String} `pattern`
* @param {Object} `options`

@@ -198,3 +205,6 @@ * @return {Object} Returns an object with useful properties and output to be used as a regex source string.

picomatch.parse = (glob, options) => parse(glob, options);
picomatch.parse = (pattern, options) => {
if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
return parse(pattern, { ...options, fastpaths: false });
};

@@ -210,8 +220,13 @@ /**

* console.log(result);
* // { prefix: '!./',
* // input: '!./foo/*.js',
* // base: 'foo',
* // glob: '*.js',
* // negated: true,
* // isGlob: true }
* { prefix: '!./',
* input: '!./foo/*.js',
* start: 3,
* base: 'foo',
* glob: '*.js',
* isBrace: false,
* isBracket: false,
* isGlob: true,
* isExtglob: false,
* isGlobstar: false,
* negated: true }
* ```

@@ -242,2 +257,24 @@ * @param {String} `input` Glob pattern to scan.

picomatch.compileRe = (parsed, options, returnOutput = false, returnState = false) => {
if (returnOutput === true) {
return parsed.output;
}
const opts = options || {};
const prepend = opts.contains ? '' : '^';
const append = opts.contains ? '' : '$';
let source = `${prepend}(?:${parsed.output})${append}`;
if (parsed && parsed.negated === true) {
source = `^(?!${source}).*$`;
}
const regex = picomatch.toRegex(source, options);
if (returnState === true) {
regex.state = parsed;
}
return regex;
};
picomatch.makeRe = (input, options, returnOutput = false, returnState = false) => {

@@ -249,5 +286,3 @@ if (!input || typeof input !== 'string') {

const opts = options || {};
const prepend = opts.contains ? '' : '^';
const append = opts.contains ? '' : '$';
let state = { negated: false, fastpaths: true };
let parsed = { negated: false, fastpaths: true };
let prefix = '';

@@ -258,3 +293,3 @@ let output;

input = input.slice(2);
prefix = state.prefix = './';
prefix = parsed.prefix = './';
}

@@ -266,23 +301,10 @@

if (output === void 0) {
state = picomatch.parse(input, options);
state.prefix = prefix + (state.prefix || '');
output = state.output;
if (output === undefined) {
parsed = parse(input, options);
parsed.prefix = prefix + (parsed.prefix || '');
} else {
parsed.output = output;
}
if (returnOutput === true) {
return output;
}
let source = `${prepend}(?:${output})${append}`;
if (state && state.negated === true) {
source = `^(?!${source}).*$`;
}
const regex = picomatch.toRegex(source, options);
if (returnState === true) {
regex.state = state;
}
return regex;
return picomatch.compileRe(parsed, options, returnOutput, returnState);
};

@@ -289,0 +311,0 @@

@@ -26,2 +26,8 @@ 'use strict';

const depth = token => {
if (token.isPrefix !== true) {
token.depth = token.isGlobstar ? Infinity : 1;
}
};
/**

@@ -43,21 +49,34 @@ * Quickly scans a glob pattern and returns an object with a handful of

module.exports = (input, options) => {
const scan = (input, options) => {
const opts = options || {};
const length = input.length - 1;
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
const slashes = [];
const tokens = [];
const parts = [];
let str = input;
let index = -1;
let start = 0;
let lastIndex = 0;
let isBrace = false;
let isBracket = false;
let isGlob = false;
let isExtglob = false;
let isGlobstar = false;
let braceEscaped = false;
let backslashes = false;
let negated = false;
let finished = false;
let braces = 0;
let prev;
let code;
let token = { value: '', depth: 0, isGlob: false };
let braceEscaped = false;
const eos = () => index >= length;
const peek = () => str.charCodeAt(index + 1);
const advance = () => {
prev = code;
return input.charCodeAt(++index);
return str.charCodeAt(++index);
};

@@ -70,6 +89,6 @@

if (code === CHAR_BACKWARD_SLASH) {
backslashes = true;
next = advance();
backslashes = token.backslashes = true;
code = advance();
if (next === CHAR_LEFT_CURLY_BRACE) {
if (code === CHAR_LEFT_CURLY_BRACE) {
braceEscaped = true;

@@ -83,10 +102,10 @@ }

while (!eos() && (next = advance())) {
if (next === CHAR_BACKWARD_SLASH) {
backslashes = true;
next = advance();
while (eos() !== true && (code = advance())) {
if (code === CHAR_BACKWARD_SLASH) {
backslashes = token.backslashes = true;
advance();
continue;
}
if (next === CHAR_LEFT_CURLY_BRACE) {
if (code === CHAR_LEFT_CURLY_BRACE) {
braces++;

@@ -96,16 +115,33 @@ continue;

if (!braceEscaped && next === CHAR_DOT && (next = advance()) === CHAR_DOT) {
isGlob = true;
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
isBrace = token.isBrace = true;
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;
}
if (!braceEscaped && next === CHAR_COMMA) {
isGlob = true;
if (braceEscaped !== true && code === CHAR_COMMA) {
isBrace = token.isBrace = true;
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;
}
if (next === CHAR_RIGHT_CURLY_BRACE) {
if (code === CHAR_RIGHT_CURLY_BRACE) {
braces--;
if (braces === 0) {
braceEscaped = false;
isBrace = token.isBrace = true;
finished = true;
break;

@@ -115,5 +151,16 @@ }

}
if (scanToEnd === true) {
continue;
}
break;
}
if (code === CHAR_FORWARD_SLASH) {
slashes.push(index);
tokens.push(token);
token = { value: '', depth: 0, isGlob: false };
if (finished === true) continue;
if (prev === CHAR_DOT && index === (start + 1)) {

@@ -128,9 +175,52 @@ start += 2;

if (opts.noext !== true) {
const isExtglobChar = code === CHAR_PLUS
|| code === CHAR_AT
|| code === CHAR_ASTERISK
|| code === CHAR_QUESTION_MARK
|| code === CHAR_EXCLAMATION_MARK;
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
isGlob = token.isGlob = true;
isExtglob = token.isExtglob = true;
finished = true;
if (scanToEnd === true) {
while (eos() !== true && (code = advance())) {
if (code === CHAR_BACKWARD_SLASH) {
backslashes = token.backslashes = true;
code = advance();
continue;
}
if (code === CHAR_RIGHT_PARENTHESES) {
isGlob = token.isGlob = true;
finished = true;
break;
}
}
continue;
}
break;
}
}
if (code === CHAR_ASTERISK) {
isGlob = true;
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;
}
if (code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK) {
isGlob = true;
if (code === CHAR_QUESTION_MARK) {
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;

@@ -140,6 +230,6 @@ }

if (code === CHAR_LEFT_SQUARE_BRACKET) {
while (!eos() && (next = advance())) {
while (eos() !== true && (next = advance())) {
if (next === CHAR_BACKWARD_SLASH) {
backslashes = true;
next = advance();
backslashes = token.backslashes = true;
advance();
continue;

@@ -149,3 +239,9 @@ }

if (next === CHAR_RIGHT_SQUARE_BRACKET) {
isGlob = true;
isBracket = token.isBracket = true;
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;

@@ -156,13 +252,4 @@ }

const isExtglobChar = code === CHAR_PLUS
|| code === CHAR_AT
|| code === CHAR_EXCLAMATION_MARK;
if (isExtglobChar && input.charCodeAt(index + 1) === CHAR_LEFT_PARENTHESES) {
isGlob = true;
break;
}
if (!opts.nonegate && code === CHAR_EXCLAMATION_MARK && index === start) {
negated = true;
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
negated = token.negated = true;
start++;

@@ -173,5 +260,5 @@ continue;

if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
while (!eos() && (code = advance())) {
while (eos() !== true && (code = advance())) {
if (code === CHAR_BACKWARD_SLASH) {
backslashes = true;
backslashes = token.backslashes = true;
code = advance();

@@ -182,3 +269,8 @@ continue;

if (code === CHAR_RIGHT_PARENTHESES) {
isGlob = true;
isGlob = token.isGlob = true;
finished = true;
if (scanToEnd === true) {
continue;
}
break;

@@ -189,3 +281,9 @@ }

if (isGlob) {
if (isGlob === true) {
finished = true;
if (scanToEnd === true) {
continue;
}
break;

@@ -196,13 +294,13 @@ }

if (opts.noext === true) {
isExtglob = false;
isGlob = false;
}
let base = str;
let prefix = '';
const orig = input;
let base = input;
let glob = '';
if (start > 0) {
prefix = input.slice(0, start);
input = input.slice(start);
prefix = str.slice(0, start);
str = str.slice(start);
lastIndex -= start;

@@ -212,12 +310,12 @@ }

if (base && isGlob === true && lastIndex > 0) {
base = input.slice(0, lastIndex);
glob = input.slice(lastIndex);
base = str.slice(0, lastIndex);
glob = str.slice(lastIndex);
} else if (isGlob === true) {
base = '';
glob = input;
glob = str;
} else {
base = input;
base = str;
}
if (base && base !== '' && base !== '/' && base !== input) {
if (base && base !== '' && base !== '/' && base !== str) {
if (isPathSeparator(base.charCodeAt(base.length - 1))) {

@@ -236,3 +334,65 @@ base = base.slice(0, -1);

return { prefix, input: orig, base, glob, negated, isGlob };
const state = {
prefix,
input,
start,
base,
glob,
isBrace,
isBracket,
isGlob,
isExtglob,
isGlobstar,
negated
};
if (opts.tokens === true) {
state.maxDepth = 0;
if (!isPathSeparator(code)) {
tokens.push(token);
}
state.tokens = tokens;
}
if (opts.parts === true || opts.tokens === true) {
let prevIndex;
for (let idx = 0; idx < slashes.length; idx++) {
const n = prevIndex ? prevIndex + 1 : start;
const i = slashes[idx];
const value = input.slice(n, i);
if (opts.tokens) {
if (idx === 0 && start !== 0) {
tokens[idx].isPrefix = true;
tokens[idx].value = prefix;
} else {
tokens[idx].value = value;
}
depth(tokens[idx]);
state.maxDepth += tokens[idx].depth;
}
if (idx !== 0 || value !== '') {
parts.push(value);
}
prevIndex = i;
}
if (prevIndex && prevIndex + 1 < input.length) {
const value = input.slice(prevIndex + 1);
parts.push(value);
if (opts.tokens) {
tokens[tokens.length - 1].value = value;
depth(tokens[tokens.length - 1]);
state.maxDepth += tokens[tokens.length - 1].depth;
}
}
state.slashes = slashes;
state.parts = parts;
}
return state;
};
module.exports = scan;

@@ -43,3 +43,3 @@ 'use strict';

if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
return input.slice(0, idx) + '\\' + input.slice(idx);
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
};

@@ -46,0 +46,0 @@

{
"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.1.1",
"version": "2.2.0",
"homepage": "https://github.com/micromatch/picomatch",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"funding": "https://github.com/sponsors/jonschlinkert",
"repository": "micromatch/picomatch",

@@ -21,10 +22,14 @@ "bugs": {

"scripts": {
"test": "mocha",
"cover": "nyc --reporter=text --reporter=html mocha"
"lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
"mocha": "mocha --reporter dot",
"test": "npm run lint && npm run mocha",
"test:ci": "npm run lint && npm run test:cover",
"test:cover": "nyc npm run mocha"
},
"devDependencies": {
"eslint": "^6.8.0",
"fill-range": "^7.0.1",
"gulp-format-md": "^2.0.0",
"mocha": "^6.0.2",
"nyc": "^13.3.0",
"mocha": "^6.2.2",
"nyc": "^15.0.0",
"time-require": "github:jonschlinkert/time-require"

@@ -37,5 +42,16 @@ },

],
"nyc": {
"reporter": [
"html",
"lcov",
"text-summary"
]
},
"verb": {
"toc": false,
"layout": false,
"toc": {
"render": true,
"method": "preWrite",
"maxdepth": 3
},
"layout": "empty",
"tasks": [

@@ -52,4 +68,4 @@ "readme"

"list": [
"micromatch",
"braces"
"braces",
"micromatch"
]

@@ -68,2 +84,2 @@ },

}
}
}
<h1 align="center">Picomatch</h1>
<p align="center">
<a href="https://npmjs.org/package/picomatch">
<img src="https://img.shields.io/npm/v/picomatch.svg" alt="version" />
</a>
<a href="https://travis-ci.org/micromatch/picomatch">
<img src="https://img.shields.io/travis/micromatch/picomatch.svg" alt="travis" />
</a>
<a href="https://npmjs.org/package/picomatch">
<img src="https://img.shields.io/npm/dm/picomatch.svg" alt="downloads" />
</a>
<a href="https://npmjs.org/package/picomatch">
<img src="https://img.shields.io/npm/v/picomatch.svg" alt="version">
</a>
<a href="https://github.com/micromatch/picomatch/actions?workflow=Tests">
<img src="https://github.com/micromatch/picomatch/workflows/Tests/badge.svg" alt="test status">
</a>
<a href="https://coveralls.io/github/micromatch/picomatch">
<img src="https://img.shields.io/coveralls/github/micromatch/picomatch/master.svg" alt="coverage status">
</a>
<a href="https://npmjs.org/package/picomatch">
<img src="https://img.shields.io/npm/dm/picomatch.svg" alt="downloads">
</a>
</p>

@@ -40,2 +43,40 @@

## Table of Contents
<details><summary> Click to expand </summary>
- [Install](#install)
- [Usage](#usage)
- [API](#api)
* [picomatch](#picomatch)
* [.test](#test)
* [.matchBase](#matchbase)
* [.isMatch](#ismatch)
* [.parse](#parse)
* [.scan](#scan)
* [.compileRe](#compilere)
* [.toRegex](#toregex)
- [Options](#options)
* [Picomatch options](#picomatch-options)
* [Scan Options](#scan-options)
* [Options Examples](#options-examples)
- [Globbing features](#globbing-features)
* [Basic globbing](#basic-globbing)
* [Advanced globbing](#advanced-globbing)
* [Braces](#braces)
* [Matching special characters as literals](#matching-special-characters-as-literals)
- [Library Comparisons](#library-comparisons)
- [Benchmarks](#benchmarks)
- [Philosophies](#philosophies)
- [About](#about)
* [Author](#author)
* [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
</details>
<br>
<br>
## Install

@@ -46,3 +87,3 @@

```sh
$ npm install --save picomatch
npm install --save picomatch
```

@@ -70,3 +111,3 @@

### [picomatch](lib/picomatch.js#L31)
### [picomatch](lib/picomatch.js#L32)

@@ -92,3 +133,3 @@ 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.

### [.test](lib/picomatch.js#L110)
### [.test](lib/picomatch.js#L117)

@@ -113,3 +154,3 @@ Test `input` with the given `regex`. This is used by the main `picomatch()` function to test the input string.

### [.matchBase](lib/picomatch.js#L154)
### [.matchBase](lib/picomatch.js#L161)

@@ -132,3 +173,3 @@ Match the basename of a filepath.

### [.isMatch](lib/picomatch.js#L176)
### [.isMatch](lib/picomatch.js#L183)

@@ -154,3 +195,3 @@ Returns true if **any** of the given glob `patterns` match the specified `string`.

### [.parse](lib/picomatch.js#L192)
### [.parse](lib/picomatch.js#L199)

@@ -161,3 +202,3 @@ Parse a glob pattern to create the source string for a regular expression.

* `glob` **{String}**
* `pattern` **{String}**
* `options` **{Object}**

@@ -170,6 +211,6 @@ * `returns` **{Object}**: Returns an object with useful properties and output to be used as a regex source string.

const picomatch = require('picomatch');
const result = picomatch.parse(glob[, options]);
const result = picomatch.parse(pattern[, options]);
```
### [.scan](lib/picomatch.js#L216)
### [.scan](lib/picomatch.js#L231)

@@ -192,11 +233,16 @@ Scan a glob pattern to separate the pattern into segments.

console.log(result);
// { prefix: '!./',
// input: '!./foo/*.js',
// base: 'foo',
// glob: '*.js',
// negated: true,
// isGlob: true }
{ prefix: '!./',
input: '!./foo/*.js',
start: 3,
base: 'foo',
glob: '*.js',
isBrace: false,
isBracket: false,
isGlob: true,
isExtglob: false,
isGlobstar: false,
negated: true }
```
### [.makeRe](lib/picomatch.js#L234)
### [.compileRe](lib/picomatch.js#L249)

@@ -221,3 +267,3 @@ Create a regular expression from a glob pattern.

### [.toRegex](lib/picomatch.js#L295)
### [.toRegex](lib/picomatch.js#L317)

@@ -247,2 +293,6 @@ Create a regular expression from the given regex source string.

### Picomatch options
The following options may be used with the main `picomatch()` function or any of the methods on the picomatch API.
| **Option** | **Type** | **Default value** | **Description** |

@@ -280,3 +330,3 @@ | --- | --- | --- | --- |

| [onResult](#optionsonResult) | `function` | `undefined` | Function to be called on all items, regardless of whether or not they are matched or ignored. |
| `posix` | `boolean` | `false` | Support POSX character classes ("posix brackets"). |
| `posix` | `boolean` | `false` | Support POSIX character classes ("posix brackets"). |
| `posixSlashes` | `boolean` | `undefined` | Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself |

@@ -288,9 +338,47 @@ | `prepend` | `boolean` | `undefined` | String to prepend to the generated regex used for matching. |

| `unescape` | `boolean` | `undefined` | Remove backslashes preceding escaped characters in the glob pattern. By default, backslashes are retained. |
| `unixify` | `boolean` | `undefined` | Alias for `posixSlashes`, for backwards compatitibility. |
| `unixify` | `boolean` | `undefined` | Alias for `posixSlashes`, for backwards compatibility. |
### Scan Options
In addition to the main [picomatch options](#picomatch-options), the following options may also be used with the [.scan](#scan) method.
| **Option** | **Type** | **Default value** | **Description** |
| --- | --- | --- | --- |
| `tokens` | `boolean` | `false` | When `true`, the returned object will include an array of tokens (objects), representing each path "segment" in the scanned glob pattern |
| `parts` | `boolean` | `false` | When `true`, the returned object will include an array of strings representing each path "segment" in the scanned glob pattern. This is automatically enabled when `options.tokens` is true |
**Example**
```js
const picomatch = require('picomatch');
const result = picomatch.scan('!./foo/*.js', { tokens: true });
console.log(result);
// {
// prefix: '!./',
// input: '!./foo/*.js',
// start: 3,
// base: 'foo',
// glob: '*.js',
// isBrace: false,
// isBracket: false,
// isGlob: true,
// isExtglob: false,
// isGlobstar: false,
// negated: true,
// maxDepth: 2,
// tokens: [
// { value: '!./', depth: 0, isGlob: false, negated: true, isPrefix: true },
// { value: 'foo', depth: 1, isGlob: false },
// { value: '*.js', depth: 1, isGlob: true }
// ],
// slashes: [ 2, 6 ],
// parts: [ 'foo', '*.js' ]
// }
```
<br>
## Options Examples
### Options Examples
### options.expandRange
#### options.expandRange

@@ -326,3 +414,3 @@ **Type**: `function`

### options.format
#### options.format

@@ -344,3 +432,3 @@ **Type**: `function`

### options.onMatch
#### options.onMatch

@@ -358,3 +446,3 @@ ```js

### options.onIgnore
#### options.onIgnore

@@ -372,3 +460,3 @@ ```js

### options.onResult
#### options.onResult

@@ -389,3 +477,3 @@ ```js

# Globbing features
## Globbing features

@@ -395,12 +483,12 @@ * [Basic globbing](#basic-globbing) (Wildcard matching)

## Basic globbing
### Basic globbing
| **Character** | **Description** |
| --- | --- |
| `*` | Matches any character zero or more times, excluding path separators. Does _not match_ path separators or hidden files or directories ("dotfiles"), unless explicitly enabled by setting the `dot` option to `true`. |
| `**` | Matches any character zero or more times, including path separators. Note that `**` will only match path separators (`/`, and `\\` on Windows) when they are the only characters in a path segment. Thus, `foo**/bar` is equivalent to `foo*/bar`, and `foo/a**b/bar` is equivalent to `foo/a*b/bar`, and _more than two_ consecutive stars in a glob path segment are regarded as _a single star_. Thus, `foo/***/bar` is equivalent to `foo/*/bar`. |
| `?` | Matches any character excluding path separators one time. Does _not match_ path separators or leading dots. |
| `[abc]` | Matches any characters inside the brackets. For example, `[abc]` would match the characters `a`, `b` or `c`, and nothing else. |
| **Character** | **Description** |
| --- | --- |
| `*` | Matches any character zero or more times, excluding path separators. Does _not match_ path separators or hidden files or directories ("dotfiles"), unless explicitly enabled by setting the `dot` option to `true`. |
| `**` | Matches any character zero or more times, including path separators. Note that `**` will only match path separators (`/`, and `\\` on Windows) when they are the only characters in a path segment. Thus, `foo**/bar` is equivalent to `foo*/bar`, and `foo/a**b/bar` is equivalent to `foo/a*b/bar`, and _more than two_ consecutive stars in a glob path segment are regarded as _a single star_. Thus, `foo/***/bar` is equivalent to `foo/*/bar`. |
| `?` | Matches any character excluding path separators one time. Does _not match_ path separators or leading dots. |
| `[abc]` | Matches any characters inside the brackets. For example, `[abc]` would match the characters `a`, `b` or `c`, and nothing else. |
### Matching behavior vs. Bash
#### Matching behavior vs. Bash

@@ -414,3 +502,3 @@ Picomatch's matching features and expected results in unit tests are based on Bash's unit tests and the Bash 4.3 specification, with the following exceptions:

## Advanced globbing
### Advanced globbing

@@ -421,6 +509,6 @@ * [extglobs](#extglobs)

### Extglobs
#### Extglobs
| **Pattern** | **Description** |
| --- | --- | --- |
| --- | --- |
| `@(pattern)` | Match _only one_ consecutive occurrence of `pattern` |

@@ -450,7 +538,7 @@ | `*(pattern)` | Match _zero or more_ consecutive occurrences of `pattern` |

// supports nested extglobs
// supports nested extglobs
console.log(pm.isMatch('foo.bar', '!(!(foo)).!(!(bar))')); // true
```
### POSIX brackets
#### POSIX brackets

@@ -487,7 +575,7 @@ POSIX classes are disabled by default. Enable this feature by setting the `posix` option to true.

## Braces
### Braces
Picomatch does not do brace expansion. For [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) and advanced matching with braces, use [micromatch](https://github.com/micromatch/micromatch) instead. Picomatch has very basic support for braces.
## Matching special characters as literals
### Matching special characters as literals

@@ -569,3 +657,3 @@ If you wish to match the following special characters in a filepath, and you want to use these characters in your glob pattern, they must be escaped with backslashes or quotes:

The number one of goal of this libary is accuracy. However, it's not unusual for different glob implementations to have different rules for matching behavior, even with simple wildcard matching. It gets increasingly more complicated when combinations of different features are combined, like when extglobs are combined with globstars, braces, slashes, and so on: `!(**/{a,b,*/c})`.
The number one of goal of this library is accuracy. However, it's not unusual for different glob implementations to have different rules for matching behavior, even with simple wildcard matching. It gets increasingly more complicated when combinations of different features are combined, like when extglobs are combined with globstars, braces, slashes, and so on: `!(**/{a,b,*/c})`.

@@ -598,3 +686,3 @@ Thus, given that there is no canonical glob specification to use as a single source of truth when differences of opinion arise regarding behavior, sometimes we have to implement our best judgement and rely on feedback from users to make improvements.

```sh
$ npm install && npm test
npm install && npm test
```

@@ -612,3 +700,3 @@

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
npm install -g verbose/verb#dev verb-generate-readme && verb
```

@@ -629,2 +717,2 @@

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

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc