GithubHelp home page GithubHelp logo

418sec / node-objnest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from okunishinishi/node-objnest

0.0 2.0 1.0 289 KB

Node.js module to convert nested object to flatten or expand.

Home Page: https://www.npmjs.com/package/objnest

License: MIT License

JavaScript 97.46% Handlebars 2.54%

node-objnest's Introduction

objnest

Build Status npm Version JS Standard

Convert nested object to flatten or expand.

{foo.bar: 'baz'} <=> {foo: {bar: 'baz'}}

Installation

npm install objnest --save

Usage

Flatten Object Properties

Convert nested object into flatten structure.

'use strict'

const objnest = require('objnest')
let flattened = objnest.flatten({
    'foo': {'bar': 'baz'}
})
console.log(flattened) // => {'foo.bar': 'baz'}

Expand Object Properties

Convert flattened object into nested structure.

'use strict'

const objnest = require('objnest')
let expanded = objnest.expand({
    'foo.bar': 'baz'
})
console.log(expanded) // => {foo: {bar: 'baz'}}

Tips

Handling Array

Brackets with numbers are parsed as array.

'use strict'

const objnest = require('objnest')
let flattened = objnest.flatten({
  'foo': { 'bar': [ 'baz0', 'baz1' ] }
})
console.log(flattened) // => {'foo.bar[0]': 'baz0', 'foo.bar[1]': 'baz1'}
'use strict'

const objnest = require('objnest')
let expanded = objnest.expand({
  'foo.bar[0]': 'baz0',
  'foo.bar[1]': 'baz1'
})
console.log(expanded) // => {foo: bar:['baz0', 'baz1']}}

License

This software is released under the MIT License.

node-objnest's People

Contributors

okunishinishi avatar arjunshibu avatar jamieslome avatar

Watchers

James Cloos avatar  avatar

Forkers

arjunshibu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.