Socket
Socket
Sign inDemoInstall

immutability-helper-x

Package Overview
Dependencies
4
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    immutability-helper-x

expand the immutability-helper, to support update by path string, like the get/set in lodash


Version published
Weekly downloads
15
increased by114.29%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

immutability-helper-x

The library extends the kolodny/immutability-helper to support update by path string, like the get/set in lodash.

Build Status Coverage Status npm

install

npm install -S immutability-helper-x

usage

import update, { updateChain } from 'immutability-helper-x';

const data = {
  a: {
    b: {
      c: 1,
      d: 2,
      e: [3, 2, 1],
    }
  },
  f: 4,
};

// 1. if you want to update the value of data.a.b, you can
update.$set(data, 'a.b', newValue);
// or
update.$set(data, ['a', 'b'], newValue);

// 2. other methods like push and apply in original update lib
update.$push(data, 'arr', ['car', 'bus']);
update.$apply(data, 'a.b', value => ++value);

// 3. extend method
// step 1
update.extend('$addtax', function(tax, original) {
  return original + (tax * original);
});
// step 2
update.$addtax(data, 'price', 0.8);
// or
update(data, {
  price: { $addtax: 0.8 },
});

// 4. update multiple values at the same time in a chain
const d = updateChain(data)
  .$set('a.b.c', 444)
  .$merge('a.b', {
    d: 555,
  })
  .$push('a.e', [4])
  .$unshift('a.e', [0])
  .$splice('a.e', [[1, 0, 8]])
  .$apply('a.b.d', val => val + 100)
  .value();

Keywords

FAQs

Last updated on 27 Sep 2017

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