Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glob-to-regexp

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-to-regexp

Convert globs to regular expressions

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is glob-to-regexp?

The glob-to-regexp npm package is used to convert glob expressions into JavaScript RegExp objects. This allows for pattern matching based on the glob pattern, which is commonly used for file matching in file systems.

What are glob-to-regexp's main functionalities?

Convert glob to RegExp

This feature allows the conversion of a simple glob pattern ('*.js') into a RegExp object. The resulting RegExp can then be used to test if strings (like filenames) match the pattern.

const globToRegExp = require('glob-to-regexp');
const pattern = globToRegExp('*.js');
console.log(pattern.test('example.js')); // true
console.log(pattern.test('example.txt')); // false

Case insensitive matching

This feature demonstrates how to convert a glob pattern into a RegExp object with case insensitive matching enabled. This is useful for environments where file names are case-insensitive, such as Windows.

const globToRegExp = require('glob-to-regexp');
const pattern = globToRegExp('*.JS', { extended: true, globstar: true, flags: 'i' });
console.log(pattern.test('EXAMPLE.js')); // true

Extended glob matching

This feature shows how to handle extended glob patterns, such as optional patterns using '?'. It converts the glob into a RegExp that matches both 'pattern.js' and '.js'.

const globToRegExp = require('glob-to-regexp');
const pattern = globToRegExp('?(pattern).js', { extended: true });
console.log(pattern.test('pattern.js')); // true
console.log(pattern.test('.js')); // true

Other packages similar to glob-to-regexp

Keywords

FAQs

Package last updated on 01 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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