Socket
Socket
Sign inDemoInstall

debounce-fn

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debounce-fn - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

license

59

index.js

@@ -1,23 +0,46 @@

module.exports = debounce;
'use strict';
const mimicFn = require('mimic-fn');
function debounce (fn, wait) {
var timer;
var args;
module.exports = (fn, options) => {
if (typeof fn !== 'function') {
throw new TypeError(`Expected the first argument to be a function, got \`${typeof fn}\``);
}
if (arguments.length == 1) {
wait = 250;
}
options = options || {};
return function () {
if (timer != undefined) {
clearTimeout(timer);
timer = undefined;
}
let timeout;
let result;
args = arguments;
const debounced = function () {
const context = this;
const args = arguments;
timer = setTimeout(function () {
fn.apply(undefined, args);
}, wait);
};
}
const later = () => {
timeout = null;
if (!options.immediate) {
result = fn.apply(context, args);
}
};
const callNow = options.immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, options.wait || 0);
if (callNow) {
result = fn.apply(context, args);
}
return result;
};
mimicFn(debounced, fn);
debounced.cancel = () => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};
return debounced;
};
{
"name": "debounce-fn",
"version": "0.1.0",
"description": "Return a debounced version of the given function",
"main": "index.js",
"version": "1.0.0",
"description": "Debounce a function",
"license": "MIT",
"repository": "sindresorhus/debounce-fn",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "node test"
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"debounce",
"debounced"
"function",
"debouncer",
"fn",
"func",
"throttle",
"delay",
"invoked"
],
"repository": {
"url": "git@github.com:azer/debounce-fn.git",
"type": "git"
"dependencies": {
"mimic-fn": "^1.1.0"
},
"author": "azer",
"license": "BSD",
"devDependencies": {
"prova": "^1.14.0"
"ava": "*",
"delay": "^2.0.0",
"xo": "*"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc