Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,3 @@ { | ||
"description": "Throttle a function", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"keywords": [], | ||
@@ -14,2 +14,2 @@ "dependencies": {}, | ||
] | ||
} | ||
} |
40
index.js
module.exports = function(fn, ms){ | ||
var ok = true; | ||
return function(){ | ||
if (!ok) return; | ||
/** | ||
* Module exports. | ||
*/ | ||
// invoke | ||
fn.apply(this, arguments); | ||
module.exports = throttle; | ||
// timeout | ||
ok = false; | ||
setTimeout(function(){ | ||
ok = true; | ||
}, ms); | ||
} | ||
}; | ||
/** | ||
* Returns a new function that, when invoked, invokes `func` at most one time per | ||
* `wait` milliseconds. | ||
* | ||
* @param {Function} func The `Function` instance to wrap. | ||
* @param {Number} wait The minimum number of milliseconds that must elapse in between `func` invokations. | ||
* @return {Function} A new function that wraps the `func` function passed in. | ||
* @api public | ||
*/ | ||
function throttle (func, wait) { | ||
var rtn; // return value | ||
var last = 0; // last invokation timestamp | ||
return function throttled () { | ||
var now = new Date().getTime(); | ||
var delta = now - last; | ||
if (delta >= wait) { | ||
rtn = func.apply(this, arguments); | ||
last = now; | ||
} | ||
return rtn; | ||
}; | ||
} |
{ | ||
"name": "throttleit", | ||
"description": "Throttle a function", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"keywords": [], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/component/throttle.git" | ||
}, | ||
"dependencies": {}, | ||
@@ -7,0 +11,0 @@ "development": {}, |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2018
49
0
1