1.1.6 • Published 1 year ago

@abstracta/parter v1.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Introduction

Easily querry and apply changes to any json object. Example:

import {applyOption} from '@abstracta/parter';
// If you have an object like this
let p1 =         pc: {
            cooling: [
                [1, 2, 3],
                [4, 5, 6]
            ],
            gpu: [
                [{ speed: 1, freq: 3 }, { speed: 2, freq: 2 }],
                [{ speed: 4, freq: 4 }]
            ],
            ram: [
                {
                    size: 8,
                    type: "ddr5",
                    frequency: 3200,
                    cooling: {
                        type: "air",
                        model: "noctua"
                    },
                    pins: [
                        {
                            di: 1,
                            do: 2
                        },
                        {
                            di: 2,
                            do: 3
                        }
                    ]
                },
                {
                    size: 8,
                    type: "ddr6",
                    frequency: 3200,
                    pins: [
                        {
                            di: 1,
                            do: 2
                        }
                    ]
                }
            ]
        };
// And you would like to make a change to every ram property of object p1...
// Let's encapsulate this change as o1 (only as an example):
const o1 = { // Example object
            schema: 'myschema',
            mergeRoot: 'pc/ram/*',
            mergeResolver: ["FUN1"],
            payload: {
                cooling: {
                    type: "air",
                    model: "fan1"
                }
            }
        }

// After applying the option with applyOption
applyOption(p1, { path: o1.mergeRoot, payload: o1.payload });

// You should get the following result:
/*
pc: {
            cooling: [
                [1, 2, 3],
                [4, 5, 6]
            ],
           
           ... 

            ram: [
                {
                    size: 8,
                    type: "ddr5",
                    frequency: 3200,
                    cooling: { // CHANGED
                        type: "air",
                        model: "fan1"
                    },
                    pins: [
                        {
                            di: 1,
                            do: 2
                        },
                        {
                            di: 2,
                            do: 3
                        }
                    ]
                },
                {
                    size: 8,
                    type: "ddr6",
                    frequency: 3200,
                     cooling: { // CHANGED
                        type: "air",
                        model: "fan1"
                    },
                    pins: [
                        {
                            di: 1,
                            do: 2
                        }
                    ]
                }
            ]
        };
        */

That's all!

1.1.6

1 year ago

1.1.5

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago