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

globdule

v1.0.12

Published

ARCHIVED Provide a filename following a naming convention, receive a data object back.

Downloads

4

Readme

globdule

Provide a filename following naming convention, receive a data object back.

Installation

$ npm install globdule --save-dev

Why?

  • Configuring data in the filename is convenient, readable, fexible and saves the need for an additional data file.
  • Formalises a convention for creating custom filters that can be reused in future projects.
  • See gifle for an example of globdule being used in a project.

Usage

Feed a string representing a filename though a series of filters:

var globdule = require('globdule');

var data = globdule.feed('export-this-movie-20fps-250x300.mov').to('ext').to('fps').to('dims').to('leftoversToSlug').end();

Result:

{  
  ext: '.mov',
  fps: 20,
  width: 250,
  height: 300,
  slug: 'export-this-movie',
  _input: 'export-this-movie-20fps-250x300.mov',
  _leftovers: '' 
}

This example uses core filters that come with globdule, though often you'll be creating your own custom filters.

Filters

A filter is a function that that receives a |glob| string object and a |data| object. It can get info from the string and append it to the data object, then alter the string for use by future filters by extracting the portion from which it obtained data.

In this example the file extension is extracted from a filename:

var extFilter = function(glob, data){
	
	var arr = glob.split('.');
	if (arr.length === 1){
		return false;
	}
	
	data.ext = '.' + arr[arr.length - 1];
	
	return glob.substr(0, glob.length - data.ext.length);

};

If the filter opts to not process the string it returns false.

The filter can optionally be registered with an identifier for future use:

globdule.defineFilter('ext', extFilter);

Then the filter can be invoked referencing this identifier:

var dataA = globdule.feed('textDoc.txt').to('ext').end();
console.log(dataA);
var dataB = globdule.feed('someData.yml').to('ext').end();
console.log(dataB);

Result:

{ ext: '.txt', _input: 'textDoc.txt', _leftovers: 'textDoc' }
{ ext: '.yml', _input: 'someData.txt', _leftovers: 'someData' }

Alternately the filter function can be passed along without being registered first. This is useful for one-off filters:

var data = globdule.feed('textDoc.txt').to(extFilter).end();

Result:

{ ext: '.txt', _input: 'textDoc.txt', _leftovers: 'textDoc' }

Or declared anonymously as you go:

var data = globdule.feed('textDoc.txt').to(function(glob, data){
	
	var arr = glob.split('.');
	if (arr.length === 1){
		return false;
	}
	
	data.ext = '.' + arr[arr.length - 1];
	
	return glob.substr(0, glob.length - data.ext.length);

}).end();

Result:

{ ext: '.txt', _input: 'textDoc.txt', _leftovers: 'textDoc' }

Params

A filter can be registered with default params that inform the filtering function.

Eg:

var extFilter = function(glob, data, params){
	
	var arr = glob.split('.');
	if (arr.length === 1){
		return false;
	}
	
	data.ext = (params.includeDot ? '.' : '') + arr[arr.length - 1];
	
	return glob.substr(0, glob.length - data.ext.length);

};
globdule.defineFilter('ext', extFilter, {includeDot: true});

When invoking the filter you can include any params to override default values:

var data = globdule.feed('textDoc.txt').to('ext', {includeDot: false}).end();

Methods

filterExists(key)

Returns: boolean result if filter has already been registered.

Release History

  • v1.0.11 - Updated dependencies
  • v1.0.9 - Added 'preserveCase' param to 'leftoversToTextFilter'
  • v1.0.8 - Added 'preserveCase' param to 'leftoversToSlugFilter'
  • v1.0.7 – Added |filterExists| method