Skip to content
Get executable file extensions as glob pattern or regular expression
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.jshintrc
.travis.yml
.verb.md
LICENSE
README.md
index.js
package.json

README.md

require-extensions Travis Coverage Status Downloads

Get the extensions of executable file names as glob pattern or regular expression

Install with npm

$ npm i require-extensions --save

Usage

require.extensions.glob             // -> '.{js,coffee}'      (String)
require.extensions.regexp           // -> /(?:\.js|\.coffee)/ (RegExp)
require.extensions.regexp_string    // -> '(?:\.js|\.coffee)' (String)
require('require-extensions');

var glob = require('glob');
var files = glob.sync("plugins/*" + require.extensions.glob);
// -> ['plugins/thisfile.js', 'plugins/thatfile.coffee', 'plugins/thisfile.litcoffee']

files[0].match(require.extensions.regexp);
// -> != null

Functions

glob

return a glob pattern for require.extensions

regexp

return a new RegExp object that matches require.extensions

regexp_string

return a new String regular expression that matches require.extensions

Motivation

Many libraries use a hardcoded .js string to discover executable file names, unfortunately leaving out other extensions that contain executable code such as .coffee, .litcoffee, and potentially others that are accessible through Node’s require.extensions property. By making this property accessible as a glob pattern and regular expression, it will become easier to use it as a search pattern and load code that was written in other languages or dialects.

Author

Andreas Pizsa

License

Copyright © 2016 Andreas Pizsa Released under the MIT license.


This file was generated by verb-cli on January 21, 2016.

You can’t perform that action at this time.