@antfu/utils
Advanced tools
Comparing version 0.6.0 to 0.6.1
113
index.d.ts
@@ -383,11 +383,29 @@ /** | ||
// Type definitions for throttle-debounce 2.1 | ||
// Type definitions for throttle-debounce 5.0 | ||
interface CancelOptions { | ||
upcomingOnly?: boolean; | ||
} | ||
interface Cancel { | ||
cancel: () => void; | ||
cancel: (options?: CancelOptions) => void; | ||
} | ||
type throttle<T> = T & Cancel; | ||
interface NoReturn<T extends (...args: any[]) => any> { | ||
(...args: Parameters<T>): void; | ||
} | ||
interface ThrottleOptions { | ||
noTrailing?: boolean; | ||
noLeading?: boolean; | ||
debounceMode?: boolean; | ||
} | ||
interface DebounceOptions { | ||
atBegin?: boolean; | ||
} | ||
type throttle<T extends (...args: any[]) => any> = NoReturn<T> & Cancel; | ||
/** | ||
@@ -401,9 +419,2 @@ * Throttle execution of a function. Especially useful for rate limiting | ||
* | ||
* @param noTrailing | ||
* If noTrailing is true, callback will only execute every `delay` milliseconds | ||
* while the throttled-function is being called. If noTrailing is false or | ||
* unspecified, callback will be executed one final time fter the last | ||
* throttled-function call. (After the throttled-function has not been called | ||
* for `delay` milliseconds, the internal counter is reset) | ||
* | ||
* @param callback | ||
@@ -414,30 +425,19 @@ * A function to be executed after delay milliseconds. The `this` context and | ||
* | ||
* @param debounceMode If `debounceMode` is true (at begin), schedule | ||
* `callback` to execute after `delay` ms. If `debounceMode` is false (at end), | ||
* schedule `callback` to execute after `delay` ms. | ||
* @param options | ||
* An object to configure options. | ||
* | ||
* @return | ||
* A new, throttled, function. | ||
*/ | ||
declare function throttle<T extends (...args: any[]) => any>( | ||
delay: number, | ||
noTrailing: boolean, | ||
callback: T, | ||
debounceMode?: boolean | ||
): throttle<T>; | ||
/** | ||
* Throttle execution of a function. Especially useful for rate limiting | ||
* execution of handlers on events like resize and scroll. | ||
* @param options.noTrailing | ||
* Optional, defaults to false. If noTrailing is true, callback will only execute | ||
* every `delay` milliseconds while the throttled-function is being called. If | ||
* noTrailing is false or unspecified, callback will be executed one final time | ||
* after the last throttled-function call. (After the throttled-function has not | ||
* been called for `delay` milliseconds, the internal counter is reset) | ||
* | ||
* @param delay | ||
* A zero-or-greater delay in milliseconds. For event callbacks, values around | ||
* 100 or 250 (or even higher) are most useful. | ||
* @param options.noLeading | ||
* Optional, defaults to false. If noLeading is false, the first throttled-function | ||
* call will execute callback immediately. If noLeading is true, the first the | ||
* callback execution will be skipped. It should be noted that callback will never | ||
* executed if both noLeading = true and noTrailing = true. | ||
* | ||
* @param callback | ||
* A function to be executed after delay milliseconds. The `this` context and | ||
* all arguments are passed through, as-is, to `callback` when the | ||
* throttled-function is executed. | ||
* | ||
* @param debounceMode If `debounceMode` is true (at begin), schedule | ||
* @param options.debounceMode If `debounceMode` is true (at begin), schedule | ||
* `callback` to execute after `delay` ms. If `debounceMode` is false (at end), | ||
@@ -452,5 +452,5 @@ * schedule `callback` to execute after `delay` ms. | ||
callback: T, | ||
debounceMode?: boolean | ||
options?: ThrottleOptions, | ||
): throttle<T>; | ||
type debounce<T> = throttle<T>; | ||
type debounce<T extends (...args: any[]) => any> = NoReturn<T> & Cancel; | ||
@@ -466,9 +466,2 @@ /** | ||
* | ||
* @param atBegin | ||
* If atBegin is false or unspecified, callback will only be executed `delay` | ||
* milliseconds after the last debounced-function call. If atBegin is true, | ||
* callback will be executed only at the first debounced-function call. (After | ||
* the throttled-function has not been called for `delay` milliseconds, the | ||
* internal counter is reset). | ||
* | ||
* @param callback | ||
@@ -479,25 +472,12 @@ * A function to be executed after delay milliseconds. The `this` context and | ||
* | ||
* @return | ||
* A new, debounced function. | ||
*/ | ||
declare function debounce<T extends (...args: any[]) => any>( | ||
delay: number, | ||
atBegin: boolean, | ||
callback: T | ||
): debounce<T>; | ||
/** | ||
* Debounce execution of a function. Debouncing, unlike throttling, | ||
* guarantees that a function is only executed a single time, either at the | ||
* very beginning of a series of calls, or at the very end. | ||
* @param options | ||
* An object to configure options. | ||
* | ||
* @param delay | ||
* A zero-or-greater delay in milliseconds. For event callbacks, values around | ||
* 100 or 250 (or even higher) are most useful. | ||
* @param options.atBegin | ||
* If atBegin is false or unspecified, callback will only be executed `delay` | ||
* milliseconds after the last debounced-function call. If atBegin is true, | ||
* callback will be executed only at the first debounced-function call. (After | ||
* the throttled-function has not been called for `delay` milliseconds, the | ||
* internal counter is reset). | ||
* | ||
* @param callback | ||
* A function to be executed after delay milliseconds. The `this` context and | ||
* all arguments are passed through, as-is, to `callback` when the | ||
* debounced-function is executed. | ||
* | ||
* @return | ||
@@ -508,3 +488,4 @@ * A new, debounced function. | ||
delay: number, | ||
callback: T | ||
callback: T, | ||
options?: DebounceOptions, | ||
): debounce<T>; | ||
@@ -511,0 +492,0 @@ |
{ | ||
"name": "@antfu/utils", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"packageManager": "pnpm@7.0.1", | ||
"description": "Opinionated collection of common JavaScript / TypeScript utils by @antfu", | ||
"keywords": [ | ||
"utils" | ||
], | ||
"author": "Anthony Fu <anthonyfu117@hotmail.com>", | ||
"license": "MIT", | ||
"funding": "https://github.com/sponsors/antfu", | ||
"homepage": "https://github.com/antfu/utils#readme", | ||
"bugs": { | ||
"url": "https://github.com/antfu/utils/issues" | ||
}, | ||
"license": "MIT", | ||
"author": "Anthony Fu <anthonyfu117@hotmail.com>", | ||
"repository": { | ||
@@ -19,13 +14,19 @@ "type": "git", | ||
}, | ||
"funding": "https://github.com/sponsors/antfu", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "index.d.ts", | ||
"bugs": { | ||
"url": "https://github.com/antfu/utils/issues" | ||
}, | ||
"keywords": [ | ||
"utils" | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"types": "./index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"types": "./index.d.ts" | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "index.d.ts", | ||
"files": [ | ||
@@ -35,3 +36,2 @@ "dist", | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
@@ -48,4 +48,4 @@ "build": "rollup -c", | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^0.23.0", | ||
"@antfu/ni": "^0.16.2", | ||
"@antfu/eslint-config": "^0.27.0", | ||
"@antfu/ni": "^0.18.2", | ||
"@rollup/plugin-alias": "^3.1.9", | ||
@@ -55,16 +55,16 @@ "@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@types/node": "^17.0.31", | ||
"@types/throttle-debounce": "^2.1.0", | ||
"bumpp": "^7.1.1", | ||
"eslint": "^8.15.0", | ||
"esno": "^0.14.1", | ||
"@types/node": "^18.11.4", | ||
"@types/throttle-debounce": "^5.0.0", | ||
"bumpp": "^8.2.1", | ||
"eslint": "^8.26.0", | ||
"esno": "^0.16.3", | ||
"p-limit": "^4.0.0", | ||
"rollup": "^2.72.1", | ||
"rollup-plugin-dts": "^4.2.1", | ||
"rollup-plugin-esbuild": "^4.9.1", | ||
"throttle-debounce": "^3.0.1", | ||
"typescript": "^4.6.4", | ||
"vite": "^2.9.8", | ||
"vitest": "^0.12.3" | ||
"rollup-plugin-esbuild": "^4.10.1", | ||
"throttle-debounce": "^5.0.0", | ||
"typescript": "^4.8.4", | ||
"vite": "^3.1.8", | ||
"vitest": "^0.24.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
78339
2503