helper-cache
Advanced tools
Comparing version 0.1.2 to 0.1.4
65
index.js
@@ -14,2 +14,22 @@ /*! | ||
/** | ||
* Utility method to define getters. | ||
* | ||
* @param {Object} `obj` | ||
* @param {String} `name` | ||
* @param {Function} `getter` | ||
* @return {Getter} | ||
* @api private | ||
*/ | ||
function defineGetter(obj, name, getter) { | ||
Object.defineProperty(obj, name, { | ||
configurable: false, | ||
enumerable: false, | ||
get: getter, | ||
set: function() {} | ||
}); | ||
} | ||
/** | ||
* ```js | ||
@@ -26,3 +46,10 @@ * var Helpers = require('helper-cache'); | ||
function Helpers (options) { | ||
this.options = options || {bindFunctions: false}; | ||
if (!(this instanceof Helpers)) { | ||
return new Helpers(options); | ||
} | ||
options = options || {bindFunctions: false}; | ||
defineGetter(this, 'options', function () { | ||
return options; | ||
}); | ||
} | ||
@@ -39,14 +66,16 @@ | ||
Helpers.prototype.set = function(key, fn) { | ||
if (typeof key !== 'string') { | ||
this.keyend(key); | ||
} else { | ||
if (this.options.bindFunctions) { | ||
this[key] = _.bind(fn, this); | ||
defineGetter(Helpers.prototype, 'set', function () { | ||
return function (key, fn, thisArg) { | ||
if (typeof key !== 'string') { | ||
_.extend(this, key); | ||
} else { | ||
this[key] = fn; | ||
if (this.options.bindFunctions) { | ||
this[key] = _.bind(fn, thisArg || this); | ||
} else { | ||
this[key] = fn; | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
return this; | ||
}.bind(this); | ||
}); | ||
@@ -62,10 +91,12 @@ | ||
Helpers.prototype.get = function(key) { | ||
if (!key) { | ||
return this; | ||
} | ||
return this[key]; | ||
}; | ||
defineGetter(Helpers.prototype, 'get', function () { | ||
return function(key) { | ||
if (!key) { | ||
return this; | ||
} | ||
return this[key]; | ||
}.bind(this); | ||
}); | ||
module.exports = Helpers; |
{ | ||
"name": "helper-cache", | ||
"description": "Easily get and set helper functions to pass to any application or template engine.", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/jonschlinkert/helper-cache", | ||
@@ -38,10 +38,6 @@ "author": { | ||
"keywords": [ | ||
"docs", | ||
"documentation", | ||
"generate", | ||
"generator", | ||
"markdown", | ||
"templates", | ||
"verb" | ||
"cache", | ||
"helpers", | ||
"helper" | ||
] | ||
} |
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
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
9288
11
137
1