Socket
Socket
Sign inDemoInstall

proxi-map

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    proxi-map

Immutable object mapping


Version published
Maintainers
1
Install size
13.6 kB
Created

Readme

Source

proxi-map

npm version Build Status Coverage Status Known Vulnerabilities npm downloads/month

A lightweight JavaScript library to create variants of an object by using its immutable proxy.

Install

npm install proxi-map

Usage

import Imap from 'proxi-map';

const data = {
    category1: {
        activeProducts: 2,
        products: [
            { name: 'product11', active: false },
            { name: 'product12', active: true },
            { name: 'product13', active: true },
        ],
    },
    category2: {
        activeProducts: 2,
        products: [
            { name: 'product21', active: true },
            { name: 'product22', active: true },
        ],
    },
};

const newData = Imap(data)
    .category1
    .activeProducts(3)
    .backtrack(-1) // 1 step back
    .products[0].active(true)
    .unwrap();

console.log(newData.category1);
// {
//     activeProducts: 3,
//     products: [
//       { name: 'product11', active: true },
//       { name: 'product12', active: true },
//       { name: 'product13', active: true }
//     ]
// }
console.log(
    data == newData, // false
    data.category1 == newData.category1, // false
    data.category2 == newData.category2 // true
);

Usage with Ramda

npm install ramda

import Imap from 'proxi-map';
import * as R from 'ramda';

// remove inactive products from category1
const newData = Imap(data)
    .category1
    .products(R.filter(R.prop('active')))
    // equivalent to: (arr) => arr.filter(obj => obj.active)
    .unwrap();

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

Keywords

FAQs

Last updated on 28 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