Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
memoize-weak
Advanced tools
Garbage-collected memoizer for variadic functions
npm install memoize-weak
import memoize from 'memoize-weak';
let foo = { foo: true };
let bar = { bar: true };
let baz = { baz: true };
const fn = memoize((...args) => args); // Create a memoized function
fn(foo, bar, baz); // Returns [{ foo: true }, { bar: true }, { baz: true }]
fn(foo, bar, baz); // Returns cached result
foo = bar = baz = undefined; // Original foo, bar and baz are now eligible for garbage collection
memoize-weak
differ from other memoize implementations?Memoize functions cache the return value of a function, so that it can be used again without having to recalculate the value.
They do this by maintaining a cache of arguments that the function has previously been called with, in order to return results that correspond to an earlier set of arguments.
Usually this argument cache is retained indefinitely, or for a predefined duration after the original function call. This means that any objects passed as arguments are not eligible for garbage collection, even if all other references to these objects have been removed.
memoize-weak
uses "weak references" to the argument values, so that once all the references to the arguments have been removed elsewehere in the application, the arguments will become eligible for cleanup (along with any cached return values that correspond to those arguments).
This allows you to use memoized functions with impunity, without having to worry about potential memory leaks.
memoize-weak
in ES5 applicationsmemoize-weak
requires that Map
and WeakMap
are globally available. This means that these will have to be polyfilled for use in an ES5 environment.
Some examples of Map
and WeakMap
polyfills for ES5:
FAQs
Garbage-collected memoizer for variadic functions
The npm package memoize-weak receives a total of 40,890 weekly downloads. As such, memoize-weak popularity was classified as popular.
We found that memoize-weak demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.