🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

utilsac

Package Overview
Dependencies
Maintainers
1
Versions
74
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

to
5.5.0

2

package.json
{
"name": "utilsac",
"version": "5.4.1",
"version": "5.5.0",
"description": "tools mostly",

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

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

timeCallback,
timePromise
timePromise,
memoizeAsStrings
} from "path.../utility.js";

@@ -39,0 +40,0 @@ ```

@@ -10,3 +10,4 @@ export {

timeCallback,
timePromise
timePromise,
memoizeAsStrings
};

@@ -173,1 +174,27 @@

};
const memoizeAsStrings = function (functionToMemoize) {
/*
todo explain better the limitations and benefits of this approach
joins together the args as strings to compare
false possible cache hits when "-" is inside the string
*/
const separator = "-";
const previousResults = {};
return function (...args) {
const argumentsAsStrings = args.map(String).join(separator);
/*
without .map(String) works but undefined and null become empty strings
const argumentsAsStrings = args.join(separator);
*/
if (Object.prototype.hasOwnProperty.call(previousResults, argumentsAsStrings)) {
// cache hit
return previousResults[argumentsAsStrings];
}
// not yet in cache
const result = functionToMemoize(...args);
// add it for later
previousResults[argumentsAsStrings] = result;
return result;
};
};