pax_global_header 0000666 0000000 0000000 00000000064 13023574430 0014513 g ustar 00root root 0000000 0000000 52 comment=9a0ec493825eb0aa9368c158927ca4ace945fefa
expand-brackets-2.1.4/ 0000775 0000000 0000000 00000000000 13023574430 0014572 5 ustar 00root root 0000000 0000000 expand-brackets-2.1.4/.editorconfig 0000664 0000000 0000000 00000000405 13023574430 0017246 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false expand-brackets-2.1.4/.eslintrc.json 0000664 0000000 0000000 00000007125 13023574430 0017373 0 ustar 00root root 0000000 0000000 {
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
}
}
expand-brackets-2.1.4/.gitattributes 0000664 0000000 0000000 00000000017 13023574430 0017463 0 ustar 00root root 0000000 0000000 *.* text eol=lf expand-brackets-2.1.4/.gitignore 0000664 0000000 0000000 00000000343 13023574430 0016562 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
*.sublime-*
# test related, or directories generated by tests
test/actual
actual
coverage
# npm
node_modules
npm-debug.log
# misc
_gh_pages
benchmark
bower_components
vendor
temp
tmp
TODO.md
expand-brackets-2.1.4/.travis.yml 0000664 0000000 0000000 00000000154 13023574430 0016703 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
os:
- linux
- osx
node_js:
- node
- '6'
- '5'
- '0.12'
- '0.10'
expand-brackets-2.1.4/.verb.md 0000664 0000000 0000000 00000003164 13023574430 0016134 0 ustar 00root root 0000000 0000000 ## Usage
```js
var brackets = require('expand-brackets');
brackets(string[, options]);
```
**Params**
The main export is a function that takes the following parameters:
- `pattern` **{String}**: the pattern to convert
- `options` **{Object}**: optionally supply an options object
- `returns` **{String}**: returns a string that can be used to create a regex
**Example**
```js
console.log(brackets('[![:lower:]]'));
//=> '[^a-z]'
```
## API
{%= apidocs("index.js") %}
## Options
### options.sourcemap
Generate a source map for the given pattern.
**Example**
```js
var res = brackets('[:alpha:]', {sourcemap: true});
console.log(res.map);
// { version: 3,
// sources: [ 'brackets' ],
// names: [],
// mappings: 'AAAA,MAAS',
// sourcesContent: [ '[:alpha:]' ] }
```
### POSIX Character classes
The following named POSIX bracket expressions are supported:
- `[:alnum:]`: Alphanumeric characters (`a-zA-Z0-9]`)
- `[:alpha:]`: Alphabetic characters (`a-zA-Z]`)
- `[:blank:]`: Space and tab (`[ t]`)
- `[:digit:]`: Digits (`[0-9]`)
- `[:lower:]`: Lowercase letters (`[a-z]`)
- `[:punct:]`: Punctuation and symbols. (`[!"#$%&'()*+, -./:;<=>?@ [\]^_``{|}~]`)
- `[:upper:]`: Uppercase letters (`[A-Z]`)
- `[:word:]`: Word characters (letters, numbers and underscores) (`[A-Za-z0-9_]`)
- `[:xdigit:]`: Hexadecimal digits (`[A-Fa-f0-9]`)
See [posix-character-classes][] for more details.
**Not supported**
- [equivalence classes][gnu] are not supported
- [POSIX.2 collating symbols][gnu] are not supported
[gnu]: https://www.gnu.org/software/gawk/manual/html_node/Bracket-Expressions.html
## History
{%= changelog("changelog.md") %}
expand-brackets-2.1.4/LICENSE 0000664 0000000 0000000 00000002077 13023574430 0015605 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015-2016, Jon Schlinkert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
expand-brackets-2.1.4/README.md 0000664 0000000 0000000 00000023076 13023574430 0016061 0 ustar 00root root 0000000 0000000 # expand-brackets [](https://www.npmjs.com/package/expand-brackets) [](https://npmjs.org/package/expand-brackets) [](https://npmjs.org/package/expand-brackets) [](https://travis-ci.org/jonschlinkert/expand-brackets) [](https://ci.appveyor.com/project/jonschlinkert/expand-brackets)
> Expand POSIX bracket expressions (character classes) in glob patterns.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save expand-brackets
```
## Usage
```js
var brackets = require('expand-brackets');
brackets(string[, options]);
```
**Params**
The main export is a function that takes the following parameters:
* `pattern` **{String}**: the pattern to convert
* `options` **{Object}**: optionally supply an options object
* `returns` **{String}**: returns a string that can be used to create a regex
**Example**
```js
console.log(brackets('[![:lower:]]'));
//=> '[^a-z]'
```
## API
### [brackets](index.js#L29)
Parses the given POSIX character class `pattern` and returns a
string that can be used for creating regular expressions for matching.
**Params**
* `pattern` **{String}**
* `options` **{Object}**
* `returns` **{Object}**
### [.match](index.js#L54)
Takes an array of strings and a POSIX character class pattern, and returns a new array with only the strings that matched the pattern.
**Example**
```js
var brackets = require('expand-brackets');
console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
//=> ['a']
console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+'));
//=> ['a', 'ab']
```
**Params**
* `arr` **{Array}**: Array of strings to match
* `pattern` **{String}**: POSIX character class pattern(s)
* `options` **{Object}**
* `returns` **{Array}**
### [.isMatch](index.js#L100)
Returns true if the specified `string` matches the given brackets `pattern`.
**Example**
```js
var brackets = require('expand-brackets');
console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]'));
//=> true
console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]'));
//=> false
```
**Params**
* `string` **{String}**: String to match
* `pattern` **{String}**: Poxis pattern
* `options` **{String}**
* `returns` **{Boolean}**
### [.matcher](index.js#L123)
Takes a POSIX character class pattern and returns a matcher function. The returned function takes the string to match as its only argument.
**Example**
```js
var brackets = require('expand-brackets');
var isMatch = brackets.matcher('[[:lower:]].[[:upper:]]');
console.log(isMatch('a.a'));
//=> false
console.log(isMatch('a.A'));
//=> true
```
**Params**
* `pattern` **{String}**: Poxis pattern
* `options` **{String}**
* `returns` **{Boolean}**
### [.makeRe](index.js#L145)
Create a regular expression from the given `pattern`.
**Example**
```js
var brackets = require('expand-brackets');
var re = brackets.makeRe('[[:alpha:]]');
console.log(re);
//=> /^(?:[a-zA-Z])$/
```
**Params**
* `pattern` **{String}**: The pattern to convert to regex.
* `options` **{Object}**
* `returns` **{RegExp}**
### [.create](index.js#L187)
Parses the given POSIX character class `pattern` and returns an object with the compiled `output` and optional source `map`.
**Example**
```js
var brackets = require('expand-brackets');
console.log(brackets('[[:alpha:]]'));
// { options: { source: 'string' },
// input: '[[:alpha:]]',
// state: {},
// compilers:
// { eos: [Function],
// noop: [Function],
// bos: [Function],
// not: [Function],
// escape: [Function],
// text: [Function],
// posix: [Function],
// bracket: [Function],
// 'bracket.open': [Function],
// 'bracket.inner': [Function],
// 'bracket.literal': [Function],
// 'bracket.close': [Function] },
// output: '[a-zA-Z]',
// ast:
// { type: 'root',
// errors: [],
// nodes: [ [Object], [Object], [Object] ] },
// parsingErrors: [] }
```
**Params**
* `pattern` **{String}**
* `options` **{Object}**
* `returns` **{Object}**
## Options
### options.sourcemap
Generate a source map for the given pattern.
**Example**
```js
var res = brackets('[:alpha:]', {sourcemap: true});
console.log(res.map);
// { version: 3,
// sources: [ 'brackets' ],
// names: [],
// mappings: 'AAAA,MAAS',
// sourcesContent: [ '[:alpha:]' ] }
```
### POSIX Character classes
The following named POSIX bracket expressions are supported:
* `[:alnum:]`: Alphanumeric characters (`a-zA-Z0-9]`)
* `[:alpha:]`: Alphabetic characters (`a-zA-Z]`)
* `[:blank:]`: Space and tab (`[ t]`)
* `[:digit:]`: Digits (`[0-9]`)
* `[:lower:]`: Lowercase letters (`[a-z]`)
* `[:punct:]`: Punctuation and symbols. (`[!"#$%&'()*+, -./:;<=>?@ [\]^_``{|}~]`)
* `[:upper:]`: Uppercase letters (`[A-Z]`)
* `[:word:]`: Word characters (letters, numbers and underscores) (`[A-Za-z0-9_]`)
* `[:xdigit:]`: Hexadecimal digits (`[A-Fa-f0-9]`)
See [posix-character-classes](https://github.com/jonschlinkert/posix-character-classes) for more details.
**Not supported**
* [equivalence classes](https://www.gnu.org/software/gawk/manual/html_node/Bracket-Expressions.html) are not supported
* [POSIX.2 collating symbols](https://www.gnu.org/software/gawk/manual/html_node/Bracket-Expressions.html) are not supported
## Changelog
### v2.0.0
**Breaking changes**
* The main export now returns the compiled string, instead of the object returned from the compiler
**Added features**
* Adds a `.create` method to do what the main function did before v2.0.0
### v0.2.0
In addition to performance and matching improvements, the v0.2.0 refactor adds complete POSIX character class support, with the exception of equivalence classes and POSIX.2 collating symbols which are not relevant to node.js usage.
**Added features**
* parser is exposed, so that expand-brackets parsers can be used by upstream parsers (like [micromatch](https://github.com/jonschlinkert/micromatch))
* compiler is exposed, so that expand-brackets compilers can be used by upstream compilers
* source maps
**source map example**
```js
var brackets = require('expand-brackets');
var res = brackets('[:alpha:]');
console.log(res.map);
{ version: 3,
sources: [ 'brackets' ],
names: [],
mappings: 'AAAA,MAAS',
sourcesContent: [ '[:alpha:]' ] }
```
## About
### Related projects
* [braces](https://www.npmjs.com/package/braces): Fast, comprehensive, bash-like brace expansion implemented in JavaScript. Complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces) | [homepage](https://github.com/jonschlinkert/braces "Fast, comprehensive, bash-like brace expansion implemented in JavaScript. Complete support for the Bash 4.3 braces specification, without sacrificing speed.")
* [extglob](https://www.npmjs.com/package/extglob): Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… [more](https://github.com/jonschlinkert/extglob) | [homepage](https://github.com/jonschlinkert/extglob "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.")
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
* [nanomatch](https://www.npmjs.com/package/nanomatch): Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… [more](https://github.com/jonschlinkert/nanomatch) | [homepage](https://github.com/jonschlinkert/nanomatch "Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash 4.3 wildcard support only (no support for exglobs, posix brackets or braces)")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Contributors
| **Commits** | **Contributor**
|
| --- | --- |
| 66 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [MartinKolarik](https://github.com/MartinKolarik) |
| 2 | [es128](https://github.com/es128) |
| 1 | [eush77](https://github.com/eush77) |
### Building docs
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install -g verb verb-generate-readme && verb
```
### Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/expand-brackets/blob/master/LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on December 12, 2016._ expand-brackets-2.1.4/appveyor.yml 0000664 0000000 0000000 00000001065 13023574430 0017164 0 ustar 00root root 0000000 0000000 # Test against this version of Node.js
environment:
matrix:
# node.js
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "0.12"
- nodejs_version: "0.10"
# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test
# Don't actually build.
build: off
expand-brackets-2.1.4/changelog.md 0000664 0000000 0000000 00000001725 13023574430 0017050 0 ustar 00root root 0000000 0000000 ## Changelog
### v2.0.0
**Breaking changes**
- The main export now returns the compiled string, instead of the object returned from the compiler
**Added features**
- Adds a `.create` method to do what the main function did before v2.0.0
### v0.2.0
In addition to performance and matching improvements, the v0.2.0 refactor adds complete POSIX character class support, with the exception of equivalence classes and POSIX.2 collating symbols which are not relevant to node.js usage.
**Added features**
- parser is exposed, so that expand-brackets parsers can be used by upstream parsers (like [micromatch][])
- compiler is exposed, so that expand-brackets compilers can be used by upstream compilers
- source maps
**source map example**
```js
var brackets = require('expand-brackets');
var res = brackets('[:alpha:]');
console.log(res.map);
{ version: 3,
sources: [ 'brackets' ],
names: [],
mappings: 'AAAA,MAAS',
sourcesContent: [ '[:alpha:]' ] }
```
expand-brackets-2.1.4/examples/ 0000775 0000000 0000000 00000000000 13023574430 0016410 5 ustar 00root root 0000000 0000000 expand-brackets-2.1.4/examples/isMatch.js 0000664 0000000 0000000 00000000157 13023574430 0020341 0 ustar 00root root 0000000 0000000 'use strict';
var brackets = require('..');
console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]'));
expand-brackets-2.1.4/examples/makeRe.js 0000664 0000000 0000000 00000000162 13023574430 0020151 0 ustar 00root root 0000000 0000000 'use strict';
var brackets = require('..');
var pattern = '[[:alpha:]]';
console.log(brackets.makeRe(pattern));
expand-brackets-2.1.4/examples/match.js 0000664 0000000 0000000 00000000254 13023574430 0020043 0 ustar 00root root 0000000 0000000 'use strict';
var brackets = require('..');
console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+'));
expand-brackets-2.1.4/examples/posix.js 0000664 0000000 0000000 00000000231 13023574430 0020104 0 ustar 00root root 0000000 0000000 'use strict';
var brackets = require('..');
var pattern = '[[:alpha:]]';
var res = brackets(pattern);
// console.log(res.ast.nodes);
console.log(res);
expand-brackets-2.1.4/examples/source-maps.js 0000664 0000000 0000000 00000000232 13023574430 0021201 0 ustar 00root root 0000000 0000000 'use strict';
var brackets = require('..');
var pattern = 'a/[[:alpha:][:digit:]]/b';
var res = brackets(pattern, {sourcemap: true});
console.log(res);
expand-brackets-2.1.4/index.js 0000664 0000000 0000000 00000012064 13023574430 0016242 0 ustar 00root root 0000000 0000000 'use strict';
/**
* Local dependencies
*/
var compilers = require('./lib/compilers');
var parsers = require('./lib/parsers');
/**
* Module dependencies
*/
var debug = require('debug')('expand-brackets');
var extend = require('extend-shallow');
var Snapdragon = require('snapdragon');
var toRegex = require('to-regex');
/**
* Parses the given POSIX character class `pattern` and returns a
* string that can be used for creating regular expressions for matching.
*
* @param {String} `pattern`
* @param {Object} `options`
* @return {Object}
* @api public
*/
function brackets(pattern, options) {
debug('initializing from <%s>', __filename);
var res = brackets.create(pattern, options);
return res.output;
}
/**
* Takes an array of strings and a POSIX character class pattern, and returns a new
* array with only the strings that matched the pattern.
*
* ```js
* var brackets = require('expand-brackets');
* console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
* //=> ['a']
*
* console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+'));
* //=> ['a', 'ab']
* ```
* @param {Array} `arr` Array of strings to match
* @param {String} `pattern` POSIX character class pattern(s)
* @param {Object} `options`
* @return {Array}
* @api public
*/
brackets.match = function(arr, pattern, options) {
arr = [].concat(arr);
var opts = extend({}, options);
var isMatch = brackets.matcher(pattern, opts);
var len = arr.length;
var idx = -1;
var res = [];
while (++idx < len) {
var ele = arr[idx];
if (isMatch(ele)) {
res.push(ele);
}
}
if (res.length === 0) {
if (opts.failglob === true) {
throw new Error('no matches found for "' + pattern + '"');
}
if (opts.nonull === true || opts.nullglob === true) {
return [pattern.split('\\').join('')];
}
}
return res;
};
/**
* Returns true if the specified `string` matches the given
* brackets `pattern`.
*
* ```js
* var brackets = require('expand-brackets');
*
* console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]'));
* //=> true
* console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]'));
* //=> false
* ```
* @param {String} `string` String to match
* @param {String} `pattern` Poxis pattern
* @param {String} `options`
* @return {Boolean}
* @api public
*/
brackets.isMatch = function(str, pattern, options) {
return brackets.matcher(pattern, options)(str);
};
/**
* Takes a POSIX character class pattern and returns a matcher function. The returned
* function takes the string to match as its only argument.
*
* ```js
* var brackets = require('expand-brackets');
* var isMatch = brackets.matcher('[[:lower:]].[[:upper:]]');
*
* console.log(isMatch('a.a'));
* //=> false
* console.log(isMatch('a.A'));
* //=> true
* ```
* @param {String} `pattern` Poxis pattern
* @param {String} `options`
* @return {Boolean}
* @api public
*/
brackets.matcher = function(pattern, options) {
var re = brackets.makeRe(pattern, options);
return function(str) {
return re.test(str);
};
};
/**
* Create a regular expression from the given `pattern`.
*
* ```js
* var brackets = require('expand-brackets');
* var re = brackets.makeRe('[[:alpha:]]');
* console.log(re);
* //=> /^(?:[a-zA-Z])$/
* ```
* @param {String} `pattern` The pattern to convert to regex.
* @param {Object} `options`
* @return {RegExp}
* @api public
*/
brackets.makeRe = function(pattern, options) {
var res = brackets.create(pattern, options);
var opts = extend({strictErrors: false}, options);
return toRegex(res.output, opts);
};
/**
* Parses the given POSIX character class `pattern` and returns an object
* with the compiled `output` and optional source `map`.
*
* ```js
* var brackets = require('expand-brackets');
* console.log(brackets('[[:alpha:]]'));
* // { options: { source: 'string' },
* // input: '[[:alpha:]]',
* // state: {},
* // compilers:
* // { eos: [Function],
* // noop: [Function],
* // bos: [Function],
* // not: [Function],
* // escape: [Function],
* // text: [Function],
* // posix: [Function],
* // bracket: [Function],
* // 'bracket.open': [Function],
* // 'bracket.inner': [Function],
* // 'bracket.literal': [Function],
* // 'bracket.close': [Function] },
* // output: '[a-zA-Z]',
* // ast:
* // { type: 'root',
* // errors: [],
* // nodes: [ [Object], [Object], [Object] ] },
* // parsingErrors: [] }
* ```
* @param {String} `pattern`
* @param {Object} `options`
* @return {Object}
* @api public
*/
brackets.create = function(pattern, options) {
var snapdragon = (options && options.snapdragon) || new Snapdragon(options);
compilers(snapdragon);
parsers(snapdragon);
var ast = snapdragon.parse(pattern, options);
ast.input = pattern;
var res = snapdragon.compile(ast, options);
res.input = pattern;
return res;
};
/**
* Expose `brackets` constructor, parsers and compilers
*/
brackets.compilers = compilers;
brackets.parsers = parsers;
/**
* Expose `brackets`
* @type {Function}
*/
module.exports = brackets;
expand-brackets-2.1.4/lib/ 0000775 0000000 0000000 00000000000 13023574430 0015340 5 ustar 00root root 0000000 0000000 expand-brackets-2.1.4/lib/compilers.js 0000664 0000000 0000000 00000003755 13023574430 0017705 0 ustar 00root root 0000000 0000000 'use strict';
var posix = require('posix-character-classes');
module.exports = function(brackets) {
brackets.compiler
/**
* Escaped characters
*/
.set('escape', function(node) {
return this.emit('\\' + node.val.replace(/^\\/, ''), node);
})
/**
* Text
*/
.set('text', function(node) {
return this.emit(node.val.replace(/([{}])/g, '\\$1'), node);
})
/**
* POSIX character classes
*/
.set('posix', function(node) {
if (node.val === '[::]') {
return this.emit('\\[::\\]', node);
}
var val = posix[node.inner];
if (typeof val === 'undefined') {
val = '[' + node.inner + ']';
}
return this.emit(val, node);
})
/**
* Non-posix brackets
*/
.set('bracket', function(node) {
return this.mapVisit(node.nodes);
})
.set('bracket.open', function(node) {
return this.emit(node.val, node);
})
.set('bracket.inner', function(node) {
var inner = node.val;
if (inner === '[' || inner === ']') {
return this.emit('\\' + node.val, node);
}
if (inner === '^]') {
return this.emit('^\\]', node);
}
if (inner === '^') {
return this.emit('^', node);
}
if (/-/.test(inner) && !/(\d-\d|\w-\w)/.test(inner)) {
inner = inner.split('-').join('\\-');
}
var isNegated = inner.charAt(0) === '^';
// add slashes to negated brackets, per spec
if (isNegated && inner.indexOf('/') === -1) {
inner += '/';
}
if (isNegated && inner.indexOf('.') === -1) {
inner += '.';
}
// don't unescape `0` (octal literal)
inner = inner.replace(/\\([1-9])/g, '$1');
return this.emit(inner, node);
})
.set('bracket.close', function(node) {
var val = node.val.replace(/^\\/, '');
if (node.parent.escaped === true) {
return this.emit('\\' + val, node);
}
return this.emit(val, node);
});
};
expand-brackets-2.1.4/lib/parsers.js 0000664 0000000 0000000 00000010452 13023574430 0017357 0 ustar 00root root 0000000 0000000 'use strict';
var utils = require('./utils');
var define = require('define-property');
/**
* Text regex
*/
var TEXT_REGEX = '(\\[(?=.*\\])|\\])+';
var not = utils.createRegex(TEXT_REGEX);
/**
* Brackets parsers
*/
function parsers(brackets) {
brackets.state = brackets.state || {};
brackets.parser.sets.bracket = brackets.parser.sets.bracket || [];
brackets.parser
.capture('escape', function() {
if (this.isInside('bracket')) return;
var pos = this.position();
var m = this.match(/^\\(.)/);
if (!m) return;
return pos({
type: 'escape',
val: m[0]
});
})
/**
* Text parser
*/
.capture('text', function() {
if (this.isInside('bracket')) return;
var pos = this.position();
var m = this.match(not);
if (!m || !m[0]) return;
return pos({
type: 'text',
val: m[0]
});
})
/**
* POSIX character classes: "[[:alpha:][:digits:]]"
*/
.capture('posix', function() {
var pos = this.position();
var m = this.match(/^\[:(.*?):\](?=.*\])/);
if (!m) return;
var inside = this.isInside('bracket');
if (inside) {
brackets.posix++;
}
return pos({
type: 'posix',
insideBracket: inside,
inner: m[1],
val: m[0]
});
})
/**
* Bracket (noop)
*/
.capture('bracket', function() {})
/**
* Open: '['
*/
.capture('bracket.open', function() {
var parsed = this.parsed;
var pos = this.position();
var m = this.match(/^\[(?=.*\])/);
if (!m) return;
var prev = this.prev();
var last = utils.last(prev.nodes);
if (parsed.slice(-1) === '\\' && !this.isInside('bracket')) {
last.val = last.val.slice(0, last.val.length - 1);
return pos({
type: 'escape',
val: m[0]
});
}
var open = pos({
type: 'bracket.open',
val: m[0]
});
if (last.type === 'bracket.open' || this.isInside('bracket')) {
open.val = '\\' + open.val;
open.type = 'bracket.inner';
open.escaped = true;
return open;
}
var node = pos({
type: 'bracket',
nodes: [open]
});
define(node, 'parent', prev);
define(open, 'parent', node);
this.push('bracket', node);
prev.nodes.push(node);
})
/**
* Bracket text
*/
.capture('bracket.inner', function() {
if (!this.isInside('bracket')) return;
var pos = this.position();
var m = this.match(not);
if (!m || !m[0]) return;
var next = this.input.charAt(0);
var val = m[0];
var node = pos({
type: 'bracket.inner',
val: val
});
if (val === '\\\\') {
return node;
}
var first = val.charAt(0);
var last = val.slice(-1);
if (first === '!') {
val = '^' + val.slice(1);
}
if (last === '\\' || (val === '^' && next === ']')) {
val += this.input[0];
this.consume(1);
}
node.val = val;
return node;
})
/**
* Close: ']'
*/
.capture('bracket.close', function() {
var parsed = this.parsed;
var pos = this.position();
var m = this.match(/^\]/);
if (!m) return;
var prev = this.prev();
var last = utils.last(prev.nodes);
if (parsed.slice(-1) === '\\' && !this.isInside('bracket')) {
last.val = last.val.slice(0, last.val.length - 1);
return pos({
type: 'escape',
val: m[0]
});
}
var node = pos({
type: 'bracket.close',
rest: this.input,
val: m[0]
});
if (last.type === 'bracket.open') {
node.type = 'bracket.inner';
node.escaped = true;
return node;
}
var bracket = this.pop('bracket');
if (!this.isType(bracket, 'bracket')) {
if (this.options.strict) {
throw new Error('missing opening "["');
}
node.type = 'bracket.inner';
node.escaped = true;
return node;
}
bracket.nodes.push(node);
define(node, 'parent', bracket);
});
}
/**
* Brackets parsers
*/
module.exports = parsers;
/**
* Expose text regex
*/
module.exports.TEXT_REGEX = TEXT_REGEX;
expand-brackets-2.1.4/lib/utils.js 0000664 0000000 0000000 00000001230 13023574430 0017032 0 ustar 00root root 0000000 0000000 'use strict';
var toRegex = require('to-regex');
var regexNot = require('regex-not');
var cached;
/**
* Get the last element from `array`
* @param {Array} `array`
* @return {*}
*/
exports.last = function(arr) {
return arr[arr.length - 1];
};
/**
* Create and cache regex to use for text nodes
*/
exports.createRegex = function(pattern, include) {
if (cached) return cached;
var opts = {contains: true, strictClose: false};
var not = regexNot.create(pattern, opts);
var re;
if (typeof include === 'string') {
re = toRegex('^(?:' + include + '|' + not + ')', opts);
} else {
re = toRegex(not, opts);
}
return (cached = re);
};
expand-brackets-2.1.4/package.json 0000664 0000000 0000000 00000003557 13023574430 0017072 0 ustar 00root root 0000000 0000000 {
"name": "expand-brackets",
"description": "Expand POSIX bracket expressions (character classes) in glob patterns.",
"version": "2.1.4",
"homepage": "https://github.com/jonschlinkert/expand-brackets",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Elan Shanker (https://github.com/es128)",
"Eugene Sharygin (https://github.com/eush77)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Martin Kolárik (http://kolarik.sk)"
],
"repository": "jonschlinkert/expand-brackets",
"bugs": {
"url": "https://github.com/jonschlinkert/expand-brackets/issues"
},
"license": "MIT",
"files": [
"index.js",
"lib"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"debug": "^2.3.3",
"define-property": "^0.2.5",
"extend-shallow": "^2.0.1",
"posix-character-classes": "^0.1.0",
"regex-not": "^1.0.0",
"snapdragon": "^0.8.1",
"to-regex": "^3.0.1"
},
"devDependencies": {
"bash-match": "^0.1.1",
"gulp-format-md": "^0.1.10",
"helper-changelog": "^0.3.0",
"minimatch": "^3.0.3",
"mocha": "^3.0.2",
"multimatch": "^2.1.0",
"yargs-parser": "^4.0.0"
},
"keywords": [
"bracket",
"brackets",
"character class",
"expand",
"expression",
"posix"
],
"verb": {
"run": true,
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"helpers": [
"helper-changelog"
],
"related": {
"list": [
"braces",
"extglob",
"micromatch",
"nanomatch"
]
},
"reflinks": [
"micromatch",
"verb",
"verb-generate-readme"
],
"lint": {
"reflinks": true
}
}
}
expand-brackets-2.1.4/test/ 0000775 0000000 0000000 00000000000 13023574430 0015551 5 ustar 00root root 0000000 0000000 expand-brackets-2.1.4/test/support/ 0000775 0000000 0000000 00000000000 13023574430 0017265 5 ustar 00root root 0000000 0000000 expand-brackets-2.1.4/test/support/compare.js 0000664 0000000 0000000 00000000170 13023574430 0021247 0 ustar 00root root 0000000 0000000 module.exports = function(a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
};
expand-brackets-2.1.4/test/support/match.js 0000664 0000000 0000000 00000002407 13023574430 0020722 0 ustar 00root root 0000000 0000000 'use strict';
var assert = require('assert');
var matcher = require('./matcher');
var compare = require('./compare');
var utils = require('./utils');
module.exports = function(fixtures, pattern, expected, options, msg) {
if (!Array.isArray(expected)) {
var tmp = expected;
expected = options;
options = tmp;
}
if (typeof options === 'string') {
msg = options;
options = {};
}
msg = msg ? (pattern + ' ' + msg) : pattern;
var actual = matcher.match(utils.arrayify(fixtures), pattern, options);
expected.sort(compare);
actual.sort(compare);
assert.deepEqual(actual, expected, msg);
};
module.exports.match = function(fixtures, pattern, expected, options, msg) {
if (!Array.isArray(expected)) {
var tmp = expected;
expected = options;
options = tmp;
}
if (typeof options === 'string') {
msg = options;
options = {};
}
msg = msg ? (pattern + ' ' + msg) : pattern;
var actual = matcher.match(utils.arrayify(fixtures), pattern, options);
expected.sort(compare);
actual.sort(compare);
assert.deepEqual(actual, expected, msg);
};
module.exports.isMatch = function() {
return matcher.isMatch.apply(null, arguments);
};
module.exports.makeRe = function() {
return matcher.makeRe.apply(null, arguments);
};
expand-brackets-2.1.4/test/support/matcher.js 0000664 0000000 0000000 00000003152 13023574430 0021247 0 ustar 00root root 0000000 0000000 'use strict';
var argv = require('yargs-parser')(process.argv.slice(2));
var minimatch = require('minimatch');
var mm = require('multimatch');
var bash = require('bash-match');
var utils = require('../../lib/utils');
var brackets = require('../..');
// use multimatch for the array/array scenario
function mi() {
return mm.apply(null, arguments);
}
// label for debugging
mm.multimatch = true;
mi.minimatch = true;
brackets.brackets = true;
bash.bash = true;
/**
* Decorate methods onto bash for parity with nanomatch
*/
bash.makeRe = function() {};
/**
* Decorate methods onto multimatch for parity with nanomatch
*/
mm.isMatch = function(files, patterns, options) {
return mm(utils.arrayify(files), patterns, options).length > 0;
};
mm.match = function(files, patterns, options) {
return mm(utils.arrayify(files), patterns, options);
};
mm.makeRe = function(pattern, options) {
return mi.makeRe(pattern, options);
};
/**
* Decorate methods onto minimatch for parity with nanomatch
*/
mi.isMatch = function(file, pattern, options) {
return minimatch(file, pattern, options);
};
mi.match = function(files, pattern, options) {
return minimatch.match(utils.arrayify(files), pattern, options);
};
mi.makeRe = function(pattern, options) {
return minimatch.makeRe(pattern, options);
};
/**
* Detect matcher based on argv, with nanomatch as default
*/
var matcher = argv.mm ? mm : (argv.mi ? mi : brackets);
if (argv.bash) {
matcher = bash;
}
/**
* Expose matcher
*/
module.exports = matcher;
module.exports.bash = bash;
module.exports.brackets = brackets;
module.exports.mm = mm;
module.exports.mi = mi;
expand-brackets-2.1.4/test/support/utils.js 0000664 0000000 0000000 00000000373 13023574430 0020766 0 ustar 00root root 0000000 0000000 'use strict';
/**
* Utils
*/
exports.arrayify = function(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
};
exports.alphaSort = function(a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
};
expand-brackets-2.1.4/test/test.js 0000664 0000000 0000000 00000027523 13023574430 0017077 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
var assert = require('assert');
var match = require('./support/match');
var brackets = require('..');
describe('brackets', function() {
describe('main export', function() {
it('should create the equivalent regex character classes for POSIX expressions:', function() {
assert.equal(brackets('foo[[:lower:]]bar'), 'foo[a-z]bar');
assert.equal(brackets('foo[[:lower:][:upper:]]bar'), 'foo[a-zA-Z]bar');
assert.equal(brackets('[[:alpha:]123]'), '[a-zA-Z123]');
assert.equal(brackets('[[:lower:]]'), '[a-z]');
assert.equal(brackets('[![:lower:]]'), '[^a-z]');
assert.equal(brackets('[[:digit:][:upper:][:space:]]'), '[0-9A-Z \\t\\r\\n\\v\\f]');
assert.equal(brackets('[[:xdigit:]]'), '[A-Fa-f0-9]');
assert.equal(brackets('[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'), '[a-zA-Z0-9a-zA-Z \\t\\x00-\\x1F\\x7F0-9\\x21-\\x7Ea-z\\x20-\\x7E \\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~ \\t\\r\\n\\v\\fA-ZA-Fa-f0-9]');
assert.equal(brackets('[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'), '[^a-zA-Z0-9a-zA-Z \\t\\x00-\\x1F\\x7F0-9a-z \\t\\r\\n\\v\\fA-ZA-Fa-f0-9]');
assert.equal(brackets('[a-c[:digit:]x-z]'), '[a-c0-9x-z]');
assert.equal(brackets('[_[:alpha:]][_[:alnum:]][_[:alnum:]]*'), '[_a-zA-Z][_a-zA-Z0-9][_a-zA-Z0-9]*', []);
});
});
describe('.match', function() {
it('should support POSIX.2 character classes', function() {
match(['e'], '[[:xdigit:]]', [ 'e' ]);
match(['a', '1', '5', 'A'], '[[:alpha:]123]', [ '1', 'a', 'A' ]);
match(['9', 'A', 'b'], '[![:alpha:]]', ['9']);
match(['9', 'A', 'b'], '[^[:alpha:]]', ['9']);
match(['9', 'a', 'B'], '[[:digit:]]', ['9']);
match(['a', 'b', 'A'], '[:alpha:]', ['a'], 'not a valid posix bracket, but valid char class');
match(['a', 'b', 'A'], '[[:alpha:]]', [ 'a', 'A', 'b' ]);
match(['a', 'aa', 'aB', 'a7'], '[[:lower:][:lower:]]', ['a']);
match(['a', '7', 'aa', 'aB', 'a7'], '[[:lower:][:digit:]]', [ '7', 'a' ]);
});
it('should match word characters', function() {
var fixtures = ['a c', 'a1c', 'a123c', 'a.c', 'a.xy.zc', 'a.zc', 'abbbbc', 'abbbc', 'abbc', 'abc', 'abq', 'axy zc', 'axy', 'axy.zc', 'axyzc'];
match(fixtures, 'a[a-z]+c', ['abbbbc', 'abbbc', 'abbc', 'abc', 'axyzc']);
});
it('should match literal brackets when escaped', function() {
match(['a [b]', 'a b'], 'a [b]', ['a b']);
match(['a [b]', 'a b'], 'a \\[b\\]', ['a [b]']);
match(['a [b]', 'a b'], 'a ([b])', ['a b']);
match(['a [b]', 'a b'], 'a (\\[b\\]|[b])', ['a [b]', 'a b']);
match(['a [b] c', 'a b c'], 'a [b] c', ['a b c']);
});
it('should match character classes', function() {
match(['abc', 'abd'], 'a[bc]d', ['abd']);
});
it('should match character class alphabetical ranges', function() {
match(['abc', 'abd', 'ace', 'ac', 'a-'], 'a[b-d]e', ['ace']);
match(['abc', 'abd', 'ace', 'ac', 'a-'], 'a[b-d]', ['ac']);
});
it('should match character classes with leading dashes', function() {
match(['abc', 'abd', 'ace', 'ac', 'a-'], 'a[-c]', ['a-', 'ac']);
});
it('should match character classes with trailing dashes', function() {
match(['abc', 'abd', 'ace', 'ac', 'a-'], 'a[c-]', ['a-', 'ac']);
});
it('should match bracket literals', function() {
match(['a]c', 'abd', 'ace', 'ac', 'a-'], 'a[]]c', ['a]c']);
});
it('should match bracket literals', function() {
match(['a]', 'abd', 'ace', 'ac', 'a-'], 'a]', ['a]']);
});
it('should negation patterns', function() {
match(['a]', 'acd', 'aed', 'ac', 'a-'], 'a[^bc]d', ['aed']);
});
it('should match negated dashes', function() {
match(['adc', 'a-c'], 'a[^-b]c', ['adc']);
});
it('should match negated brackets', function() {
match(['adc', 'a]c'], 'a[^]b]c', ['adc']);
});
it('should match alpha-numeric characters', function() {
match(['01234', '0123e456', '0123e45g78'], '[\\de]+', ['01234', '0123e456']);
match(['01234', '0123e456', '0123e45g78'], '[\\de]*', ['01234', '0123e456']);
match(['01234', '0123e456', '0123e45g78'], '[e\\d]+', ['01234', '0123e456']);
});
it('should not create an invalid posix character class:', function() {
assert.equal(brackets('[:al:]'), '[:al:]');
assert.equal(brackets('[abc[:punct:][0-9]'), '[abc\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~\\[0-9]');
});
it('should return `true` when the pattern matches:', function() {
assert(match.isMatch('a', '[[:lower:]]'));
assert(match.isMatch('A', '[[:upper:]]'));
assert(match.isMatch('A', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch('1', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch(' ', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch('5', '[[:xdigit:]]'));
assert(match.isMatch('f', '[[:xdigit:]]'));
assert(match.isMatch('D', '[[:xdigit:]]'));
assert(match.isMatch('_', '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('_', '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('.', '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('5', '[a-c[:digit:]x-z]'));
assert(match.isMatch('b', '[a-c[:digit:]x-z]'));
assert(match.isMatch('y', '[a-c[:digit:]x-z]'));
});
it('should return `false` when the pattern does not match:', function() {
assert(!match.isMatch('A', '[[:lower:]]'));
assert(match.isMatch('A', '[![:lower:]]'));
assert(!match.isMatch('a', '[[:upper:]]'));
assert(!match.isMatch('a', '[[:digit:][:upper:][:space:]]'));
assert(!match.isMatch('.', '[[:digit:][:upper:][:space:]]'));
assert(!match.isMatch('.', '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'));
assert(!match.isMatch('q', '[a-c[:digit:]x-z]'));
});
});
describe('.makeRe()', function() {
it('should make a regular expression for the given pattern:', function() {
assert.deepEqual(brackets.makeRe('[[:alpha:]123]'), /^(?:[a-zA-Z123])$/);
assert.deepEqual(brackets.makeRe('[![:lower:]]'), /^(?:[^a-z])$/);
});
});
describe('.match()', function() {
it('should return an array of matching strings:', function() {
match(['a1B', 'a1b'], '[[:alpha:]][[:digit:]][[:upper:]]', ['a1B']);
match(['.', 'a', '!'], '[[:digit:][:punct:][:space:]]', ['.', '!']);
});
});
describe('POSIX: From the test suite for the POSIX.2 (BRE) pattern matching code:', function() {
it('First, test POSIX.2 character classes', function() {
assert(match.isMatch('e', '[[:xdigit:]]'));
assert(match.isMatch('1', '[[:xdigit:]]'));
assert(match.isMatch('a', '[[:alpha:]123]'));
assert(match.isMatch('1', '[[:alpha:]123]'));
});
it('should match using POSIX.2 negation patterns', function() {
assert(match.isMatch('9', '[![:alpha:]]'));
assert(match.isMatch('9', '[^[:alpha:]]'));
});
it('should match word characters', function() {
assert(match.isMatch('A', '[[:word:]]'));
assert(match.isMatch('B', '[[:word:]]'));
assert(match.isMatch('a', '[[:word:]]'));
assert(match.isMatch('b', '[[:word:]]'));
});
it('should match digits with word class', function() {
assert(match.isMatch('1', '[[:word:]]'));
assert(match.isMatch('2', '[[:word:]]'));
});
it('should not digits', function() {
assert(match.isMatch('1', '[[:digit:]]'));
assert(match.isMatch('2', '[[:digit:]]'));
});
it('should not match word characters with digit class', function() {
assert(!match.isMatch('a', '[[:digit:]]'));
assert(!match.isMatch('A', '[[:digit:]]'));
});
it('should match uppercase alpha characters', function() {
assert(match.isMatch('A', '[[:upper:]]'));
assert(match.isMatch('B', '[[:upper:]]'));
});
it('should not match lowercase alpha characters', function() {
assert(!match.isMatch('a', '[[:upper:]]'));
assert(!match.isMatch('b', '[[:upper:]]'));
});
it('should not match digits with upper class', function() {
assert(!match.isMatch('1', '[[:upper:]]'));
assert(!match.isMatch('2', '[[:upper:]]'));
});
it('should match lowercase alpha characters', function() {
assert(match.isMatch('a', '[[:lower:]]'));
assert(match.isMatch('b', '[[:lower:]]'));
});
it('should not match uppercase alpha characters', function() {
assert(!match.isMatch('A', '[[:lower:]]'));
assert(!match.isMatch('B', '[[:lower:]]'));
});
it('should match one lower and one upper character', function() {
assert(match.isMatch('aA', '[[:lower:]][[:upper:]]'));
assert(!match.isMatch('AA', '[[:lower:]][[:upper:]]'));
assert(!match.isMatch('Aa', '[[:lower:]][[:upper:]]'));
});
it('should match hexidecimal digits', function() {
assert(match.isMatch('ababab', '[[:xdigit:]]*'));
assert(match.isMatch('020202', '[[:xdigit:]]*'));
assert(match.isMatch('900', '[[:xdigit:]]*'));
});
it('should match punctuation characters (\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~)', function() {
assert(match.isMatch('!', '[[:punct:]]'));
assert(match.isMatch('?', '[[:punct:]]'));
assert(match.isMatch('#', '[[:punct:]]'));
assert(match.isMatch('&', '[[:punct:]]'));
assert(match.isMatch('@', '[[:punct:]]'));
assert(match.isMatch('+', '[[:punct:]]'));
assert(match.isMatch('*', '[[:punct:]]'));
assert(match.isMatch(':', '[[:punct:]]'));
assert(match.isMatch('=', '[[:punct:]]'));
assert(match.isMatch('|', '[[:punct:]]'));
assert(match.isMatch('|++', '[[:punct:]]*'));
});
it('should only match one character', function() {
assert(!match.isMatch('?*+', '[[:punct:]]'));
});
it('should only match zero or more characters', function() {
assert(match.isMatch('?*+', '[[:punct:]]*'));
assert(match.isMatch('', '[[:punct:]]*'));
});
it('invalid character class expressions are just characters to be matched', function() {
match(['a'], '[:al:]', ['a']);
match(['a'], '[[:al:]', ['a']);
match(['!'], '[abc[:punct:][0-9]', ['!']);
});
it('should match the start of a valid sh identifier', function() {
assert(match.isMatch('PATH', '[_[:alpha:]]*'));
});
it('should match the first two characters of a valid sh identifier', function() {
assert(match.isMatch('PATH', '[_[:alpha:]][_[:alnum:]]*'));
});
/**
* Some of these tests (and their descriptions) were ported directly
* from the Bash 4.3 unit tests.
*/
it('how about A?', function() {
match(['9'], '[[:digit:]]', ['9']);
match(['X'], '[[:digit:]]', []);
match(['aB'], '[[:lower:]][[:upper:]]', ['aB']);
match(['a', '3', 'aa', 'a3', 'abc'], '[[:alpha:][:digit:]]', ['3', 'a']);
match(['a', 'b'], '[[:alpha:]\\]', [], []);
});
it('OK, what\'s a tab? is it a blank? a space?', function() {
assert(match.isMatch('\t', '[[:blank:]]'));
assert(match.isMatch('\t', '[[:space:]]'));
assert(match.isMatch(' ', '[[:space:]]'));
});
it('let\'s check out characters in the ASCII range', function() {
assert(!match.isMatch('\\377', '[[:ascii:]]'));
assert(!match.isMatch('9', '[1[:alpha:]123]'));
});
it('punctuation', function() {
assert(!match.isMatch(' ', '[[:punct:]]'));
});
it('graph', function() {
assert(match.isMatch('A', '[[:graph:]]'));
assert(!match.isMatch('\b', '[[:graph:]]'));
assert(!match.isMatch('\n', '[[:graph:]]'));
assert(match.isMatch('\s', '[[:graph:]]'));
});
});
});
expand-brackets-2.1.4/test/wildmatch.js 0000664 0000000 0000000 00000017045 13023574430 0020072 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
var assert = require('assert');
var match = require('./support/match');
describe('original wildmatch', function() {
it('should support basic wildmatch (brackets) features', function() {
assert(!match.isMatch('aab', 'a[]-]b'));
assert(!match.isMatch('ten', '[ten]'));
assert(!match.isMatch('ten', 't[!a-g]n'));
assert(match.isMatch(']', ']'));
assert(match.isMatch('a-b', 'a[]-]b'));
assert(match.isMatch('a]b', 'a[]-]b'));
assert(match.isMatch('a]b', 'a[]]b'));
assert(match.isMatch('aab', 'a[]a-]b'));
assert(match.isMatch('ten', 't[a-g]n'));
assert(match.isMatch('ton', 't[!a-g]n'));
assert(match.isMatch('ton', 't[^a-g]n'));
});
it('should support Extended slash-matching features', function() {
assert(!match.isMatch('foo/bar', 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'));
assert(match.isMatch('foo/bar', 'foo[/]bar'));
assert(match.isMatch('foo-bar', 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'));
});
it('should match braces', function() {
assert(match.isMatch('foo{}baz', 'foo[{a,b}]+baz'));
});
it('should match parens', function() {
assert(match.isMatch('foo(bar)baz', 'foo[bar()]+baz'));
});
it('should match escaped characters', function() {
assert(!match.isMatch('', '\\'));
assert(!match.isMatch('XXX/\\', '[A-Z]+/\\'));
assert(match.isMatch('\\', '\\'));
assert(match.isMatch('XXX/\\', '[A-Z]+/\\\\'));
assert(match.isMatch('[ab]', '\\[ab]'));
assert(match.isMatch('[ab]', '[\\[:]ab]'));
});
it('should match brackets', function() {
assert(!match.isMatch(']', '[!]-]'));
assert(match.isMatch('a', '[!]-]'));
assert(match.isMatch('[ab]', '[[]ab]'));
});
it('should not choke on malformed posix brackets', function() {
assert(!match.isMatch('[ab]', '[[::]ab]'));
assert(match.isMatch('[ab]', '[[:]ab]'));
assert(match.isMatch('[ab]', '[[:digit]ab]'));
});
it('should not choke on non-bracket characters', function() {
assert(!match.isMatch('foo', '@foo'));
assert(match.isMatch('({foo})', '\\({foo}\\)'));
assert(match.isMatch('@foo', '@foo'));
assert(match.isMatch('{foo}', '{foo}'));
});
it('should support Character class tests', function() {
assert(!match.isMatch('.', '[[:digit:][:upper:][:space:]]'));
assert(!match.isMatch('1', '[[:digit:][:upper:][:spaci:]]'));
assert(!match.isMatch('a', '[[:digit:][:upper:][:space:]]'));
assert(!match.isMatch('q', '[a-c[:digit:]x-z]'));
assert(match.isMatch(' ', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch('.', '[[:digit:][:punct:][:space:]]'));
assert(match.isMatch('.', '[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('1', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch('5', '[[:xdigit:]]'));
assert(match.isMatch('5', '[a-c[:digit:]x-z]'));
assert(match.isMatch('_', '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('_', '[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'));
assert(match.isMatch('A', '[[:digit:][:upper:][:space:]]'));
assert(match.isMatch('a1B', '[[:alpha:]][[:digit:]][[:upper:]]'));
assert(match.isMatch('b', '[a-c[:digit:]x-z]'));
assert(match.isMatch('D', '[[:xdigit:]]'));
assert(match.isMatch('f', '[[:xdigit:]]'));
assert(match.isMatch('y', '[a-c[:digit:]x-z]'));
});
it('should support Additional tests, including some malformed wildmats', function() {
assert(!match.isMatch('$', '[ --]'));
assert(!match.isMatch('+', '[,-.]'));
assert(!match.isMatch('-', '[!a-'));
assert(!match.isMatch('-', '[\\-_]'));
assert(!match.isMatch('-', '[a-'));
assert(!match.isMatch('-.]', '[,-.]'));
assert(!match.isMatch('0', '[ --]'));
assert(!match.isMatch('2', '[\\1-\\3]'));
assert(!match.isMatch('4', '[\\1-\\3]'));
assert(!match.isMatch('5', '[--A]'));
assert(!match.isMatch('[', '[\\\\-^]'));
assert(!match.isMatch('[', '[]-a]'));
assert(!match.isMatch('\\', '[!\\\\]'));
assert(!match.isMatch('\\', '[[-\\]]'));
assert(!match.isMatch('\\', '[\\]'));
assert(!match.isMatch('\\', '[\\]]'));
assert(!match.isMatch('\\]', '[\\]]'));
assert(!match.isMatch(']', '[\\\\-^]'));
assert(!match.isMatch('^', '[]-a]'));
assert(!match.isMatch('a[]b', 'a[]b'));
assert(!match.isMatch('ab', '[!'));
assert(!match.isMatch('ab', '[-'));
assert(!match.isMatch('ab', 'a[]b'));
assert(!match.isMatch('acrt', 'a[c-c]st'));
assert(!match.isMatch('G', '[A-\\\\]'));
assert(!match.isMatch('j', '[a-e-n]'));
assert(match.isMatch(' ', '[ --]'));
assert(match.isMatch(' ', '[-- ]'));
assert(match.isMatch(',', '[,]'));
assert(match.isMatch(',', '[\\\\,]'));
assert(match.isMatch('-', '[ --]'));
assert(match.isMatch('-', '[,-.]'));
assert(match.isMatch('-', '[------]'));
assert(match.isMatch('-', '[---]'));
assert(match.isMatch('-', '[--A]'));
assert(match.isMatch('-', '[-]'));
assert(match.isMatch('-', '[[-\\]]'));
assert(match.isMatch('-', '[a-e-n]'));
assert(match.isMatch('-b]', '[a-]b]'));
assert(match.isMatch('3', '[\\1-\\3]'));
assert(match.isMatch('[', '[!]-a]'));
assert(match.isMatch('[', '[[-\\]]'));
assert(match.isMatch('\\', '[\\\\,]'));
assert(match.isMatch('\\', '[\\\\]'));
assert(match.isMatch(']', '[[-\\]]'));
assert(match.isMatch(']', '[\\]]'));
assert(match.isMatch('^', '[!]-a]'));
assert(match.isMatch('^', '[a^bc]'));
assert(match.isMatch('a', '[!------]'));
assert(match.isMatch('ab[', 'ab['));
assert(match.isMatch('acrt', 'a[c-c]rt'));
});
it('should support Case-sensitivy features', function() {
assert(!match.isMatch('A', '[[:lower:]]'));
assert(!match.isMatch('a', '[[:upper:]]'));
assert(!match.isMatch('a', '[A-Z]'));
assert(!match.isMatch('A', '[a-z]'));
assert(!match.isMatch('A', '[B-a]'));
assert(!match.isMatch('A', '[B-Za]'));
assert(!match.isMatch('z', '[Z-y]'));
assert(match.isMatch('a', '[[:lower:]]'));
assert(match.isMatch('A', '[[:upper:]]'));
assert(match.isMatch('A', '[A-Z]'));
assert(match.isMatch('a', '[a-z]'));
assert(match.isMatch('a', '[B-a]'));
assert(match.isMatch('a', '[B-Za]'));
assert(match.isMatch('Z', '[Z-y]'));
assert(match.isMatch('a', '[A-Z]', {nocase: true}));
assert(match.isMatch('A', '[A-Z]', {nocase: true}));
assert(match.isMatch('A', '[a-z]', {nocase: true}));
assert(match.isMatch('a', '[a-z]', {nocase: true}));
assert(match.isMatch('a', '[[:upper:]]', {nocase: true}));
assert(match.isMatch('A', '[[:upper:]]', {nocase: true}));
assert(match.isMatch('A', '[[:lower:]]', {nocase: true}));
assert(match.isMatch('a', '[[:lower:]]', {nocase: true}));
assert(match.isMatch('A', '[B-Za]', {nocase: true}));
assert(match.isMatch('a', '[B-Za]', {nocase: true}));
assert(match.isMatch('A', '[B-a]', {nocase: true}));
assert(match.isMatch('a', '[B-a]', {nocase: true}));
assert(match.isMatch('z', '[Z-y]', {nocase: true}));
assert(match.isMatch('Z', '[Z-y]', {nocase: true}));
});
it('should support Additional tests not found in the original wildmatch', function() {
assert(match.isMatch('-', '[]-z]'));
assert(match.isMatch('-', '[[:space:]-\\]]'));
assert(match.isMatch(']', '[[:space:]-\\]]'));
assert(!match.isMatch('[', '[[:space:]-\\]]'));
assert(!match.isMatch('c', '[[:space:]-z]'));
assert(!match.isMatch('c', '[]-z]'));
});
});