modify-object-recursively
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

npm version

modify-object-recursively

A npm module which allows you to perform a single function on an object, and any sub objects recursively, it works ONLY on objects, and does not do anything with any other type of values. this is useful when you wish to append methods, or new keys to objects, or sub objects.

Usage and examples

  • Install.
yarn add modify-object-recursively
npm install modify-object-recursively
  • Import/RequireUsage
import ModifyObjectRecursively from 'modify-object-recursively';
  • Actual use examples
    // Declare the object
      var obj = {
          a: 1,
          b: {a: 1, b: {}},
      };
    // Apply some method to object and sub objects
      var result=ModifyObjectRecursively(obj, (subObj) => { 
                                 subObj.test1=2;
                                 subObj.test2=3;
                                 return subObj;
                             });
    • result will be:
        {
            a: 1,
            b: {
                a: 1, b: {
                    2,
                    test2: 3
                }, test1: 2,
                test2: 3
            },
            test1: 2,
            test2: 3
        };

License

The license chosen for this project can be found inside package.json: MIT

Hopefully this module will save you a little bit of time, have fun and best of luck!

Package Sidebar

Install

npm i modify-object-recursively

Weekly Downloads

60

Version

1.0.0

License

MIT

Unpacked Size

10.9 kB

Total Files

8

Last publish

Collaborators

  • vasilevich