@a-type/utils
Advanced tools
Comparing version
export declare function assert(condition: any, message?: string): asserts condition; | ||
export declare function debounce<Fn extends (...args: any[]) => void>(callback: Fn, delay: number): Fn; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assert = void 0; | ||
exports.debounce = exports.assert = void 0; | ||
function assert(condition, message = 'assertion failed') { | ||
@@ -10,2 +10,15 @@ if (!condition) { | ||
exports.assert = assert; | ||
function debounce(callback, delay) { | ||
let timeout; | ||
return ((...args) => { | ||
if (timeout !== undefined) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(() => { | ||
timeout = undefined; | ||
callback(...args); | ||
}, delay); | ||
}); | ||
} | ||
exports.debounce = debounce; | ||
//# sourceMappingURL=index.js.map |
export declare function assert(condition: any, message?: string): asserts condition; | ||
export declare function debounce<Fn extends (...args: any[]) => void>(callback: Fn, delay: number): Fn; |
@@ -6,2 +6,14 @@ export function assert(condition, message = 'assertion failed') { | ||
} | ||
export function debounce(callback, delay) { | ||
let timeout; | ||
return ((...args) => { | ||
if (timeout !== undefined) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(() => { | ||
timeout = undefined; | ||
callback(...args); | ||
}, delay); | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@a-type/utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "access": "public", |
@@ -9,1 +9,17 @@ export function assert( | ||
} | ||
export function debounce<Fn extends (...args: any[]) => void>( | ||
callback: Fn, | ||
delay: number, | ||
): Fn { | ||
let timeout: NodeJS.Timeout | undefined; | ||
return ((...args) => { | ||
if (timeout !== undefined) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(() => { | ||
timeout = undefined; | ||
callback(...args); | ||
}, delay); | ||
}) as Fn; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4933
61.26%66
175%