Socket
Socket
Sign inDemoInstall

glob-regex

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-regex - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

39

index.js
const dotRE = /\./g
const globAnyRE = /\*\*/g
const globEndRE = /\*\*$/g
const globDirsRE = /\*\*\//g
const globNamesRE = /\*/g
var dotRE = /\./g
var dotPattern = '\\.'
function globRegex(glob) {
const source = Array.isArray(glob) ? join(glob) : convert(glob)
return new RegExp('^' + source + '$')
var restRE = /\*\*$/g
var restPattern = '(.+)'
var globRE = /(?:\*\*\/|\*\*|\*)/g
var globPatterns = {
'*': '([^/]+)', // no backslashes
'**': '(.+/)?([^/]+)', // short for "**/*"
'**/': '(.+/)?', // one or more directories
}
function convert(glob) {
function mapToPattern(str) {
return globPatterns[str]
}
function replace(glob) {
return glob
.replace(dotRE, '\\.')
.replace(globDirsRE, '(.+/)?')
.replace(globEndRE, '(.+)')
.replace(globAnyRE, '(.+/)?([^/]+)')
.replace(globNamesRE, '([^/]+)')
.replace(dotRE, dotPattern)
.replace(restRE, restPattern)
.replace(globRE, mapToPattern)
}
function join(globs) {
return '((' + globs.map(convert).join(')|(') + '))'
return '((' + globs.map(replace).join(')|(') + '))'
}
function globRegex(glob) {
return new RegExp('^' + (Array.isArray(glob) ? join : replace)(glob) + '$')
}
globRegex.replace = replace
module.exports = globRegex
{
"name": "glob-regex",
"version": "0.2.2",
"version": "0.3.0",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

# glob-regex v0.2.2
# glob-regex v0.3.0

@@ -41,2 +41,4 @@ Convert a glob to a `RegExp` object.

Use `globRegex.replace()` to transform a glob into a RegExp-compatible string.
**NOTE:** It's not recommended to use `globRegex(array)` if you need

@@ -43,0 +45,0 @@ the `exec` method, since the result will be difficult to make use of.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc