json-atom

1.2.1 • Public • Published
master develop npm
Build Status Build Status npm version

json-atom

    const {get, set, apply} = require('json-atom');
    const data = {
        user: {
            contact: {
                home: {
                    number: 11111
                }, mobile: {
                    number: 22222
                }
            },
            posts: [
                {content: 'Hello World!', likes: 10},
                {content: 'Goodbye World!', likes: 1}
            ]
        }
    };

    let result = get('$.user.contact.home.number')(data);
    // 11111

    result = get('$.user.contact["home","mobile"].number')(data);
    // {home: 11111, mobile: 22222}

    result = set('$.user.contact["home","mobile"].number')(99999)(data)

    // set is Immutable, data hasn't been modified, a new refernece is returned
    // lenses powering json-atom effectively behave like HAMT
    // They only create new objects for the nodes from root to path, the rest of the structure is shared.

    // {"user":{"contact":{"home":{"number":99999},"mobile":{"number":99999}},"posts":[{"content":"Hello World!","likes":10},{"content":"Goodbye World!","likes":1}]}}

    // number fields under both branches, namely 'home' AND 'mobile' are both set to value in the new object reference







Possible use cases

  • Redux Store Like Behavior around any JSON reference
  • Immutable deep manipulation of JSON data

Run the tests

npm test

FAQs

Build Targets

Currently the following target build environments are configured for babel-preset-env plugin

 "targets": {
   "node": 4.3,
   "browsers": ["last 10 versions", "ie >= 7"]
 }

In case this turns out to be not generous enough, more backward compatible babel transpilation targets would be added.

Roadmap

  • bigger and better
  • rule'em all

Contributing

See CONTRIBUTING.md

License

MIT

Package Sidebar

Install

npm i json-atom

Weekly Downloads

0

Version

1.2.1

License

MIT

Unpacked Size

25.5 kB

Total Files

11

Last publish

Collaborators

  • slyd