nanomatch
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -14,2 +14,18 @@ ## History | ||
### [1.0.4] - 2017-04-06 | ||
Housekeeping updates. Adds documentation section about escaping, cleans up utils. | ||
### [1.0.3] - 2017-04-06 | ||
This release includes fixes for windows path edge cases and other improvements for stricter adherence to bash spec. | ||
**Fixed** | ||
- More windows path edge cases | ||
**Added** | ||
- Support for bash-like quoted strings for escaping sequences of characters, such as `foo/"**"/bar` where `**` should be matched literally and not evaluated as special characters. | ||
### [1.0.1] - 2016-12-12 | ||
@@ -16,0 +32,0 @@ |
27
index.js
'use strict'; | ||
/** | ||
* Module dependencies | ||
*/ | ||
var util = require('util'); | ||
var toRegex = require('to-regex'); | ||
var extend = require('extend-shallow'); | ||
/** | ||
* Local dependencies | ||
@@ -73,3 +65,8 @@ */ | ||
} else { | ||
keep = list.map(utils.unixify(options)); | ||
var unixify = utils.unixify(options); | ||
keep = []; | ||
for (var i = 0; i < list.length; i++) { | ||
keep.push(unixify(list[i])); | ||
} | ||
} | ||
@@ -168,3 +165,3 @@ } | ||
if (typeof str !== 'string') { | ||
throw new TypeError('expected a string: "' + util.inspect(str) + '"'); | ||
throw new TypeError('expected a string'); | ||
} | ||
@@ -199,3 +196,3 @@ | ||
nanomatch.not = function(list, patterns, options) { | ||
var opts = extend({}, options); | ||
var opts = utils.extend({}, options); | ||
var ignore = opts.ignore; | ||
@@ -290,3 +287,3 @@ delete opts.ignore; | ||
var opts = extend({}, options); | ||
var opts = utils.extend({}, options); | ||
opts.strictClose = false; | ||
@@ -440,4 +437,4 @@ opts.strictOpen = false; | ||
var res = nanomatch.create(pattern, options); | ||
var opts = extend({wrap: false}, options); | ||
return toRegex(res.output, opts); | ||
var opts = utils.extend({wrap: false}, options); | ||
return utils.toRegex(res.output, opts); | ||
} | ||
@@ -629,3 +626,3 @@ | ||
/** | ||
* Expose parser, compiler and constructor on `nanomatch` | ||
* Expose compiler, parser and cache on `nanomatch` | ||
*/ | ||
@@ -632,0 +629,0 @@ |
'use strict'; | ||
var path = require('path'); | ||
var Snapdragon = require('snapdragon'); | ||
var utils = module.exports; | ||
var path = require('path'); | ||
@@ -10,8 +11,8 @@ /** | ||
var Snapdragon = require('snapdragon'); | ||
utils.define = require('define-property'); | ||
utils.diff = require('arr-diff'); | ||
utils.extend = require('extend-shallow'); | ||
utils.pick = require('object.pick'); | ||
utils.toRegex = require('to-regex'); | ||
utils.typeOf = require('kind-of'); | ||
utils.pick = require('object.pick'); | ||
utils.unique = require('array-unique'); | ||
@@ -228,3 +229,3 @@ | ||
var ch = str.charAt(1); | ||
if (ch === '\\' || ch === '/') { | ||
if (utils.isSlash(ch)) { | ||
return str.slice(2); | ||
@@ -246,2 +247,7 @@ } | ||
/** | ||
* Returns true if the given str is an escaped or | ||
* unescaped path character | ||
*/ | ||
utils.isSlash = function(str) { | ||
@@ -372,3 +378,5 @@ return str === '/' || str === '\\/' || str === '\\' || str === '\\\\'; | ||
return function(filepath) { | ||
if (utils.isWindows() || options.unixify === true) { | ||
if (options.unescape === true) { | ||
filepath = utils.unescape(filepath); | ||
} else if (utils.isWindows() || options.unixify === true) { | ||
filepath = utils.toPosixPath(filepath); | ||
@@ -379,7 +387,4 @@ } | ||
} | ||
if (options.unescape === true) { | ||
filepath = utils.unescape(filepath); | ||
} | ||
return filepath; | ||
}; | ||
}; |
{ | ||
"name": "nanomatch", | ||
"description": "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)", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"homepage": "https://github.com/jonschlinkert/nanomatch", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
181
README.md
@@ -10,2 +10,5 @@ # nanomatch [![NPM version](https://img.shields.io/npm/v/nanomatch.svg?style=flat)](https://www.npmjs.com/package/nanomatch) [![NPM monthly downloads](https://img.shields.io/npm/dm/nanomatch.svg?style=flat)](https://npmjs.org/package/nanomatch) [![NPM total downloads](https://img.shields.io/npm/dt/nanomatch.svg?style=flat)](https://npmjs.org/package/nanomatch) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/nanomatch.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/nanomatch) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/nanomatch.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/nanomatch) | ||
- [Getting started](#getting-started) | ||
* [Installing nanomatch](#installing-nanomatch) | ||
* [Usage](#usage) | ||
* [Documentation](#documentation) | ||
- [API](#api) | ||
@@ -33,3 +36,2 @@ - [Options](#options) | ||
* [Latest results](#latest-results) | ||
- [History](#history) | ||
- [About](#about) | ||
@@ -44,2 +46,50 @@ * [Related projects](#related-projects) | ||
<details> | ||
<summary><strong>Release history</strong></summary> | ||
## History | ||
### key | ||
Changelog entries are classified using the following labels _(from [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog)_): | ||
* `added`: for new features | ||
* `changed`: for changes in existing functionality | ||
* `deprecated`: for once-stable features removed in upcoming releases | ||
* `removed`: for deprecated features removed in this release | ||
* `fixed`: for any bug fixes | ||
* `bumped`: updated dependencies, only minor or higher will be listed. | ||
### [1.0.4](https://github.com/jonschlinkert/nanomatch/compare/1.0.3...1.0.4) - 2017-04-06 | ||
Housekeeping updates. Adds documentation section about escaping, cleans up utils. | ||
### [1.0.3](https://github.com/jonschlinkert/nanomatch/compare/1.0.1...1.0.3) - 2017-04-06 | ||
This release includes fixes for windows path edge cases and other improvements for stricter adherence to bash spec. | ||
**Fixed** | ||
* More windows path edge cases | ||
**Added** | ||
* Support for bash-like quoted strings for escaping sequences of characters, such as `foo/"**"/bar` where `**` should be matched literally and not evaluated as special characters. | ||
### [1.0.1](https://github.com/jonschlinkert/nanomatch/compare/1.0.0...1.0.1) - 2016-12-12 | ||
**Added** | ||
* Support for windows path edge cases where backslashes are used in brackets or other unusual combinations. | ||
### [1.0.0](https://github.com/jonschlinkert/nanomatch/compare/0.1.0...1.0.0) - 2016-12-12 | ||
Stable release. | ||
### [0.1.0] - 2016-10-08 | ||
First release. | ||
</details> | ||
## What is nanomatch? | ||
@@ -51,2 +101,3 @@ | ||
* [Getting started](#getting-started): learn how to install and begin using nanomatch | ||
* [Features](#features): jump to info about supported patterns, and a glob matching reference | ||
@@ -56,8 +107,41 @@ * [API documentation](#api): jump to available options and methods | ||
**How is this different from [micromatch](https://github.com/jonschlinkert/micromatch)?** | ||
<details> | ||
<summary><strong>How is this different from [minimatch](https://github.com/isaacs/minimatch)?</strong></summary> | ||
Micromatch supports 4 additional [bash "expansion" types](#bash-expansion-libs) beyond the wildcard matching provided by nanomatch. _(micromatch v3.0.0 will begin using the nanomatch parser and compiler for glob matching)_ | ||
**Speed and accuracy** | ||
Nanomatch uses [snapdragon](https://github.com/jonschlinkert/snapdragon) for parsing and compiling globs, which results in: | ||
* Granular control over the entire conversion process in a way that is easy to understand, reason about, and customize. | ||
* Much greater accuracy than minimatch. In fact, nanomatch passes _all of the spec tests_ from bash, including some that bash still fails. However, since there is no real specification for globs, if you encounter a pattern that yields unexpected match results [after researching previous issues](../../issues), [please let us know](../../issues/new). | ||
* Faster matching, from a combination of optimized glob patterns and (optional) caching. | ||
**Basic globbing only** | ||
Nanomatch supports [basic globbing only](#features), which is limited to `*`, `**`, `?` and regex-like brackets. | ||
If you need support for the other [bash "expansion" types](#bash-expansion-libs) (in addition to the wildcard matching provided by nanomatch), consider using [micromatch](https://github.com/jonschlinkert/micromatch) instead. _(micromatch >=3.0.0 uses the nanomatch parser and compiler for basic glob matching)_ | ||
</details> | ||
## Getting started | ||
### Installing nanomatch | ||
**Install with [yarn](https://yarnpkg.com/)** | ||
```sh | ||
$ yarn add nanomatch | ||
``` | ||
**Install with [npm](https://npmjs.com)** | ||
```sh | ||
$ npm install nanomatch | ||
``` | ||
### Usage | ||
Add nanomatch to your project using node's `require()` system: | ||
```js | ||
@@ -67,3 +151,3 @@ var nanomatch = require('nanomatch'); | ||
// the main export is a function that takes an array of strings to match | ||
// and one or more patterns to use for matching | ||
// and a string or array of patterns to use for matching | ||
nanomatch(list, patterns[, options]); | ||
@@ -74,7 +158,7 @@ ``` | ||
* `list` **{String|Array}**: One or more strings to match against. This is often a list of files. | ||
* `list` **{String|Array}**: List of strings to perform matches against. This is often a list of file paths. | ||
* `patterns` **{String|Array}**: One or more [glob paterns](#features) to use for matching. | ||
* `options` **{Object}**: Visit the API to learn about available options. | ||
* `options` **{Object}**: Any [supported options](#options) may be passed | ||
**Example** | ||
**Examples** | ||
@@ -93,4 +177,30 @@ ```js | ||
Additional detail provided in the [API documentation](#api). | ||
See the [API documentation](#api) for available methods and [options](https://github.com/einaros/options.js). | ||
### Documentation | ||
<details> | ||
<summary><strong>Escaping</strong></summary> | ||
Backslashes and quotes can be used to escape characters, forcing nanomatch to regard those characters as a literal characters. | ||
**Backslashes** | ||
Use backslashes to escape single characters. For example, the following pattern would match `foo/` folled by a literal `*`, followed by zero or more of any characters besides `/`, followed by `/bar`. | ||
```js | ||
'foo/\**/bar' | ||
``` | ||
**Quoted strings** | ||
Use single or double quotes to escape sequences of characters. For example, the following patterns would match `foo/**/bar` exactly: | ||
```js | ||
'foo/"**"/bar' | ||
"foo/'**'/bar" | ||
``` | ||
</details> | ||
## API | ||
@@ -101,3 +211,3 @@ | ||
### [nanomatch](index.js#L39) | ||
### [nanomatch](index.js#L31) | ||
@@ -128,3 +238,3 @@ The main function takes a list of strings and one or more glob patterns to use for matching. | ||
### [.match](index.js#L102) | ||
### [.match](index.js#L99) | ||
@@ -155,3 +265,3 @@ Similar to the main function, but `pattern` must be a string. | ||
### [.isMatch](index.js#L165) | ||
### [.isMatch](index.js#L162) | ||
@@ -184,3 +294,3 @@ Returns true if the specified `string` matches the given glob `pattern`. | ||
### [.not](index.js#L196) | ||
### [.not](index.js#L193) | ||
@@ -211,3 +321,3 @@ Returns a list of strings that _DO NOT MATCH_ any of the given `patterns`. | ||
### [.any](index.js#L230) | ||
### [.any](index.js#L227) | ||
@@ -240,3 +350,3 @@ Returns true if the given `string` matches any of the given glob `patterns`. | ||
### [.contains](index.js#L271) | ||
### [.contains](index.js#L268) | ||
@@ -269,3 +379,3 @@ Returns true if the given `string` contains the given pattern. Similar to [.isMatch](#isMatch) but the pattern can match any part of the string. | ||
### [.matchKeys](index.js#L326) | ||
### [.matchKeys](index.js#L323) | ||
@@ -297,3 +407,3 @@ Filter the keys of the given object with the given `glob` pattern and `options`. Does not attempt to match nested keys. If you need this feature, use [glob-object](https://github.com/jonschlinkert/glob-object) instead. | ||
### [.matcher](index.js#L355) | ||
### [.matcher](index.js#L352) | ||
@@ -326,3 +436,3 @@ Returns a memoized matcher function from the given glob `pattern` and `options`. The returned function takes a string to match as its only argument and returns true if the string is a match. | ||
### [.makeRe](index.js#L421) | ||
### [.makeRe](index.js#L418) | ||
@@ -352,3 +462,3 @@ Create a regular expression from the given glob `pattern`. | ||
### [.create](index.js#L482) | ||
### [.create](index.js#L479) | ||
@@ -400,3 +510,3 @@ Parses the given glob `pattern` and returns an object with the compiled `output` and optional source `map`. | ||
### [.parse](index.js#L521) | ||
### [.parse](index.js#L518) | ||
@@ -439,3 +549,3 @@ Parse the given `str` with the given `options`. | ||
### [.compile](index.js#L574) | ||
### [.compile](index.js#L571) | ||
@@ -479,3 +589,3 @@ Compile the given `ast` or string with the given `options`. | ||
### [.clearCache](index.js#L597) | ||
### [.clearCache](index.js#L594) | ||
@@ -843,29 +953,2 @@ Clear the regex cache. | ||
## History | ||
### key | ||
Changelog entries are classified using the following labels _(from [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog)_): | ||
* `added`: for new features | ||
* `changed`: for changes in existing functionality | ||
* `deprecated`: for once-stable features removed in upcoming releases | ||
* `removed`: for deprecated features removed in this release | ||
* `fixed`: for any bug fixes | ||
* `bumped`: updated dependencies, only minor or higher will be listed. | ||
### [1.0.1](https://github.com/jonschlinkert/nanomatch/compare/1.0.0...1.0.1) - 2016-12-12 | ||
**Added** | ||
* Support for windows path edge cases where backslashes are used in brackets or other unusual combinations. | ||
### [1.0.0](https://github.com/jonschlinkert/nanomatch/compare/0.1.0...1.0.0) - 2016-12-12 | ||
Stable release. | ||
### [0.1.0] - 2016-10-08 | ||
First release. | ||
## About | ||
@@ -906,2 +989,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 06, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 09, 2017._ |
967
72045
9
1381