Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utilsac

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utilsac - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

2

package.json
{
"name": "utilsac",
"version": "5.0.0",
"version": "5.1.0",
"description": "tools mostly",

@@ -5,0 +5,0 @@ "main": "files.js",

@@ -17,3 +17,4 @@ # Utilities and random js files

```
export {
import {
createDebouncedFunction,
createThrottledFunction,

@@ -27,3 +28,16 @@ createCustomRound,

timePromise
};
```
} from "path.../utility.js";
```
## About
### License
[CC0](license.txt)
### Related
* [fnk](https://github.com/seanohue/fnk)
* jQuery
* lodash
* ramda
export {
createDebouncedFunction,
createThrottledFunction,

@@ -12,8 +13,32 @@ createCustomRound,

const createDebouncedFunction = function (functionToDebounce, waitTime) {
/* creates a function that is de-bounced,
calling it, will eventually execute it, when you stop calling it
useful for scroll events, resize, search etc
the returned function always return undefined
TODO is debounced the correct word ?
*/
let timeOutId = 0;
return function(...args) {
if (timeOutId > 0) {
clearTimeout(timeOutId);
timeOutId = 0;
}
timeOutId = setTimeout(function () {
functionToDebounce(...args);
}, waitTime);
};
};
const createThrottledFunction = function (functionToThrottle, minimumTimeSpace) {
/* creates a function that is throttled,
calling it once will execute it immediately
calling it very often during a period less than minimumTimeSpace will only execute it once
the returned function always return undefined
an alternative implementation could use Date.now() , this means less performance
but would work for throttling inside a single tick
but would work for throttling inside a single long tick
*/

@@ -25,7 +50,8 @@ let ready = true;

return function(...args) {
if (ready) {
ready = false;
functionToThrottle(...args);
setTimeout(makeReady, minimumTimeSpace);
if (!ready) {
return;
}
ready = false;
functionToThrottle(...args);
setTimeout(makeReady, minimumTimeSpace);
};

@@ -46,12 +72,10 @@ };

return function (anyNumber) {
const rest = anyNumber % precision;
const rest = anyNumber % precision;
if (rest === 0) {
return anyNumber;
} else {
if (rest > halfPrecision) {
return anyNumber + (precision - rest);
} else {
return anyNumber - rest;
}
}
if (rest > halfPrecision) {
return anyNumber + (precision - rest);
}
return anyNumber - rest;
};

@@ -58,0 +82,0 @@ };

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