sfcode: expand-brackets <a href="https://www.npmjs.com/package/expand-brackets"><img src="https://img.shields.io/npm/v/expand-brackets.svg?style=flat" alt="NPM version"/></a> <a href="https://npmjs.org/package/expand-brackets"><img src="https://img.shields.io/npm/dm/expand-brackets.svg?style=flat" alt="NPM monthly downloads"/></a> <a href="https://npmjs.org/package/expand-brackets"><img src="https://img.shields.io/npm/dt/expand-brackets.svg?style=flat" alt="NPM total downloads"/></a> <a href="https://travis-ci.org/jonschlinkert/expand-brackets"><img src="https://img.shields.io/travis/jonschlinkert/expand-brackets.svg?style=flat&label=Travis" alt="Linux Build Status"/></a> <a href="https://ci.appveyor.com/project/jonschlinkert/expand-brackets"><img src="https://img.shields.io/appveyor/ci/jonschlinkert/expand-brackets.svg?style=flat&label=AppVeyor" alt="Windows Build Status"/></a>

sfcode An Online Competing and Development Environment

expand-brackets

> Expand POSIX bracket expressions (character classes) in glob patterns.

# Install

Install with npm:

$ npm install --save expand-brackets

# Usage

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

console.log(brackets('[![:lower:]]'));
//=> '[^a-z]'

# API

## <a href="index.js#L29">brackets</a>

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}**

## <a href="index.js#L54">.match</a>

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

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}**

## <a href="index.js#L100">.isMatch</a>

Returns true if the specified `string` matches the given brackets `pattern`.

Example

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}**

## <a href="index.js#L123">.matcher</a>

Takes a POSIX character class pattern and returns a matcher function. The returned function takes the string to match as its only argument.

Example

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}**

## <a href="index.js#L145">.makeRe</a>

Create a regular expression from the given `pattern`.

Example

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}**

## <a href="index.js#L187">.create</a>

Parses the given POSIX character class `pattern` and returns an object with the compiled `output` and optional source `map`.

Example

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

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 are not supported
- POSIX.2 collating symbols 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)
- compiler is exposed, so that expand-brackets compilers can be used by upstream compilers
- source maps

source map example

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: Fast, comprehensive, bash-like brace expansion implemented in JavaScript. Complete support for the Bash 4.3 braces… more | homepage
- extglob: Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… more | [homepage](https://github.com/jonschlinkert/extglob "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.")
- micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | homepage
- nanomatch: Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… more | [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.

## Contributors

Commits | Contributor
--- | ---
66 | jonschlinkert
2 | MartinKolarik
2 | es128
1 | eush77

## Building docs

_(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)_

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

## Running tests

Install dev dependencies:

$ npm install -d && npm test

## Author

Jon Schlinkert

- github/jonschlinkert
- twitter/jonschlinkert

## License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.

This file was generated by verb-generate-readme, v0.2.0, on December 12, 2016.