0.1.2 • Published 1 year ago

proxi-map v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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 }
//     ]
// }
0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago