Projekt

Obecné

Profil

Stáhnout (7.15 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# is-glob [![NPM version](https://img.shields.io/npm/v/is-glob.svg?style=flat)](https://www.npmjs.com/package/is-glob) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-glob.svg?style=flat)](https://npmjs.org/package/is-glob) [![NPM total downloads](https://img.shields.io/npm/dt/is-glob.svg?style=flat)](https://npmjs.org/package/is-glob) [![Linux Build Status](https://img.shields.io/travis/micromatch/is-glob.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/is-glob) [![Windows Build Status](https://img.shields.io/appveyor/ci/micromatch/is-glob.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/micromatch/is-glob)
2
3
> Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.
4
5
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6
7
## Install
8
9
Install with [npm](https://www.npmjs.com/):
10
11
```sh
12
$ npm install --save is-glob
13
```
14
15
You might also be interested in [is-valid-glob](https://github.com/jonschlinkert/is-valid-glob) and [has-glob](https://github.com/jonschlinkert/has-glob).
16
17
## Usage
18
19
```js
20
var isGlob = require('is-glob');
21
```
22
23
### Default behavior
24
25
**True**
26
27
Patterns that have glob characters or regex patterns will return `true`:
28
29
```js
30
isGlob('!foo.js');
31
isGlob('*.js');
32
isGlob('**/abc.js');
33
isGlob('abc/*.js');
34
isGlob('abc/(aaa|bbb).js');
35
isGlob('abc/[a-z].js');
36
isGlob('abc/{a,b}.js');
37
//=> true
38
```
39
40
Extglobs
41
42
```js
43
isGlob('abc/@(a).js');
44
isGlob('abc/!(a).js');
45
isGlob('abc/+(a).js');
46
isGlob('abc/*(a).js');
47
isGlob('abc/?(a).js');
48
//=> true
49
```
50
51
**False**
52
53
Escaped globs or extglobs return `false`:
54
55
```js
56
isGlob('abc/\\@(a).js');
57
isGlob('abc/\\!(a).js');
58
isGlob('abc/\\+(a).js');
59
isGlob('abc/\\*(a).js');
60
isGlob('abc/\\?(a).js');
61
isGlob('\\!foo.js');
62
isGlob('\\*.js');
63
isGlob('\\*\\*/abc.js');
64
isGlob('abc/\\*.js');
65
isGlob('abc/\\(aaa|bbb).js');
66
isGlob('abc/\\[a-z].js');
67
isGlob('abc/\\{a,b}.js');
68
//=> false
69
```
70
71
Patterns that do not have glob patterns return `false`:
72
73
```js
74
isGlob('abc.js');
75
isGlob('abc/def/ghi.js');
76
isGlob('foo.js');
77
isGlob('abc/@.js');
78
isGlob('abc/+.js');
79
isGlob('abc/?.js');
80
isGlob();
81
isGlob(null);
82
//=> false
83
```
84
85
Arrays are also `false` (If you want to check if an array has a glob pattern, use [has-glob](https://github.com/jonschlinkert/has-glob)):
86
87
```js
88
isGlob(['**/*.js']);
89
isGlob(['foo.js']);
90
//=> false
91
```
92
93
### Option strict
94
95
When `options.strict === false` the behavior is less strict in determining if a pattern is a glob. Meaning that
96
some patterns that would return `false` may return `true`. This is done so that matching libraries like [micromatch](https://github.com/micromatch/micromatch) have a chance at determining if the pattern is a glob or not.
97
98
**True**
99
100
Patterns that have glob characters or regex patterns will return `true`:
101
102
```js
103
isGlob('!foo.js', {strict: false});
104
isGlob('*.js', {strict: false});
105
isGlob('**/abc.js', {strict: false});
106
isGlob('abc/*.js', {strict: false});
107
isGlob('abc/(aaa|bbb).js', {strict: false});
108
isGlob('abc/[a-z].js', {strict: false});
109
isGlob('abc/{a,b}.js', {strict: false});
110
//=> true
111
```
112
113
Extglobs
114
115
```js
116
isGlob('abc/@(a).js', {strict: false});
117
isGlob('abc/!(a).js', {strict: false});
118
isGlob('abc/+(a).js', {strict: false});
119
isGlob('abc/*(a).js', {strict: false});
120
isGlob('abc/?(a).js', {strict: false});
121
//=> true
122
```
123
124
**False**
125
126
Escaped globs or extglobs return `false`:
127
128
```js
129
isGlob('\\!foo.js', {strict: false});
130
isGlob('\\*.js', {strict: false});
131
isGlob('\\*\\*/abc.js', {strict: false});
132
isGlob('abc/\\*.js', {strict: false});
133
isGlob('abc/\\(aaa|bbb).js', {strict: false});
134
isGlob('abc/\\[a-z].js', {strict: false});
135
isGlob('abc/\\{a,b}.js', {strict: false});
136
//=> false
137
```
138
139
## About
140
141
<details>
142
<summary><strong>Contributing</strong></summary>
143
144
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
145
146
</details>
147
148
<details>
149
<summary><strong>Running Tests</strong></summary>
150
151
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:
152
153
```sh
154
$ npm install && npm test
155
```
156
157
</details>
158
159
<details>
160
<summary><strong>Building docs</strong></summary>
161
162
_(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.)_
163
164
To generate the readme, run the following command:
165
166
```sh
167
$ npm install -g verbose/verb#dev verb-generate-readme && verb
168
```
169
170
</details>
171
172
### Related projects
173
174
You might also be interested in these projects:
175
176
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
177
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
178
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
179
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")
180
181
### Contributors
182
183
| **Commits** | **Contributor** |  
184
| --- | --- |  
185
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |  
186
| 5  | [doowb](https://github.com/doowb) |  
187
| 1  | [phated](https://github.com/phated) |  
188
| 1  | [danhper](https://github.com/danhper) |  
189
| 1  | [paulmillr](https://github.com/paulmillr) |  
190
191
### Author
192
193
**Jon Schlinkert**
194
195
* [GitHub Profile](https://github.com/jonschlinkert)
196
* [Twitter Profile](https://twitter.com/jonschlinkert)
197
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
198
199
### License
200
201
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
202
Released under the [MIT License](LICENSE).
203
204
***
205
206
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 27, 2019._