[Pkg-javascript-commits] [node-expand-brackets] 01/05: Import Upstream version 2.1.3
Sruthi Chandran
srud-guest at moszumanska.debian.org
Thu Nov 3 14:49:58 UTC 2016
This is an automated email from the git hooks/post-receive script.
srud-guest pushed a commit to branch master
in repository node-expand-brackets.
commit eed8221e4c1a55e08690e9a315d40d820e8e7256
Author: Sruthi <srud at disroot.org>
Date: Thu Nov 3 13:01:09 2016 +0530
Import Upstream version 2.1.3
---
.editorconfig | 13 +++
.eslintrc.json | 122 +++++++++++++++++++
.gitattributes | 1 +
.gitignore | 21 ++++
.travis.yml | 11 ++
.verb.md | 71 ++++++++++++
LICENSE | 21 ++++
README.md | 302 ++++++++++++++++++++++++++++++++++++++++++++++++
appveyor.yml | 26 +++++
changelog.md | 35 ++++++
examples/isMatch.js | 5 +
examples/makeRe.js | 6 +
examples/match.js | 7 ++
examples/posix.js | 8 ++
examples/source-maps.js | 7 ++
index.js | 211 +++++++++++++++++++++++++++++++++
lib/compilers.js | 83 +++++++++++++
lib/parsers.js | 219 +++++++++++++++++++++++++++++++++++
lib/utils.js | 34 ++++++
package.json | 85 ++++++++++++++
test/support/compare.js | 5 +
test/support/match.js | 54 +++++++++
test/support/matcher.js | 76 ++++++++++++
test/support/utils.js | 15 +++
test/test.js | 286 +++++++++++++++++++++++++++++++++++++++++++++
test/wildmatch.js | 176 ++++++++++++++++++++++++++++
26 files changed, 1900 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..818e072
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+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
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..948dbdb
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,122 @@
+{
+ "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"]
+ }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..a52bd18
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.* text eol=lf
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7988154
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+# 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
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..98b1311
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,11 @@
+sudo: false
+language: node_js
+os:
+ - linux
+ - osx
+node_js:
+ - node
+ - '6'
+ - '5'
+ - '0.12'
+ - '0.10'
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..cad54d0
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,71 @@
+## 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") %}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6525171
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4e174b4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,302 @@
+# expand-brackets [![NPM version](https://img.shields.io/npm/v/expand-brackets.svg?style=flat)](https://www.npmjs.com/package/expand-brackets) [![NPM monthly downloads](https://img.shields.io/npm/dm/expand-brackets.svg?style=flat)](https://npmjs.org/package/expand-brackets) [![NPM total downloads](https://img.shields.io/npm/dt/expand-brackets.svg?style=flat)](https://npmjs.org/package/expand-brackets) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/expand-brackets.svg [...]
+
+> 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): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces) | [homepage](https://github.com/jonschlinkert/braces "Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces specification.")
+* [extglob](https://www.npmjs.com/package/extglob): Convert extended globs to regex-compatible strings. Add (almost) the expressive power of regular expressions to… [more](https://github.com/jonschlinkert/extglob) | [homepage](https://github.com/jonschlinkert/extglob "Convert extended globs to regex-compatible strings. Add (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**<br/> |
+| --- | --- |
+| 63 | [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 October 21, 2016._
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..ce44317
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,26 @@
+# 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
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 0000000..0c0723a
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,35 @@
+## 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:]' ] }
+```
diff --git a/examples/isMatch.js b/examples/isMatch.js
new file mode 100644
index 0000000..978ccc1
--- /dev/null
+++ b/examples/isMatch.js
@@ -0,0 +1,5 @@
+'use strict';
+
+var brackets = require('..');
+
+console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]'));
diff --git a/examples/makeRe.js b/examples/makeRe.js
new file mode 100644
index 0000000..fe565c3
--- /dev/null
+++ b/examples/makeRe.js
@@ -0,0 +1,6 @@
+'use strict';
+
+var brackets = require('..');
+var pattern = '[[:alpha:]]';
+
+console.log(brackets.makeRe(pattern));
diff --git a/examples/match.js b/examples/match.js
new file mode 100644
index 0000000..413bb4a
--- /dev/null
+++ b/examples/match.js
@@ -0,0 +1,7 @@
+'use strict';
+
+var brackets = require('..');
+
+console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
+
+console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+'));
diff --git a/examples/posix.js b/examples/posix.js
new file mode 100644
index 0000000..7c9c48f
--- /dev/null
+++ b/examples/posix.js
@@ -0,0 +1,8 @@
+'use strict';
+
+var brackets = require('..');
+var pattern = '[[:alpha:]]';
+
+var res = brackets(pattern);
+// console.log(res.ast.nodes);
+console.log(res);
diff --git a/examples/source-maps.js b/examples/source-maps.js
new file mode 100644
index 0000000..0ef8b2d
--- /dev/null
+++ b/examples/source-maps.js
@@ -0,0 +1,7 @@
+'use strict';
+
+var brackets = require('..');
+var pattern = 'a/[[:alpha:][:digit:]]/b';
+
+var res = brackets(pattern, {sourcemap: true});
+console.log(res);
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..74b8b15
--- /dev/null
+++ b/index.js
@@ -0,0 +1,211 @@
+'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;
diff --git a/lib/compilers.js b/lib/compilers.js
new file mode 100644
index 0000000..7bb8d93
--- /dev/null
+++ b/lib/compilers.js
@@ -0,0 +1,83 @@
+'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);
+ }
+
+ 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);
+ });
+};
diff --git a/lib/parsers.js b/lib/parsers.js
new file mode 100644
index 0000000..450a512
--- /dev/null
+++ b/lib/parsers.js
@@ -0,0 +1,219 @@
+'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;
diff --git a/lib/utils.js b/lib/utils.js
new file mode 100644
index 0000000..599ff51
--- /dev/null
+++ b/lib/utils.js
@@ -0,0 +1,34 @@
+'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);
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..83a4484
--- /dev/null
+++ b/package.json
@@ -0,0 +1,85 @@
+{
+ "name": "expand-brackets",
+ "description": "Expand POSIX bracket expressions (character classes) in glob patterns.",
+ "version": "2.1.3",
+ "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 <jon.schlinkert at sellside.com> (http://twitter.com/jonschlinkert)",
+ "Martin Kolárik <martin at kolarik.sk> (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.2.0",
+ "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
+ }
+ }
+}
diff --git a/test/support/compare.js b/test/support/compare.js
new file mode 100644
index 0000000..8a4aef0
--- /dev/null
+++ b/test/support/compare.js
@@ -0,0 +1,5 @@
+module.exports = function(a, b) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ return a > b ? 1 : a < b ? -1 : 0;
+};
diff --git a/test/support/match.js b/test/support/match.js
new file mode 100644
index 0000000..02f17ba
--- /dev/null
+++ b/test/support/match.js
@@ -0,0 +1,54 @@
+'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);
+};
diff --git a/test/support/matcher.js b/test/support/matcher.js
new file mode 100644
index 0000000..4eeb521
--- /dev/null
+++ b/test/support/matcher.js
@@ -0,0 +1,76 @@
+'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;
diff --git a/test/support/utils.js b/test/support/utils.js
new file mode 100644
index 0000000..c57e0f1
--- /dev/null
+++ b/test/support/utils.js
@@ -0,0 +1,15 @@
+'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;
+};
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..3f2dd1e
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,286 @@
+'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:]]'));
+ });
+ });
+});
+
diff --git a/test/wildmatch.js b/test/wildmatch.js
new file mode 100644
index 0000000..1def356
--- /dev/null
+++ b/test/wildmatch.js
@@ -0,0 +1,176 @@
+'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('-', '[!a-'));
+ assert(!match.isMatch('-', '[[-\\]]'));
+ assert(!match.isMatch('-', '[a-'));
+ assert(!match.isMatch('-.]', '[,-.]'));
+ assert(!match.isMatch('0', '[ --]'));
+ assert(!match.isMatch('4', '[\\1-\\3]'));
+ assert(!match.isMatch('[', '[\\\\-^]'));
+ assert(!match.isMatch('[', '[]-a]'));
+ 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('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('2', '[\\1-\\3]'));
+ assert(match.isMatch('3', '[\\1-\\3]'));
+ assert(match.isMatch('5', '[--A]'));
+ 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(']', '[\\]]'));
+ 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'));
+ assert(match.isMatch('G', '[A-\\\\]'));
+ });
+
+ 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('c', '[[:space:]-z]'));
+ assert(match.isMatch('c', '[]-z]'));
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expand-brackets.git
More information about the Pkg-javascript-commits
mailing list