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

require-globify

v1.4.1

Published

transform for browserify, which allows to require files with globbing expressions

Downloads

17,077

Readme

require-globify

Build Status Build Status Dependency Status devDependency Status

Transform for browserify, which allows to require files with globbing expressions.

Installation

require-globify

Usage

browserify -t require-globify entry.js > bundle.js

Example

The transform is triggered by adding an additional parameter to the classic require() call.

// just expand to multiple require calls, one for each matched file
require('./includes/*.js', {mode: 'expand'});

// return an object that maps each matched path to it's require() call
var hash = require('./includes/*.js', {mode: 'hash'});

Interface

The second parameter to require must be an object and supports the following keys:

mode [required]

Possible values are

  • 'expand': replaces the call with multiple calls, one for each match.

This replaces the option glob: true in <1.2.0.

  • 'hash': replaces the call with an object.

Every matched file is represented by a key and it's respective require call as the value. The keys are generated by the resolver option. This replaces the option hash: true in <1.2.0.

  • 'list': replaces the call with an array.

Every matched file is represented by an object that contains two properties: + name which represents it's key. The keys are generated by the resolver option. + module which contains it's respective require call as the value.

  • function(base, files, config) { return "require(...)" }

You can provide a custom function. It takes the parameters base (the path of the file that is being transformed), files (an array that contains all the files matched by the glob, sorted on their full path) and config (the config object passed to the require call in the source file). If you believe your custom function is of general purpose to others, you can add a pull request for it.

  • You are very welcome to suggest other options by starting an issue!.

E.g. 'list' to return the require calls wrapped in an array, if you'd find a use-case for it :p

resolve [optional, default:["path-reduce", "strip-ext"]]

The list of functions to determine the key of a matched file. You can provide a single value, but you can also provide an array of these values. In the case an array is provided, the resolvers are executed in order to determine the final key.

Possible values are

  • 'path'

Every file uses it's relative path as its key. The relative path will always begin with either ../ or ./. On Windows, paths will be written unix-style (so \ will be replaced by /). This replaces the options hash: "path", ext: true in <1.2.0.

  • 'strip-ext'

Every file has it's extension removed, but only if it would not cause a duplicate key. This replaces the options ext: false in <1.2.0.

  • 'path-reduce'

Strips the common path from all matches. In most cases this will replace the options hash: true, ext: false in <1.2.0.

  • 'reduce-prefix'

Tries to reduce the key by determining the largest common prefix of each match and removing them from the matched filename.

  • 'reduce-postfix'

Tries to reduce the key by determining the largest common postfix of each match and removing them from the matched filename.

  • 'reduce'

Combination of reduce-prefix and reduce-postfix.

  • function(base, files, config) { return {"path": "key"} }

You can provide a custom function. It takes the parameters base (the path of the file that is being transformed), files (an object that contains all the files matched by the glob, using their full path as keys) and config (the config object passed to the require call in the source file). If you believe your custom function is of general purpose to others, you can add a pull request for it.

  • You are very welcome to suggest other options by starting an issue!.

options [optional, default:{}]

This allows options to be provided to node-glob, which is used internally to find matching files.

ext [deprecated, optional, default:false]

This option is replaced by resolve: 'strip-ext', but remains supported until version 2.0.0. WARNING: Backwards compatibility is not available in combination with the newer "resolve" option.

glob [deprecated]

This option is replaced by mode: 'expand', but remains supported until version 2.0.0

hash [deprecated]

This option is replaced by mode: 'hash' and resolve: ['path', 'strip-ext'], but remains supported until version 2.0.0

Credits

Original concept from Jiří špác, completely reimplemented by Adriaan Callaerts(@call-a3).
Hashing with paths implemented by Pat Collins(@patcoll).

License

MIT

Changelog

  • 1.2.1:
    • Fixed bugs #12, #13 and #14
    • Streamlined badges on README
  • 1.2.0: Complete overhaul of architecture, adding new features such as pass-through options for node-glob and multiple bugfixes.
  • 1.1.0: Added hashing with path.
  • 1.0.*: Bugfixes.
  • 1.0.0: Rewrite based on browserify-transform-tools.
  • 0.* : Base implementation by Jiří špác(@capaj).