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.0.1 to 0.1.0

17

index.js
const dotRE = /\./g
const globAllRE = /\*\*/g
const globDirsRE = /\*\*\//g
const globNamesRE = /\*/g
function globRegex(glob) {
if (Array.isArray(glob)) {
glob = '((' + glob.join(')|(') + '))'
}
const pattern = glob
.replace('.', '\\.')
.replace('**/', '(.+\\/)?')
.replace('**', '(.+\\/)?*')
.replace('*', '[^\\/]+')
.replace(dotRE, '\\.')
.replace(globDirsRE, '(.+/)?')
.replace(globAllRE, '(.+/)?*')
.replace(globNamesRE, '[^/]+')

@@ -9,0 +18,0 @@ return new RegExp('^' + pattern + '$')

{
"name": "glob-regex",
"version": "0.0.1",
"version": "0.1.0",
"repository": {

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

# glob-regex v0.0.1
# glob-regex v0.1.0

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

@@ -16,2 +16,10 @@ #!/usr/bin/env node

},
'*/*.js': {
'a.js': false,
'a/b.js': true,
'a/b/c.js': false,
'a/b.css': false,
'.js': false,
'': false,
},
'**.js': {

@@ -74,1 +82,8 @@ 'a.js': true,

})
test('an array can be passed', (t) => {
const re = globRegex(['*.js', '*.css'])
t.assert(!re.test('a.jsx'))
t.assert(re.test('a.js'))
t.assert(re.test('b.css'))
})
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