npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jsxtools/glob

v1.0.0

Published

convert glob patterns into regular expressions

Downloads

50

Readme

glob

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')