New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

proxy-memoize

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-memoize

Intuitive magical memoization library with Proxy and WeakMap

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is proxy-memoize?

The proxy-memoize package is a utility for creating memoized functions that use JavaScript Proxy objects to efficiently cache and retrieve computed values based on input arguments. It is particularly useful for optimizing performance in applications where functions are called frequently with the same inputs.

What are proxy-memoize's main functionalities?

Basic Memoization

This feature allows you to memoize a simple function, such as an addition function. The memoized function caches the result of the function call with specific arguments, so subsequent calls with the same arguments return the cached result, improving performance.

const memoize = require('proxy-memoize');

const add = (a, b) => a + b;
const memoizedAdd = memoize(add);

console.log(memoizedAdd(1, 2)); // 3
console.log(memoizedAdd(1, 2)); // 3, retrieved from cache

Deep Object Memoization

This feature demonstrates the ability to memoize functions that access deeply nested properties within objects. The proxy-memoize package efficiently tracks access to nested properties and caches results based on those accesses.

const memoize = require('proxy-memoize');

const getNestedValue = (obj) => obj.deep.nested.value;
const memoizedGetNestedValue = memoize(getNestedValue);

const obj = { deep: { nested: { value: 42 } } };
console.log(memoizedGetNestedValue(obj)); // 42
console.log(memoizedGetNestedValue(obj)); // 42, retrieved from cache

Other packages similar to proxy-memoize

Keywords

FAQs

Package last updated on 12 Jul 2024

Did you know?

Socket

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.

Install

Related posts

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