# glob-regex

> Tiny glob->regex converter

Latest version **0.3.2** (published 2018-11-19) · 0 weekly downloads

## Install

```sh
npm install glob-regex
pnpm add glob-regex
yarn add glob-regex
bun add glob-regex
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2018-11-19 |
| First published | 2017-11-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | aleclarson |
| Keywords | glob, globs, regex, regexp |

## Links

- npm: https://www.npmjs.com/package/glob-regex
- Repository: https://github.com/aleclarson/glob-regex
- Homepage: https://github.com/aleclarson/glob-regex#readme
- Issues: https://github.com/aleclarson/glob-regex/issues
- npm.io page: https://npm.io/package/glob-regex

## Recent versions

- 0.3.2 (latest) — 2018-11-19
- 0.3.1 — 2018-11-13
- 0.3.0 — 2018-06-26
- 0.2.2 — 2017-12-30
- 0.2.1 — 2017-12-30
- 0.2.0 — 2017-12-13
- 0.1.1 — 2017-12-01
- 0.1.0 — 2017-11-30
- 0.0.1 — 2017-11-26

## README

# glob-regex

[![npm](https://img.shields.io/npm/v/glob-regex.svg)](https://www.npmjs.com/package/glob-regex)
[![Bundle size](https://badgen.net/bundlephobia/min/glob-regex)](https://bundlephobia.com/result?p=glob-regex)
[![Install size](https://packagephobia.now.sh/badge?p=glob-regex)](https://packagephobia.now.sh/result?p=glob-regex)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)

Convert a glob to a `RegExp` object.

- Any periods are escaped (`.` -> `\\.`)
- `*` and `**` are replaced
- Always start with `^` and end with `$`
- All `RegExp` syntax is valid
- Path separators are auto-escaped by `new RegExp`

```js
const globRegex = require('glob-regex')

// Match no directory.
let re = globRegex('*.js')
re.test('a.js') // => true
re.test('a.css') // => false
re.test('a/b.js') // => false

// Use ? operator for optional character.
re = globRegex('*.jsx?')
re.test('a.js') // => true
re.test('b.jsx') // => true

// Match any directory.
re = globRegex('**.css')
re.test('a.css') // => true
re.test('a/b.css') // => true

// Match any directory and specific name.
re = globRegex('**/a.css')
re.test('a.css') // => true
re.test('b/a.css') // => true

// Use | operator to match multiple values.
re = globRegex('*.(js|css)')
re.test('a.js') // => true
re.test('a.css') // => true
```

Use `globRegex.replace()` to transform a glob into a RegExp-compatible string.

**NOTE:** It's not recommended to use `globRegex(array)` if you need
the `exec` method, since the result will be difficult to make use of.
Using the `test` method works great, though!

---
_Source: https://npm.io/package/glob-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
