require-array

    0.1.4 • Public • Published

    require-array

    extend native require to handle array inputs based on node-resolve

    Example

    ⌘ tree example/
    example/
    ├── files
    │   ├── a.js
    │   ├── b.js
    │   └── exclude.js
    └── require.js
    

    require.js:

     
    var arequire = require('..');
     
    var mods = arequire(['path', './a.js'], { basedir: __dirname + '/files' })
     
    console.log(
        mods[0].basename('/path/to/a.js', '.js'),
        mods[1]
    );
     
    mods = arequire.glob(['*.js', '!exclude.js'], { cwd: __dirname + '/files' })
     
    console.log(
        mods
    );
     

    a.js:

    module.exports = 'a';

    b.js:

    module.exports = 'b';

    exclude.js:

    module.exports = 'exclude';

    output:

    ⌘ node example/require.js
    a a
    [ 'a', 'b' ]
    

    Usage

    arequire(mods, opts)

    arequire.resolve(mods, opts)

    Resolve the path to be required.

    arequire.glob(patterns, opts, resolveOpts)

    • patterns: String Array patterns to locate files by xglob
    • opts: Object Optional passed directly to xglob
    • resolveOpts: Object|Function Optional If Object, passed directly to node-resolve.sync. If Function, used to resolve the modules like node-resolve.sync

    arequire.glob.resolve(mods, opts, resolveOpts)

    Resolve the path to be required.

    Install

    npm i require-array

    DownloadsWeekly Downloads

    40

    Version

    0.1.4

    License

    MIT

    Last publish

    Collaborators

    • zoubin