Socket
Socket
Sign inDemoInstall

es-toolkit

Package Overview
Dependencies
Maintainers
2
Versions
722
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-toolkit - npm Package Compare versions

Comparing version 1.2.2-dev.69 to 1.2.2-dev.70

dist/chunk-GOXQV6DX.mjs

19

dist/function/debounce.d.ts

@@ -0,1 +1,4 @@

interface DebounceOptions {
signal?: AbortSignal;
}
/**

@@ -8,2 +11,4 @@ * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds

* @param {number} debounceMs - The number of milliseconds to delay.
* @param {DebounceOptions} options - The options object.
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
* @returns {F & { cancel: () => void }} A new debounced function with a `cancel` method.

@@ -21,4 +26,16 @@ *

* debouncedFunction.cancel();
*
* // With AbortSignal
* const controller = new AbortController();
* const signal = controller.signal;
* const debouncedWithSignal = debounce(() => {
* console.log('Function executed');
* }, 1000, { signal });
*
* debouncedWithSignal();
*
* // Will cancel the debounced function call
* controller.abort();
*/
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number): F & {
declare function debounce<F extends (...args: any[]) => void>(func: F, debounceMs: number, { signal }?: DebounceOptions): F & {
cancel: () => void;

@@ -25,0 +42,0 @@ };

@@ -26,17 +26,27 @@ "use strict";

module.exports = __toCommonJS(debounce_exports);
function debounce(func, debounceMs) {
function debounce(func, debounceMs, { signal } = {}) {
let timeoutId = null;
const debounced = function(...args) {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
}
if (signal == null ? void 0 : signal.aborted) {
return;
}
timeoutId = setTimeout(() => {
func(...args);
timeoutId = null;
}, debounceMs);
};
const onAbort = function() {
debounced.cancel();
};
debounced.cancel = function() {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
};
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
return debounced;

@@ -43,0 +53,0 @@ }

@@ -31,17 +31,27 @@ "use strict";

// src/function/debounce.ts
function debounce(func, debounceMs) {
function debounce(func, debounceMs, { signal } = {}) {
let timeoutId = null;
const debounced = function(...args) {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
}
if (signal == null ? void 0 : signal.aborted) {
return;
}
timeoutId = setTimeout(() => {
func(...args);
timeoutId = null;
}, debounceMs);
};
const onAbort = function() {
debounced.cancel();
};
debounced.cancel = function() {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
};
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
return debounced;

@@ -48,0 +58,0 @@ }

@@ -338,17 +338,27 @@ "use strict";

// src/function/debounce.ts
function debounce(func, debounceMs) {
function debounce(func, debounceMs, { signal } = {}) {
let timeoutId = null;
const debounced = function(...args) {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
}
if (signal == null ? void 0 : signal.aborted) {
return;
}
timeoutId = setTimeout(() => {
func(...args);
timeoutId = null;
}, debounceMs);
};
const onAbort = function() {
debounced.cancel();
};
debounced.cancel = function() {
if (timeoutId != null) {
if (timeoutId !== null) {
clearTimeout(timeoutId);
timeoutId = null;
}
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
};
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
return debounced;

@@ -355,0 +365,0 @@ }

2

package.json
{
"name": "es-toolkit",
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
"version": "1.2.2-dev.69+fde86f7f",
"version": "1.2.2-dev.70+a707c06f",
"workspaces": [

@@ -6,0 +6,0 @@ "docs"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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