pax_global_header00006660000000000000000000000064132715676530014531gustar00rootroot0000000000000052 comment=1a70cc275197ea0297c915fbac03ea86e3a392ae expand-brackets-4.0.0/000077500000000000000000000000001327156765300146055ustar00rootroot00000000000000expand-brackets-4.0.0/.editorconfig000066400000000000000000000004051327156765300172610ustar00rootroot00000000000000root = 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 = falseexpand-brackets-4.0.0/.eslintrc.json000066400000000000000000000071251327156765300174060ustar00rootroot00000000000000{ "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-4.0.0/.gitattributes000066400000000000000000000000171327156765300174760ustar00rootroot00000000000000*.* text eol=lfexpand-brackets-4.0.0/.gitignore000066400000000000000000000003431327156765300165750ustar00rootroot00000000000000# 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-4.0.0/.travis.yml000066400000000000000000000001361327156765300167160ustar00rootroot00000000000000sudo: false language: node_js os: - linux - osx node_js: - '10' - '8' - '6' - '4' expand-brackets-4.0.0/.verb.md000066400000000000000000000031641327156765300161470ustar00rootroot00000000000000## 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-4.0.0/LICENSE000066400000000000000000000020771327156765300156200ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015-2018, 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-4.0.0/README.md000066400000000000000000000242011327156765300160630ustar00rootroot00000000000000# 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/micromatch/expand-brackets.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/expand-brackets) [![Windows Build Status](https://img.shields.io/appveyor/ci/micromatch/expand-brackets.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/micromatch/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 ``` Install with [yarn](https://yarnpkg.com): ```sh $ yarn add 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#L27) 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#L51) Takes an array of strings and a POSIX character class pattern, and returns a new array with only the strings that matched the pattern. **Params** * `arr` **{Array}**: Array of strings to match * `pattern` **{String}**: POSIX character class pattern(s) * `options` **{Object}** * `returns` **{Array}** **Example** ```js const brackets = require('expand-brackets'); console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]')); //=> ['a'] console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+')); //=> ['a', 'ab'] ``` ### [.isMatch](index.js#L97) Returns true if the specified `string` matches the given brackets `pattern`. **Params** * `string` **{String}**: String to match * `pattern` **{String}**: Poxis pattern * `options` **{String}** * `returns` **{Boolean}** **Example** ```js const brackets = require('expand-brackets'); console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]')); //=> true console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]')); //=> false ``` ### [.matcher](index.js#L120) Takes a POSIX character class pattern and returns a matcher function. The returned function takes the string to match as its only argument. **Params** * `pattern` **{String}**: Poxis pattern * `options` **{String}** * `returns` **{Boolean}** **Example** ```js const brackets = require('expand-brackets'); const isMatch = brackets.matcher('[[:lower:]].[[:upper:]]'); console.log(isMatch('a.a')); //=> false console.log(isMatch('a.A')); //=> true ``` ### [.makeRe](index.js#L140) Create a regular expression from the given `pattern`. **Params** * `pattern` **{String}**: The pattern to convert to regex. * `options` **{Object}** * `returns` **{RegExp}** **Example** ```js const brackets = require('expand-brackets'); const re = brackets.makeRe('[[:alpha:]]'); console.log(re); //=> /^(?:[a-zA-Z])$/ ``` ### [.create](index.js#L182) Parses the given POSIX character class `pattern` and returns an object with the compiled `output` and optional source `map`. **Params** * `pattern` **{String}** * `options` **{Object}** * `returns` **{Object}** **Example** ```js const 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: [] } ``` ## 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 ### v4.0.0 **Breaking changes** * Snapdragon was updated to 0.12. Other packages that integrate `expand-brackets` need to also use snapdragon 0.12. * Minimum Node.JS version is now version 4. ### v3.0.0 **Breaking changes** * Snapdragon was updated to 0.11. Other packages that integrate `expand-brackets` need to also use snapdragon 0.11. ### 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/micromatch/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): Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with 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/micromatch/extglob) | [homepage](https://github.com/micromatch/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/micromatch/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/micromatch/nanomatch) | [homepage](https://github.com/micromatch/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** | | --- | --- | | 69 | [jonschlinkert](https://github.com/jonschlinkert) | | 13 | [danez](https://github.com/danez) | | 2 | [MartinKolarik](https://github.com/MartinKolarik) | | 2 | [es128](https://github.com/es128) | | 1 | [doowb](https://github.com/doowb) | | 1 | [eush77](https://github.com/eush77) | | 1 | [mjbvz](https://github.com/mjbvz) | ### Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ``` ### Running tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ``` ### Author **Jon Schlinkert** * [github/jonschlinkert](https://github.com/jonschlinkert) * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) ### License Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 30, 2018._expand-brackets-4.0.0/appveyor.yml000066400000000000000000000010641327156765300171760ustar00rootroot00000000000000# Test against this version of Node.js environment: matrix: # node.js - nodejs_version: "10.0" - nodejs_version: "8.0" - nodejs_version: "6.0" - nodejs_version: "4.0" # 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-4.0.0/changelog.md000066400000000000000000000024571327156765300170660ustar00rootroot00000000000000## Changelog ### v4.0.0 **Breaking changes** - Snapdragon was updated to 0.12. Other packages that integrate `expand-brackets` need to also use snapdragon 0.12. - Minimum Node.JS version is now version 4. ### v3.0.0 **Breaking changes** - Snapdragon was updated to 0.11. Other packages that integrate `expand-brackets` need to also use snapdragon 0.11. ### 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-4.0.0/examples/000077500000000000000000000000001327156765300164235ustar00rootroot00000000000000expand-brackets-4.0.0/examples/isMatch.js000066400000000000000000000001571327156765300203540ustar00rootroot00000000000000'use strict'; var brackets = require('..'); console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]')); expand-brackets-4.0.0/examples/makeRe.js000066400000000000000000000001621327156765300201640ustar00rootroot00000000000000'use strict'; var brackets = require('..'); var pattern = '[[:alpha:]]'; console.log(brackets.makeRe(pattern)); expand-brackets-4.0.0/examples/match.js000066400000000000000000000002541327156765300200560ustar00rootroot00000000000000'use strict'; var brackets = require('..'); console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]')); console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+')); expand-brackets-4.0.0/examples/posix.js000066400000000000000000000002311327156765300201170ustar00rootroot00000000000000'use strict'; var brackets = require('..'); var pattern = '[[:alpha:]]'; var res = brackets(pattern); // console.log(res.ast.nodes); console.log(res); expand-brackets-4.0.0/examples/source-maps.js000066400000000000000000000002321327156765300212140ustar00rootroot00000000000000'use strict'; var brackets = require('..'); var pattern = 'a/[[:alpha:][:digit:]]/b'; var res = brackets(pattern, {sourcemap: true}); console.log(res); expand-brackets-4.0.0/index.js000066400000000000000000000117141327156765300162560ustar00rootroot00000000000000'use strict'; /** * Local dependencies */ const compilers = require('./lib/compilers'); const parsers = require('./lib/parsers'); /** * Module dependencies */ const Snapdragon = require('snapdragon'); const 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) { const 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 * const 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); const opts = Object.assign({}, options); const isMatch = brackets.matcher(pattern, opts); const len = arr.length; const res = []; let idx = -1; while (++idx < len) { const 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 * const 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 * const brackets = require('expand-brackets'); * const 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) { const re = brackets.makeRe(pattern, options); return (str) => re.test(str); }; /** * Create a regular expression from the given `pattern`. * * ```js * const brackets = require('expand-brackets'); * const 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) { const res = brackets.create(pattern, options); const opts = Object.assign({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 * const 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) { const snapdragon = (options && options.snapdragon) || new Snapdragon(options); compilers(snapdragon); parsers(snapdragon); const ast = snapdragon.parse(pattern, options); ast.input = pattern; const 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-4.0.0/lib/000077500000000000000000000000001327156765300153535ustar00rootroot00000000000000expand-brackets-4.0.0/lib/compilers.js000066400000000000000000000037551327156765300177200ustar00rootroot00000000000000'use strict'; const 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); } let 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); }) .set('bracket.open', function(node) { return this.emit(node.val, node); }) .set('bracket.inner', function(node) { let 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('\\-'); } const 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) { const val = node.val.replace(/^\\/, ''); if (node.parent.escaped === true) { return this.emit('\\' + val, node); } return this.emit(val, node); }); }; expand-brackets-4.0.0/lib/parsers.js000066400000000000000000000103201327156765300173640ustar00rootroot00000000000000'use strict'; const utils = require('./utils'); /** * Text regex */ const TEXT_REGEX = '(\\[(?=.*\\])|\\])+'; const not = utils.createRegex(TEXT_REGEX); /** * Brackets parsers */ function parsers(brackets) { brackets.state = brackets.state || {}; brackets.parser.sets.bracket = brackets.parser.sets.bracket || []; brackets.parser .set('escape', function() { if (this.isInside('bracket')) return; const pos = this.position(); const m = this.match(/^\\(.)/); if (!m) return; return pos({ type: 'escape', val: m[0] }); }) /** * Text parser */ .set('text', function() { if (this.isInside('bracket')) return; const pos = this.position(); const m = this.match(not); if (!m || !m[0]) return; return pos({ type: 'text', val: m[0] }); }) /** * POSIX character classes: "[[:alpha:][:digits:]]" */ .set('posix', function() { const pos = this.position(); const 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) */ .set('bracket', function() {}) /** * Open: '[' */ .set('bracket.open', function() { const parsed = this.parsed; const pos = this.position(); const m = this.match(/^\[(?=.*\])/); if (!m) return; const prev = this.prev(); const 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] }); } const 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; } const node = pos({ type: 'bracket', nodes: [] }); this.push('bracket', node); this.pushNode(node, prev); this.pushNode(open, node); }) /** * Bracket text */ .set('bracket.inner', function() { if (!this.isInside('bracket')) return; const pos = this.position(); const m = this.match(not); if (!m || !m[0]) return; const next = this.input.charAt(0); let val = m[0]; const node = pos({ type: 'bracket.inner', val }); if (val === '\\\\') { return node; } const first = val.charAt(0); const 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: ']' */ .set('bracket.close', function() { const parsed = this.parsed; const pos = this.position(); const m = this.match(/^\]/); if (!m) return; const prev = this.prev(); const 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] }); } const 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; } const 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; } this.pushNode(node, bracket); }); } /** * Brackets parsers */ module.exports = parsers; /** * Expose text regex */ module.exports.TEXT_REGEX = TEXT_REGEX; expand-brackets-4.0.0/lib/utils.js000066400000000000000000000012401327156765300170460ustar00rootroot00000000000000'use strict'; const toRegex = require('to-regex'); const regexNot = require('regex-not'); let 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; const opts = {contains: true, strictClose: false}; const not = regexNot.create(pattern, opts); let re; if (typeof include === 'string') { re = toRegex('^(?:' + include + '|' + not + ')', opts); } else { re = toRegex(not, opts); } return (cached = re); }; expand-brackets-4.0.0/package.json000066400000000000000000000034161327156765300170770ustar00rootroot00000000000000{ "name": "expand-brackets", "description": "Expand POSIX bracket expressions (character classes) in glob patterns.", "version": "4.0.0", "homepage": "https://github.com/micromatch/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": "micromatch/expand-brackets", "bugs": { "url": "https://github.com/micromatch/expand-brackets/issues" }, "license": "MIT", "files": [ "index.js", "lib" ], "main": "index.js", "engines": { "node": ">=4.0.0" }, "scripts": { "test": "mocha" }, "dependencies": { "posix-character-classes": "^1.0.0", "regex-not": "^1.0.0", "snapdragon": "^0.12.0", "to-regex": "^3.0.1" }, "devDependencies": { "bash-match": "^1.0.2", "gulp-format-md": "^1.0.0", "helper-changelog": "^0.3.0", "minimatch": "^3.0.3", "mocha": "^5.1.1", "multimatch": "^2.1.0", "yargs-parser": "^10.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-4.0.0/test/000077500000000000000000000000001327156765300155645ustar00rootroot00000000000000expand-brackets-4.0.0/test/support/000077500000000000000000000000001327156765300173005ustar00rootroot00000000000000expand-brackets-4.0.0/test/support/compare.js000066400000000000000000000001701327156765300212620ustar00rootroot00000000000000module.exports = function(a, b) { a = a.toLowerCase(); b = b.toLowerCase(); return a > b ? 1 : a < b ? -1 : 0; }; expand-brackets-4.0.0/test/support/match.js000066400000000000000000000024071327156765300207350ustar00rootroot00000000000000'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-4.0.0/test/support/matcher.js000066400000000000000000000031521327156765300212620ustar00rootroot00000000000000'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-4.0.0/test/support/utils.js000066400000000000000000000003731327156765300210010ustar00rootroot00000000000000'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-4.0.0/test/test.js000066400000000000000000000275231327156765300171120ustar00rootroot00000000000000'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-4.0.0/test/wildmatch.js000066400000000000000000000170441327156765300201040ustar00rootroot00000000000000'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('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('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]')); }); });