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

gex

v4.0.1

Published

Glob expressions for JavaScript

Downloads

48,022

Readme

gex

npm version Build Coverage Status DeepScan grade Maintainability Dependency Status

Glob expressions for JavaScript

"When regular expressions are just too hard!"

Match glob expressions using * and ? against any JavaScript data type. The character * means match anything of any length, the character ? means match exactly one of any character, and all other characters match themselves.

const { Gex } = require('gex')

Gex('a*').on( 'abc' ) // returns 'abc'
Gex('a*c').on( 'abbbc' ) // returns 'abbbc'
Gex('a?c').on( 'abc' ) // returns 'abc'

You can also match against objects and arrays:

Gex('a*').on( ['ab','zz','ac'] ) // returns ['ab','ac']
Gex('a*').on( {ab:1,zz:2,ac:3} ) // returns {ab:1,ac:3}

And also match against multiple globs:

Gex(['a*','b*']).on( 'bx' ) // returns 'bx'
Gex(['a*','b*']).on( ['ax','zz','bx'] ) // returns ['ax','bx']

One of the most useful things you can do with this library is quick assertions in unit tests. For example if your objects contain dates, randomly generated unique identifiers, or other data irrelevant for testing, Gex can help you ignore them when you use JSON.stringify:

var entity = {created: new Date().getTime(), name:'foo' }
assert.ok( Gex('{"created":*,"name":"foo"}').on( JSON.stringify(entity) ) )

If you need to use globbing on files, here's how apply a glob to a list of files in a folder:

var fs = require('fs')
fs.readdir('.',function(err,files){ 
  var pngs = Gex('*.png').on(files) 
})

And that's it!

Installation

npm install gex

And in your code:

const { Gex } = require('gex')

Or clone the git repository: git clone git://github.com/rjrodger/gex.git

This library depends on the excellent underscore module: underscore

Usage

The Gex object is a function that takes a single argument, the glob expression. This returns a Gex object that has only one function itself: on. The on function accepts any JavaScript data type, and operates as follows:

  • strings, numbers, booleans, dates, regexes: converted to string form for matching, returned as themselves
  • arrays: return a new array with all the elements that matched. Elements are not modified, but are converted to strings for matching. Does not recurse into elements.
  • objects: return a new object with with all the property names that matched. Values are copied by reference.
  • null, NAN, undefined: never match anything

Support

If you're using this library, feel free to contact me on twitter if you have any questions! :) @rjrodger

This module works on both Node.js and browsers.

License

Copyright (c) 2010-2020, Richard Rodger and other contributors. Licensed under MIT.