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

glob-var

v1.0.3

Published

extends glob with named variables

Downloads

88

Readme

glob-var

extends glob with named variables.

why?

use it when you want to transform the glob filename Array. it is used in glob-resolve.

how does it work?

  • variables start with a colon (like e.g. express.js routes variables)
  • the variables are then replaced with a star: * e.g. fixtures/:module/public turns into -> fixtures/*/public or fixtures/:module/public/:rest* turns into -> fixtures/*/public/**
  • therefore globstar works as well (but only one globstar is allowed in the pattern right now)
  • instead of the glob filename Array, glob-var returns a search object with:
    • paths: glob filename Array
    • values: Array with variable key:value pair objects

install

npm install glob-var

use


var glob = require('glob-var');

// async
glob(__dirname + '/fixtures/:module/public', function(err, search) {
    
    // -> search output:
    search == { pattern: 'fixtures/:module/public',
      glob: 'fixtures/*/public',
      globstars: 0,
      named: [ 'module' ],
      unnamed: [],
      vars: 
       [ { segment: ':module',
           compiled: '*',
           type: 'named',
           name: 'module',
           globstar: false,
           index: undefined } ],
      segments: 
       [ { segment: 'fixtures',
           compiled: 'fixtures',
           type: 'text',
           name: undefined,
           globstar: false,
           index: 0 },
         { segment: ':module',
           compiled: '*',
           type: 'named',
           name: 'module',
           globstar: false,
           index: undefined },
         { segment: 'public',
           compiled: 'public',
           type: 'text',
           name: undefined,
           globstar: false,
           index: 2 } ],
      paths: [ 'fixtures/Irish-Pub/public', 'fixtures/test_pub/public' ],
      values: [ { ':module': 'Irish-Pub' }, { ':module': 'test_pub' } ] 
    }
});
//or sync version
var search = glob.sync('fixtures/:module/public/:rest*');
search ==  { pattern: 'fixtures/:module/public/:rest*',
  glob: 'fixtures/*/public/**',
  globstars: 1,
  named: [ 'module', 'rest' ],
  unnamed: [],
  vars: 
   [ { segment: ':module',
       compiled: '*',
       type: 'named',
       name: 'module',
       globstar: false,
       index: undefined },
     { segment: ':rest*',
       compiled: '**',
       type: 'named',
       name: 'rest',
       globstar: true,
       index: 3 } ],
  segments: 
   [ { segment: 'fixtures',
       compiled: 'fixtures',
       type: 'text',
       name: undefined,
       globstar: false,
       index: 0 },
     { segment: ':module',
       compiled: '*',
       type: 'named',
       name: 'module',
       globstar: false,
       index: undefined },
     { segment: 'public',
       compiled: 'public',
       type: 'text',
       name: undefined,
       globstar: false,
       index: 2 },
     { segment: ':rest*',
       compiled: '**',
       type: 'named',
       name: 'rest',
       globstar: true,
       index: 3 } ],
  paths: 
   [ 'fixtures/Irish-Pub/public',
     'fixtures/Irish-Pub/public/css',
     'fixtures/Irish-Pub/public/css/bundle.css',
     'fixtures/Irish-Pub/public/css/style.css',
     'fixtures/Irish-Pub/public/js',
     'fixtures/Irish-Pub/public/js/bundle.ss',
     'fixtures/Irish-Pub/public/readme.md',
     'fixtures/test_pub/public',
     'fixtures/test_pub/public/css',
     'fixtures/test_pub/public/css/bundle.css',
     'fixtures/test_pub/public/css/style.css',
     'fixtures/test_pub/public/js',
     'fixtures/test_pub/public/js/bundle.ss',
     'fixtures/test_pub/public/readme.md' ],
  values: 
   [ { ':module': 'Irish-Pub', ':rest*': '' },
     { ':module': 'Irish-Pub', ':rest*': 'css' },
     { ':module': 'Irish-Pub', ':rest*': 'css/bundle.css' },
     { ':module': 'Irish-Pub', ':rest*': 'css/style.css' },
     { ':module': 'Irish-Pub', ':rest*': 'js' },
     { ':module': 'Irish-Pub', ':rest*': 'js/bundle.ss' },
     { ':module': 'Irish-Pub', ':rest*': 'readme.md' },
     { ':module': 'test_pub', ':rest*': '' },
     { ':module': 'test_pub', ':rest*': 'css' },
     { ':module': 'test_pub', ':rest*': 'css/bundle.css' },
     { ':module': 'test_pub', ':rest*': 'css/style.css' },
     { ':module': 'test_pub', ':rest*': 'js' },
     { ':module': 'test_pub', ':rest*': 'js/bundle.ss' },
     { ':module': 'test_pub', ':rest*': 'readme.md' } ] 
}

functions

glob(pattern [,options] ,callback)

async pendant of glob.

sync(pattern [,options])

glob's sync pendant.

hasMagic(pattern [,options])

glob's hasMagic function

extractVars(pattern)

returns the search object with these fields (example):

search =  { pattern: ':root/*/public',
  glob: '*/*/public',
  globstars: 0,
  named: [ 'root' ],
  unnamed: [ '*' ],
  vars: 
   [ { segment: ':root',
       compiled: '*',
       type: 'named',
       name: 'root',
       globstar: false,
       index: 0 },
     { segment: '*',
       compiled: '*',
       type: 'unnamed',
       name: '*',
       globstar: false,
       index: 1 } ],
  segments: 
   [ { segment: ':root',
       compiled: '*',
       type: 'named',
       name: 'root',
       globstar: false,
       index: 0 },
     { segment: '*',
       compiled: '*',
       type: 'unnamed',
       name: '*',
       globstar: false,
       index: 1 },
     { segment: 'public',
       compiled: 'public',
       type: 'text',
       name: undefined,
       globstar: false,
       index: 2 } ]
}

extractValues(search [,options] ,callback)

it runs the glob function and analyses the resulting filenames Array. it adds the paths and values arrays to the search objects. you can use this function after extractVars. glob(pattern [,options] ,callback) does this internally.

extractValuesSync(search [,options] ,callback)

same as extractValues but sync :-) sync(pattern [,options]) does this.

insertValues(pattern, values)

it inserts the values into the pattern.

test

npm test

license

MIT