Skip to content

Commit

Permalink
provide picomatch/posix, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Dec 13, 2021
1 parent 5f88af5 commit 7e120bb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Creates a matcher function from one or more glob patterns. The returned function

**Example**

By default, `picomatch` uses [`os.platform()`](https://nodejs.org/api/os.html#osplatform) to detect the operating system.

```js
const picomatch = require('picomatch');
// picomatch(glob[, options]);
Expand All @@ -127,6 +129,23 @@ console.log(isMatch('a.a')); //=> false
console.log(isMatch('a.b')); //=> true
```

**Example without node.js**

For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.

```js
const picomatch = require('picomatch/posix');
// the same API, defaulting to posix paths
const isMatch = picomatch('a/*');
console.log(isMatch('a\\b')); //=> false
console.log(isMatch('a/b')); //=> true

// you can still configure the matcher function to accept windows paths
const isMatch = picomatch('a/*', { options: windows });
console.log(isMatch('a\\b')); //=> true
console.log(isMatch('a/b')); //=> true
```

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

Test `input` with the given `regex`. This is used by the main `picomatch()` function to test the input string.
Expand Down
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
'use strict';

module.exports = require('./lib/picomatch');
const os = require('os');
const pico = require('./lib/picomatch');

const isWindows = os.platform() === 'win32';

function picomatch(glob, options, returnState = false) {
// default to os.platform()
if (options.windows === null || options.windows === undefined) {
options.windows = isWindows;
}
return pico(glob, options, returnState);
}

module.exports = picomatch;
// public api
module.exports.test = pico.test;
module.exports.matchBase = pico.matchBase;
module.exports.isMatch = pico.isMatch;
module.exports.parse = pico.parse;
module.exports.scan = pico.scan;
module.exports.compileRe = pico.compileRe;
module.exports.toRegex = pico.toRegex;
// for tests
module.exports.makeRe = pico.makeRe;
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "picomatch-browser",
"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.",
"version": "2.2.5",
"homepage": "https://github.com/acao/picomatch",
"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.2.2",
"homepage": "https://github.com/micromatch/picomatch",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"funding": "https://github.com/sponsors/jonschlinkert",
"repository": "micromatch/picomatch",
Expand All @@ -12,6 +12,7 @@
"license": "MIT",
"files": [
"index.js",
"posix.js",
"lib"
],
"main": "index.js",
Expand Down
3 changes: 3 additions & 0 deletions posix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./lib/picomatch');
17 changes: 17 additions & 0 deletions test/api.posix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const assert = require('assert');
const picomatch = require('../posix');

describe('picomatch/posix', () => {
it('should use posix paths only by default', () => {
const match = picomatch('a/**');
assert(match('a/b'));
assert(!match('a\\b'));
});
it('should still be manually configurable to accept non-posix paths', () => {
const match = picomatch('a/**', { windows: true });
assert(match('a\\b'));
assert(match('a/b'));
});
});

0 comments on commit 7e120bb

Please sign in to comment.