Skip to content

Commit 7e120bb

Browse files
committed
provide picomatch/posix, documentation
1 parent 5f88af5 commit 7e120bb

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Creates a matcher function from one or more glob patterns. The returned function
118118

119119
**Example**
120120

121+
By default, `picomatch` uses [`os.platform()`](https://nodejs.org/api/os.html#osplatform) to detect the operating system.
122+
121123
```js
122124
const picomatch = require('picomatch');
123125
// picomatch(glob[, options]);
@@ -127,6 +129,23 @@ console.log(isMatch('a.a')); //=> false
127129
console.log(isMatch('a.b')); //=> true
128130
```
129131

132+
**Example without node.js**
133+
134+
For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.
135+
136+
```js
137+
const picomatch = require('picomatch/posix');
138+
// the same API, defaulting to posix paths
139+
const isMatch = picomatch('a/*');
140+
console.log(isMatch('a\\b')); //=> false
141+
console.log(isMatch('a/b')); //=> true
142+
143+
// you can still configure the matcher function to accept windows paths
144+
const isMatch = picomatch('a/*', { options: windows });
145+
console.log(isMatch('a\\b')); //=> true
146+
console.log(isMatch('a/b')); //=> true
147+
```
148+
130149
### [.test](lib/picomatch.js#L117)
131150

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

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
'use strict';
22

3-
module.exports = require('./lib/picomatch');
3+
const os = require('os');
4+
const pico = require('./lib/picomatch');
5+
6+
const isWindows = os.platform() === 'win32';
7+
8+
function picomatch(glob, options, returnState = false) {
9+
// default to os.platform()
10+
if (options.windows === null || options.windows === undefined) {
11+
options.windows = isWindows;
12+
}
13+
return pico(glob, options, returnState);
14+
}
15+
16+
module.exports = picomatch;
17+
// public api
18+
module.exports.test = pico.test;
19+
module.exports.matchBase = pico.matchBase;
20+
module.exports.isMatch = pico.isMatch;
21+
module.exports.parse = pico.parse;
22+
module.exports.scan = pico.scan;
23+
module.exports.compileRe = pico.compileRe;
24+
module.exports.toRegex = pico.toRegex;
25+
// for tests
26+
module.exports.makeRe = pico.makeRe;

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "picomatch-browser",
3-
"description": "(temporary fork of picomatch) 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.",
4-
"version": "2.2.5",
5-
"homepage": "https://github.com/acao/picomatch",
2+
"name": "picomatch",
3+
"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.",
4+
"version": "2.2.2",
5+
"homepage": "https://github.com/micromatch/picomatch",
66
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
77
"funding": "https://github.com/sponsors/jonschlinkert",
88
"repository": "micromatch/picomatch",
@@ -12,6 +12,7 @@
1212
"license": "MIT",
1313
"files": [
1414
"index.js",
15+
"posix.js",
1516
"lib"
1617
],
1718
"main": "index.js",

posix.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./lib/picomatch');

test/api.posix.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const picomatch = require('../posix');
5+
6+
describe('picomatch/posix', () => {
7+
it('should use posix paths only by default', () => {
8+
const match = picomatch('a/**');
9+
assert(match('a/b'));
10+
assert(!match('a\\b'));
11+
});
12+
it('should still be manually configurable to accept non-posix paths', () => {
13+
const match = picomatch('a/**', { windows: true });
14+
assert(match('a\\b'));
15+
assert(match('a/b'));
16+
});
17+
});

0 commit comments

Comments
 (0)