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

globule

v1.3.4

Published

An easy-to-use wildcard globbing library.

Downloads

12,797,574

Readme

globule Build Status: Linux Build Status: Windows

An easy-to-use wildcard globbing library.

Getting Started

Install the module with: npm install globule

var globule = require('globule');
var filepaths = globule.find('**/*.js');

Documentation

globule.find

Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with ! will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant. Patterns may be specified as function arguments or as a src property of the options object.

globule.find(patterns [, patterns [, ...]] [, options])
globule.find({src: patterns, /* other options */})

The options object supports all glob library options, along with a few extras. These are the most commonly used:

  • src This property may be used instead of specifying patterns as function arguments.
  • filter Either a valid fs.Stats method name or a function that will be passed the matched src filepath and options object as arguments. This function should return a Boolean value.
  • nonull Retain globbing patterns in result set even if they fail to match files.
  • matchBase Patterns without slashes will match just the basename part. Eg. this makes *.js work like **/*.js.
  • srcBase Patterns will be matched relative to the specified path instead of the current working directory. This is a synonym for cwd.
  • prefixBase Any specified srcBase will be prefixed to all returned filepaths.

globule.match

Match one or more globbing patterns against one or more file paths. Returns a uniqued array of all file paths that match any of the specified globbing patterns. Both the patterns and filepaths arguments can be a single string or array of strings. Paths matching patterns that begin with ! will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.

globule.match(patterns, filepaths [, options])

globule.isMatch

This method contains the same signature and logic as the globule.match method, but returns true if any files were matched, otherwise false.

globule.isMatch(patterns, filepaths [, options])

globule.mapping

Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified. Patterns may be specified as function arguments or as a src property of the options object.

globule.mapping(filepaths [, filepaths [, ...]]  [, options])
globule.mapping({src: filepaths, /* other options */})

In addition to the options the globule.find method supports, the options object also supports these properties:

  • srcBase The directory from which patterns are matched. Any string specified as srcBase is effectively stripped from the beginning of all matched paths.
  • destBase The specified path is prefixed to all dest filepaths.
  • ext Remove anything after (and including) the first . in the destination path, then append this value.
  • extDot Change the behavior of ext, "first" and "last" will remove anything after the first or last . in the destination filename, respectively. Defaults to "first".
  • flatten Remove the path component from all matched src files. The src file path is still joined to the specified destBase.
  • rename If specified, this function will be responsible for returning the final dest filepath. By default, it flattens paths (if specified), changes extensions (if specified) and joins the matched path to the destBase.

globule.findMapping

This method is a convenience wrapper around the globule.find and globule.mapping methods.

globule.findMapping(patterns [, options])

Examples

Given the files foo/a.js and foo/b.js:

srcBase and destBase

globule.find("foo/*.js")
// ["foo/a.js", "foo/b.js"]

globule.find("*.js", {srcBase: "foo"})
// ["a.js", "b.js"]

globule.find({src: "*.js", srcBase: "foo", prefixBase: true})
// ["foo/a.js", "foo/b.js"]
globule.findMapping("foo/*.js")
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]

globule.findMapping("foo/*.js", {destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]

globule.findMapping({src: "*.js", srcBase: "foo", destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
globule.mapping(["foo/a.js", "foo/b.js"])
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]

globule.mapping(["foo/a.js", "foo/b.js"], {destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]

globule.mapping("foo/a.js", "foo/b.js", {destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]

globule.mapping(["a.js", "b.js"], {srcBase: "foo", destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]

globule.mapping({src: ["a.js", "b.js"], srcBase: "foo", destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

2018-05-29 - v1.2.1 - Update dependencies, [email protected] to avoid errant security warnings.
2017-06-10 - v1.2.0 - Update dependencies, [email protected].
2016-10-23 - v1.1.0 - Update dependencies, [email protected], [email protected].
2016-04-14 - v1.0.0 - Update dependencies, [email protected], [email protected], [email protected]. Paths are unix-style with prefixBase enabled.
2014-01-07 - v0.2.0 - Updated dependencies. Added src option. Improved exclusion speed significantly.
2013-04-11 - v0.1.0 - Initial release.

License

Copyright (c) 2018 "Cowboy" Ben Alman
Licensed under the MIT license.