Socket
Socket
Sign inDemoInstall

@jsxtools/glob

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jsxtools/glob

convert glob patterns into regular expressions


Version published
Weekly downloads
4
decreased by-78.95%
Maintainers
1
Install size
10.9 kB
Created
Weekly downloads
 

Readme

Source

glob

npm version build status issue tracker pull requests

glob lets you convert glob patterns into regular expressions. It has no dependencies and is 1120 bytes, or 471 bytes gzipped. It works in all browsers and all versions of Node.

glob is a code-golfing fork of the amazing globrex.

Usage

Add glob to your project:

npm install @jsxtools/glob

Use glob to convert glob patterns into regular expressions:

glob = require('@jsxtools/glob')

// match JS files either within "path/to/" or a subdirectory of "path/to/"
match1 = glob('path/to/{*,*/*}.js')

// these paths will match
match1.test('path/to/file.js')
match1.test('path/to/lib/file.js')

// these paths will NOT match
match1.test('path/to/file.js.map')
match1.test('path/to/lib/deeper/file.js')
match1.test('path/to/file.js/lib')

// match paths that start with "p" followed by any letter followed by "ck"
match2 = glob('p[a-z]ck')

// these will match
match2.test('pack')
match2.test('puck')

// these will NOT match
match2.test('pck')
match2.test('pluck')
match2.test('p-ck')

glob supports single character matching.

glob('/path/to/file?.txt').test('/path/to/file1.txt') // true
glob('/path/to/file?.txt').test('/path/to/file2.txt') // true
glob('/path/to/file?.txt').test('/path/to/file3.txt') // true
glob('/path/to/file?.txt').test('/path/to/fileZ.txt') // true

glob('/path/to/file?.txt').test('/path/to/file11.txt') // FALSE
glob('/path/to/file?.txt').test('/path/to/file.txt') // FALSE

glob supports matching ranges of characters.

glob('/path/to/[a-c]').test('/path/to/a') // true
glob('/path/to/[a-c]').test('/path/to/b') // true
glob('/path/to/[a-c]').test('/path/to/c') // true

glob('/path/to/[a-c]').test('/path/to/d') // FALSE
glob('/path/to/[a-c]').test('/path/to/e') // FALSE

glob supports group matching.

glob('{*.doc,*.pdf}').test('file.doc') // true
glob('{*.doc,*.pdf}').test('file.pdf') // true
glob('{*.doc,*.pdf}').test('file.xxx.pdf') // true

glob('{*.doc,*.pdf}').test('file.pdf.xxx') // FALSE

glob supports globstar patterns.

glob('/path/*/index.js').test('/path/to/index.js') // true
glob('/path/*/index.js').test('/path/of/index.js') // true

glob('/path/*/index.js').test('/path/to/the/index.js') // FALSE
glob('/path/*/index.js').test('/path/of/the/index.js') // FALSE
glob('/path/*/index.js').test('/path/index.js') // FALSE
glob('/path/*/index.js').test('/index.js') // FALSE

glob supports posix-style paths and does not support windows-style paths.

I recommend you detect the windows environment and manage this conversion yourself:

// whether the environment is windows
const isWin = process.platform === 'win32'

// returns a windows-style path converted into a posix-style path
const win2pos = win32path => win32path.replace(/^(\w+):|\\/g, '/$1')

// returns any path conditionally converted into a posix-style path
const all2pos = anypath => isWin ? win2pos(anypath) : anypath

// becomes "/Users/THX1138/images/../files"
all2pos('/Users/THX1138/images/../files')

// becomes "/C/Users/THX1138/images/../files"
all2pos('C:\\Users\\THX1138\\images\\..\\files')

Keywords

FAQs

Last updated on 08 Oct 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc