Comparing version 9.7.2 to 9.8.0
{ | ||
"name": "utilsac", | ||
"version": "9.7.2", | ||
"version": "9.8.0", | ||
"description": "Utility functions", | ||
@@ -5,0 +5,0 @@ "main": "files.js", |
@@ -27,3 +27,4 @@ # Utility functions | ||
deepCopy, | ||
deepAssign | ||
deepAssign, | ||
createTemplateTag | ||
} from "path.../utility.js"; | ||
@@ -30,0 +31,0 @@ ``` |
export { | ||
createDebounced, | ||
createThrottled, | ||
throttledWithLast, | ||
throttledWithLast, | ||
createThrottledUsingTimeout, | ||
@@ -16,3 +16,4 @@ createCustomRound, | ||
deepCopy, | ||
deepAssign | ||
deepAssign, | ||
createTemplateTag | ||
}; | ||
@@ -61,22 +62,22 @@ | ||
calling it very often during a period less than minimumTimeSpace will only execute it twice: | ||
the first and last call | ||
The last call is always eventually executed | ||
the first and last call | ||
The last call is always eventually executed | ||
the returned function always returns undefined */ | ||
let timeOutId = 0; | ||
let timeOutId = 0; | ||
let lastTime = Number.MIN_SAFE_INTEGER; | ||
return function(...args) { | ||
const now = Date.now(); | ||
const timeAlreadyWaited = now - lastTime; | ||
const timeAlreadyWaited = now - lastTime; | ||
if (timeOutId !== 0) { | ||
clearTimeout(timeOutId); | ||
timeOutId = 0; | ||
timeOutId = 0; | ||
} | ||
if (minimumTimeSpace > timeAlreadyWaited) { | ||
timeOutId = setTimeout(function () { | ||
timeOutId = 0; | ||
lastTime = now; | ||
functionToThrottle(...args); | ||
}, waitTime - timeAlreadyWaited); | ||
timeOutId = setTimeout(function () { | ||
timeOutId = 0; | ||
lastTime = now; | ||
functionToThrottle(...args); | ||
}, waitTime - timeAlreadyWaited); | ||
return; | ||
@@ -134,5 +135,4 @@ } | ||
/* [].fill is for static values only | ||
alternative , return Array.from({length: times}, aFunction); | ||
same if aFunction ignores its second argument */ | ||
alternative , return Array.from({length: times}, aFunction); | ||
same if aFunction ignores its second argument */ | ||
const array = []; | ||
@@ -255,3 +255,3 @@ for (let i = 0; i < times; i += 1) { | ||
const previousResults = {}; | ||
const previousResults = {}; | ||
return function (...args) { | ||
@@ -328,1 +328,16 @@ const argumentsAsStrings = args.map(String).join(separator); | ||
}; | ||
const createTemplateTag = (mapper) => { | ||
/* creates a template tag function | ||
that will map the provided function on all runtime values | ||
before constructing the string | ||
example: | ||
const createURLString = createTemplateTag(encodeURIComponent) | ||
createURLString`https://example.com/id/${`slashes and spaces are properly escaped ///`}`; | ||
// -> "https://example.com/id/slashes%20and%20spaces%20are%20properly%20escaped%20%2F%2F%2F" */ | ||
return (staticStrings, ...parts) => { | ||
return Array.from(parts, (part, index) => { | ||
return `${staticStrings[index]}${mapper(part)}` | ||
}).concat(staticStrings[staticStrings.length - 1]).join(``); | ||
}; | ||
}; |
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
27944
14
571
86