load-helpers
Advanced tools
Comparing version 0.2.10 to 0.2.11
35
index.js
@@ -10,5 +10,6 @@ /*! | ||
var util = require('util'); | ||
var utils = require('./utils'); | ||
module.exports = function (cache, options) { | ||
module.exports = function(cache, options) { | ||
options = options || {}; | ||
@@ -25,5 +26,7 @@ cache = cache || {}; | ||
} | ||
if (utils.isObject(key)) { | ||
return addHelpers(key, val); | ||
} | ||
val = val || {}; | ||
@@ -40,6 +43,10 @@ key = utils.arrayify(key); | ||
function addHelper(name, fn) { | ||
var fn = typeof fn === 'string' | ||
? utils.tryRequire(fn) | ||
: fn; | ||
if (typeof fn === 'string') { | ||
fn = utils.tryRequire(fn); | ||
} | ||
if (typeof fn !== 'function' && !utils.isObject(fn)) { | ||
throw new TypeError('expected a function or object'); | ||
} | ||
if (options.async === true) { | ||
@@ -54,8 +61,22 @@ fn.async = true; | ||
if (Array.isArray(helpers) && helpers.length) { | ||
helpers.forEach(function (helper) { | ||
helpers.forEach(function(helper) { | ||
loadHelpers(helper, opts); | ||
}); | ||
} else { | ||
} else if (utils.isObject(helpers)) { | ||
for (var name in helpers) { | ||
addHelper(name, helpers[name]); | ||
var helper = helpers[name]; | ||
if (typeof helper === 'function') { | ||
addHelper(name, helper); | ||
} else if (utils.isObject(helper)) { | ||
addHelpers(helper, opts); | ||
} else if (typeof helper === 'string') { | ||
addHelper(name, utils.tryRequire(helper)); | ||
} else if (Array.isArray(helper)) { | ||
var obj = {}; | ||
obj[name] = {}; | ||
helper.forEach(function(val) { | ||
utils.extend(obj[name], loadHelpers(val, opts)); | ||
}); | ||
utils.extend(cache, obj); | ||
} | ||
} | ||
@@ -62,0 +83,0 @@ } |
{ | ||
"name": "load-helpers", | ||
"description": "Load helpers with patterns, as an object, key-value pair, or module.", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"homepage": "https://github.com/jonschlinkert/load-helpers", | ||
@@ -24,15 +24,15 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"extend-shallow": "^2.0.1", | ||
"is-valid-glob": "^0.3.0", | ||
"lazy-cache": "^0.2.3", | ||
"matched": "^0.3.2", | ||
"lazy-cache": "^2.0.1", | ||
"matched": "^0.4.1", | ||
"resolve-dir": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.9.0", | ||
"gulp-istanbul": "^0.10.0", | ||
"gulp-jshint": "^1.11.2", | ||
"gulp-mocha": "^2.1.3", | ||
"jshint-stylish": "^2.0.1", | ||
"mocha": "*", | ||
"should": "*" | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-istanbul": "^0.10.4", | ||
"gulp-mocha": "^2.2.0", | ||
"mocha": "^2.5.3", | ||
"should": "^9.0.0" | ||
}, | ||
@@ -55,5 +55,5 @@ "keywords": [ | ||
"list": [ | ||
"handlebars-helpers", | ||
"helper-cache", | ||
"template-helpers", | ||
"handlebars-helpers" | ||
"template-helpers" | ||
] | ||
@@ -60,0 +60,0 @@ } |
15
utils.js
@@ -5,2 +5,6 @@ 'use strict'; | ||
var utils = require('lazy-cache')(require); | ||
var fn = require; | ||
require = utils; | ||
/** | ||
@@ -10,9 +14,6 @@ * Lazily required module dependencies | ||
var utils = require('lazy-cache')(require); | ||
var fn = require; | ||
require = utils; | ||
require('extend-shallow', 'extend'); | ||
require('is-valid-glob', 'isGlob'); | ||
require('matched', 'glob'); | ||
require('resolve-dir'); | ||
require('is-valid-glob', 'isGlob'); | ||
require = fn; | ||
@@ -30,3 +31,3 @@ | ||
return require(name); | ||
} catch(err) {} | ||
} catch (err) {} | ||
@@ -36,3 +37,3 @@ // try to require by absolute path | ||
return require(utils.resolve(name, opts)); | ||
} catch(err) {} | ||
} catch (err) {} | ||
return null; | ||
@@ -39,0 +40,0 @@ }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6
140
0
6097
5
4
1
0
+ Addedextend-shallow@^2.0.1
+ Addedarr-union@3.1.0(transitive)
+ Addedasync-array-reduce@0.2.1(transitive)
+ Addedfs-exists-sync@0.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-glob@0.1.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@2.0.2(transitive)
+ Addedmatched@0.4.4(transitive)
+ Addedset-getter@0.1.1(transitive)
+ Addedto-object-path@0.3.0(transitive)
- Removedasync-array-reduce@0.1.0(transitive)
- Removedglob@5.0.15(transitive)
- Removedlazy-cache@0.2.7(transitive)
- Removedmatched@0.3.2(transitive)
Updatedlazy-cache@^2.0.1
Updatedmatched@^0.4.1