Socket
Socket
Sign inDemoInstall

structural-sharing

Package Overview
Dependencies
62
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    structural-sharing

Tests whether two objects (recursively) have structural sharing. In other words, whether they access a common memory location. If the exported method *shareMemory* returns *false* then each of the objects can be modified, anywhere in its graph, without af


Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

js-structural-sharing

Tests whether two objects (recursively) have structural sharing. In other words, whether they access a common memory location. If the exported method shareMemory returns false then each of the objects can be modified, anywhere in its graph, without affecting the other.

Installation

npm install structural-sharing --save

Usage


  import {shareMemory} from 'structural-sharing'

Examples


   import {shareMemory} from 'structural-sharing'
   const o = {};
   const a1 = {a1: {a2: {v:1, y:2}, a3: o}, a4: [1,2,3,4]};
   const a2 = {a1: {a2: [1, 2,3, [1, 3, [1, 2, o]]]}, a4: [1,2,3,4]};           
   assert.isTrue(shareMemory(o, a1));
   assert.isTrue(shareMemory(o, a2));
   assert.isTrue(shareMemory(a1, a2));
   assert.isFalse(shareMemory(a1, JSON.parse(JSON.stringify(a2))));   

For more examples look in file test.js

Tests

npm test

Keywords

FAQs

Last updated on 21 Dec 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc