New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

obj-reuse

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obj-reuse

Package which processes objects to reuse existing references when those are unchanged

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

obj-reuse

This package processes objects to reuse existing references when those are unchanged. It is useful when the data producer provides a new object for each update but the data consumer relies on shallow testing for optimization, such as React's memo function.

It has support for the following objects:

  • Array
  • Object (including objects with a null prototype)
  • Map (reusing the value only as it is impossible to tell which key was which)
  • Date
  • RegExp
  • URL

In the case of partial reuse, the new object provided as input is not used but a copy is created instead.

Installation

$ npm install obj-reuse

Usage

import reuse from 'obj-reuse';

let old = {
  foo: [5, 6],
  bar: 7
};

let updated = {
  foo: [5, 6],
  bar: 8
};

let result = reuse(updated, old);
// Here 'updated.foo' was left unchanged and thus reused, meaning 'result.foo === old.foo'

let result = reuse(updated, old, (updated, old) => {
  // Logic for custom reuse
  // ...

  // By default, skip reuse entirely
  return updated;
});

FAQs

Package last updated on 01 May 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