1# is-glob [](https://www.npmjs.com/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://travis-ci.org/micromatch/is-glob) [](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 5Please 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 9Install with [npm](https://www.npmjs.com/): 10 11```sh 12$ npm install --save is-glob 13``` 14 15You 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 20var isGlob = require('is-glob'); 21``` 22 23### Default behavior 24 25**True** 26 27Patterns that have glob characters or regex patterns will return `true`: 28 29```js 30isGlob('!foo.js'); 31isGlob('*.js'); 32isGlob('**/abc.js'); 33isGlob('abc/*.js'); 34isGlob('abc/(aaa|bbb).js'); 35isGlob('abc/[a-z].js'); 36isGlob('abc/{a,b}.js'); 37//=> true 38``` 39 40Extglobs 41 42```js 43isGlob('abc/@(a).js'); 44isGlob('abc/!(a).js'); 45isGlob('abc/+(a).js'); 46isGlob('abc/*(a).js'); 47isGlob('abc/?(a).js'); 48//=> true 49``` 50 51**False** 52 53Escaped globs or extglobs return `false`: 54 55```js 56isGlob('abc/\\@(a).js'); 57isGlob('abc/\\!(a).js'); 58isGlob('abc/\\+(a).js'); 59isGlob('abc/\\*(a).js'); 60isGlob('abc/\\?(a).js'); 61isGlob('\\!foo.js'); 62isGlob('\\*.js'); 63isGlob('\\*\\*/abc.js'); 64isGlob('abc/\\*.js'); 65isGlob('abc/\\(aaa|bbb).js'); 66isGlob('abc/\\[a-z].js'); 67isGlob('abc/\\{a,b}.js'); 68//=> false 69``` 70 71Patterns that do not have glob patterns return `false`: 72 73```js 74isGlob('abc.js'); 75isGlob('abc/def/ghi.js'); 76isGlob('foo.js'); 77isGlob('abc/@.js'); 78isGlob('abc/+.js'); 79isGlob('abc/?.js'); 80isGlob(); 81isGlob(null); 82//=> false 83``` 84 85Arrays 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 88isGlob(['**/*.js']); 89isGlob(['foo.js']); 90//=> false 91``` 92 93### Option strict 94 95When `options.strict === false` the behavior is less strict in determining if a pattern is a glob. Meaning that 96some 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 100Patterns that have glob characters or regex patterns will return `true`: 101 102```js 103isGlob('!foo.js', {strict: false}); 104isGlob('*.js', {strict: false}); 105isGlob('**/abc.js', {strict: false}); 106isGlob('abc/*.js', {strict: false}); 107isGlob('abc/(aaa|bbb).js', {strict: false}); 108isGlob('abc/[a-z].js', {strict: false}); 109isGlob('abc/{a,b}.js', {strict: false}); 110//=> true 111``` 112 113Extglobs 114 115```js 116isGlob('abc/@(a).js', {strict: false}); 117isGlob('abc/!(a).js', {strict: false}); 118isGlob('abc/+(a).js', {strict: false}); 119isGlob('abc/*(a).js', {strict: false}); 120isGlob('abc/?(a).js', {strict: false}); 121//=> true 122``` 123 124**False** 125 126Escaped globs or extglobs return `false`: 127 128```js 129isGlob('\\!foo.js', {strict: false}); 130isGlob('\\*.js', {strict: false}); 131isGlob('\\*\\*/abc.js', {strict: false}); 132isGlob('abc/\\*.js', {strict: false}); 133isGlob('abc/\\(aaa|bbb).js', {strict: false}); 134isGlob('abc/\\[a-z].js', {strict: false}); 135isGlob('abc/\\{a,b}.js', {strict: false}); 136//=> false 137``` 138 139## About 140 141<details> 142<summary><strong>Contributing</strong></summary> 143 144Pull 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 151Running 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 164To 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 174You 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 201Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). 202Released 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._