Socket
Socket
Sign inDemoInstall

improx

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    improx

Immutable Object Mapping


Version published
Maintainers
1
Created

Readme

Source

improx

Use immutable proxy of an object to create its variant.

Install

npm install improx

Usage

import Impr from 'improx';

const data = {
    category1: {
        active: true,
        products: [
            { name: 'product21', active: false },
            { name: 'product22', active: true },
            { name: 'product23', active: true },
        ],
    },
    category2: {
        active: true,
        products: [
            { name: 'product31', active: true },
            { name: 'product32', active: true },
        ],
    },
};

const newData = Impr.of(data)
    .category1
    .products[0].active(true)
    .unwrap();

console.log(newData.category1);
// {
//     active: true,
//     products: [
//       { name: 'product21', active: true },
//       { name: 'product22', active: true },
//       { name: 'product23', active: true }
//     ]
// }
console.log(
    data === newData, // false
    data.category1 === newData.category1, // false
    data.category2 === newData.category2 // true
);

Usage with Ramda

npm install ramda

import Impr from 'improx';
import * as R from 'ramda';

// remove inactive products from category1
const newData = Impr.of(data)
    .category1
    .products(R.filter(R.prop('active')))
    .unwrap();

console.log(newData.category1);
// {
//     active: true,
//     products: [
//       { name: 'product22', active: true },
//       { name: 'product23', active: true }
//     ]
// }

Keywords

FAQs

Last updated on 26 Dec 2022

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