UNPKG

ninjs-lodash

Version:
25 lines (22 loc) 672 B
/** * Factory * Attempts to require a mod at src * src is anchored at root|cwd|prefix|. * * EXAMPLE : Get vhd module * Input : { root: "F:\\libs", src: "data/vhd" } * Output : require("F:\\libs\\data\\vhd") */ 'use strict' const _ = require('lodash') const path = require('path') exports = module.exports = function(root) { return function() { const args = _.toArray(arguments) if(root && _.isString(root)) args.unshift(root) const src = path.join.apply(path, args) const mod = src && _.isString(src) ? _.attempt(require, src) : null return mod && !_.isError(mod) ? mod : null } } _.mixin({ factory: exports })