Gathering detailed insights and metrics for require-glob
Gathering detailed insights and metrics for require-glob
Gathering detailed insights and metrics for require-glob
Gathering detailed insights and metrics for require-glob
Requires multiple modules using glob patterns and combines them into a nested object.
npm install require-glob
Typescript
Module System
Min. Node Version
Node Version
NPM Version
96.4
Supply Chain
100
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
7,569,141
Last Day
661
Last Week
17,120
Last Month
80,874
Last Year
1,084,736
MIT License
21 Stars
87 Commits
2 Watchers
2 Branches
3 Contributors
Updated on Nov 03, 2021
Minified
Minified + Gzipped
Latest Version
4.1.0
Package Id
require-glob@4.1.0
Unpacked Size
18.80 kB
Size
6.13 kB
File Count
20
NPM Version
8.1.2
Node Version
16.13.2
Cumulative downloads
Total Downloads
Last Day
28.1%
661
Compared to previous day
Last Week
-5.7%
17,120
Compared to previous week
Last Month
-6.4%
80,874
Compared to previous month
Last Year
-0.9%
1,084,736
Compared to previous year
3
require-glob
Requires multiple modules using glob patterns and combines them into a nested object.
$ npm install --save require-glob
┣━ unicorn.js
┣━ cake.js
┗━ rainbow/
┣━ red-orange.js
┣━ _yellow_green.js
┗━ BluePurple.js
1var requireGlob = require('require-glob'); 2 3requireGlob(['**/*.js', '!cake.js']).then(function (modules) { 4 console.log(modules); 5 // { 6 // unicorn: [object Object], 7 // rainbow: { 8 // redOrange: [object Object], 9 // _yellow_green: [object Object], 10 // BluePurple: [object Object] 11 // } 12 // } 13});
Returns a promise that resolves to an object containing the required contents of matching globbed files.
Returns an object containing the required contents of matching globbed files.
Type: {String|Array.<String>}
One or more minimatch
glob patterns patterns. Supports negation.
Type: {Object}
(optional)
This object is ultimately passed directly to node-glob
so check there for more options, in addition to those below.
Type: {String}
(default: __dirname
)
The current working directory in which to search. Defaults to the __dirname
of the requiring module so relative paths work the same as Node.js's require.
Type: {String}
(default: common non-glob parent)
Default is everything before the first glob starts in the first pattern (see glob-parent
).
This option has no effect if you define your own mapper
function.
1requireGlob(['./src/**', './lib/**'], { cwd: '/home/jdoe/my-module' });
2// base is: /home/jdoe/my-module/src
3
4requireGlob('./{src,lib}/**', { cwd: '/home/jdoe/my-module' });
5// base is: /home/jdoe/my-module
Type: {Boolean}
(default: false
)
Whether to force the reload of modules by deleting them from the cache. Useful inside watch tasks.
This option has no effect if you define your own mapper
function.
Type: {Function(options, filePath, i, filePaths) : Object}
The mapper is reponsible for requiring the globbed modules. The default mapper returns an object containing path information and the result of requiring the module.
1// file: /home/jdoe/my-module/index.js 2requireGlob('./src/**/*.js'); 3 4// the resulting list of files 5[ 6 './src/unicorn.js', 7 './src/rainbow/red-orange.js', 8 './src/rainbow/_yellow_green.js', 9 './src/rainbow/BluePurple.js', 10] 11 12// will be mapped to 13[ 14 { 15 cwd: '/home/jdoe/my-module', 16 base: '/home/jdoe/my-module/src', 17 path: '/home/jdoe/my-module/src/unicorn.js', 18 exports: require('./src/unicorn') 19 }, 20 { 21 cwd: '/home/jdoe/my-module', 22 base: '/home/jdoe/my-module/src', 23 path: '/home/jdoe/my-module/src/rainbow/red-orange.js', 24 exports: require('./src/rainbow/red-orange') 25 }, 26 { 27 cwd: '/home/jdoe/my-module', 28 base: '/home/jdoe/my-module/src', 29 path: '/home/jdoe/my-module/src/rainbow/_yellow_green.js', 30 exports: require('./src/rainbow/_yellow_green') 31 }, 32 { 33 cwd: '/home/jdoe/my-module', 34 base: '/home/jdoe/my-module/src', 35 path: '/home/jdoe/my-module/src/rainbow/BluePurple.js', 36 exports: require('./src/rainbow/BluePurple') 37 } 38]
Type: {Function(options, result, fileObject, i, fileObjects): Object}
The reducer is responsible for generating the final object structure. The default reducer expects an array as produced by the default mapper and turns it into a nested object. Path separators determine object nesting. Directory names and file names are converted to camelCase
. File extensions are ignored.
1// mapper example is reduced to 2 3{ 4 unicorn: require('./src/unicorn.js'), 5 rainbow: { 6 redOrange: require('./src/rainbow/red-orange.js'), 7 _yellow_green: require('./src/rainbow/_yellow_green.js'), 8 BluePurple: require('./src/rainbow/BluePurple.js'), 9 } 10}
Type: {any}
(default: {}
)
The initial value passed to the reducer. The default is an empty object, as expected by the default reducer.
1// file: /home/jdoe/my-module/index.js 2const defaultDependencies = { 3 clover: require('clover'), 4 unicorn: require('unicorn'), 5}; 6 7requireGlob('./src/**/*.js', { 8 initialValue: defaultDependencies, 9}); 10 11// reducer example is changed to 12{ 13 clover: require('clover'), 14 unicorn: require('./src/unicorn.js'), 15 rainbow: { 16 redOrange: require('./src/rainbow/red-orange.js'), 17 _yellow_green: require('./src/rainbow/_yellow_green.js'), 18 BluePurple: require('./src/rainbow/BluePurple.js'), 19 } 20}
Type: {Function(options, fileObj): String|Array.<String>}
The default reducer uses this function to generate a unique key path for every module. The default keygen converts hyphenated and dot-separated sections of directory names and the file name to camelCase
. File extensions are ignored. Path separators determine object nesting.
This option has no effect if you define your own reducer
function.
1// given the mapped object 2{ 3 cwd: '/home/jdoe/my-module', 4 base: '/home/jdoe/my-module/src', 5 path: '/home/jdoe/my-module/src/fooBar/bar-baz/_bat.qux.js', 6 exports: require('./src/fooBar/bar-baz/_bat.qux.js') 7} 8 9// the keygen will produce 10[ 11 'fooBar', 12 'barBaz', 13 '_batQux' 14] 15 16// which the reducer will use to construct 17{ 18 fooBar: { 19 barBaz: { 20 _batQux: require('./src/fooBar/bar-baz/_bat.qux.js') 21 } 22 } 23}
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
$ npm test
MIT © Shannon Moeller
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 3/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moreglobal
Require global variables
babel-plugin-require-glob
Babel plugin which gives you ability to require globs.
require-glob-array
`require` node modules and place their exported values in an array
glob-require
Use glob to find and call `require` on all matching files in a directory tree.