lazy-cache
Advanced tools
Comparing version 1.0.0 to 1.0.1
15
index.js
@@ -15,2 +15,4 @@ 'use strict'; | ||
* @param {Function} `fn` Function that will be called only once. | ||
* @param {Object} `options` Options to determine how modules are cached. | ||
* @param {Boolean} `options.unlazy` When set to `true`, `fn` is called immediately. Defaults to `false`. | ||
* @return {Function} Function that can be called to get the cached function | ||
@@ -20,6 +22,11 @@ * @api public | ||
function lazyCache(fn) { | ||
function lazyCache(fn, opts) { | ||
opts = opts || {}; | ||
var cache = {}; | ||
var proxy = function (mod, name) { | ||
name = name || camelcase(mod); | ||
if (opts.unlazy === true) { | ||
cache[name] = fn(mod); | ||
} | ||
Object.defineProperty(proxy, name, { | ||
@@ -35,7 +42,3 @@ enumerable: true, | ||
} | ||
try { | ||
return (cache[name] = fn(mod)); | ||
} catch (err) { | ||
throw err; | ||
} | ||
return (cache[name] = fn(mod)); | ||
} | ||
@@ -42,0 +45,0 @@ return getter; |
{ | ||
"name": "lazy-cache", | ||
"description": "Cache requires to be lazy-loaded when needed.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/jonschlinkert/lazy-cache", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
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
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
6182
58