npm.io
1.0.0 • Published 8 years ago

obj-to-routes

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0

obj-to-routes

Convert object to array of URL routes with associated value



Built with ︎ by tiaanduplessis and contributors

Table of Contents

Table of Contents
  • Install
  • Usage
  • Contribute
  • License
  • Install

    $ npm install obj-to-routes
    # OR
    $ yarn add obj-to-routes

    Usage

    const objToRoutes = require('obj-to-routes')
    
    const data = {
      posts: {
        foo: {
          message: 'hello'
        }
      },
      other: 'foo',
      baz: [1,2,3],
      food: {
        steal: {
          healthy: true
        }
      }
    }
    
    console.log(objToRoutes(data))
    // [ { path: '/',
    //     value: { posts: [Object], other: 'foo', baz: [Array], food: [Object] } },
    //   { path: '/posts', value: { foo: [Object] } },
    //   { path: '/posts/foo', value: { message: 'hello' } },
    //   { path: '/posts/foo/message', value: 'hello' },
    //   { path: '/other', value: 'foo' },
    //   { path: '/baz', value: [ 1, 2, 3 ] },
    //   { path: '/food', value: { steal: [Object] } },
    //   { path: '/food/steal', value: { healthy: true } },
    //   { path: '/food/steal/healthy', value: true } ]
    

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.