Giter VIP home page Giter VIP logo

dotize's Introduction

npm version Bower version Build Status codecov

dotize

Convert (Complex js object)

{
  "status": "success",
  "auth": {
    "code": 123,
    "name": "qwerty asdfgh"
  }
}

to (Dot notation js object)

{
  "status": "success",
  "auth.code": 123,
  "auth.name": "qwerty asdfgh"
}
npm install dotize

bower

bower install dotize
npm install -g mocha
mocha test/test.js

dotize's People

Contributors

iamrenejr avatar siutsin avatar vardars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dotize's Issues

keyword/number documents should probably return the raw value

dotize.convert(null) ==> {  } // expect: null
dotize.convert(true) ==> {  } // expect: true
dotize.convert(1984) ==> {  } // expect: 1984
dotize.convert(null,"foo") ==> {  } // expect: {foo:null}
dotize.convert(true,"foo") ==> {  } // expect: {foo:true}
dotize.convert(1984,"foo") ==> {  } // expect: {foo:1984}

bug with strings

dotize.convert("foo") ==> {0:"f",1:"o",2:"o"} // expect "foo"
dotize.convert("foo","foo") ==> { foo.0: "f", foo.1: "o", foo.2: "o" } // expect {foo:"foo"}

Number as object key

Is this behavior normal?

dotize.backward({"2": "2"}) => [ null, null, "2" ] // expect { "2" : "2"}

License

Can you mention the license please? Thanks!

wishlist

  1. Reverse method for "convert"
  2. Custom delimiter symbol eg: -,_
  3. Arrays convert config ( exclude prototypes, map array to index-like object)

arrays should have a consistant notation

dotize.convert([])   ==> {  } // expect: [] ???
dotize.convert([],"foo") ==> {  } // expect: {foo:[]} ???
OKAY!: dotize.convert(["foo"]) ==> {0:"foo"}
OKAY!: dotize.convert(["foo"],"foo") ==> {foo.0:"foo"}

dotize.convert([[[{foo:"one"}],[{foo:"two"}]],[[{foo:"three"}],[{foo:"four"}]]]) ==>
    { 0.0[0].foo: "one", 0.1[0].foo: "two", 1.0[0].foo: "three", 1.1[0].foo: "four" }
    // expect: { 0.0.0.foo: "one", 0.1.0.foo: "two", 1.0.0.foo: "three", 1.1.0.foo: "four" }

primitive type added a dot

Nice work.
I found a little error in you code.
You are missing a check for if prefix is not defined in line 21 like you do all the other places in the code. This error causes a dot to be added to the beginning of a property name of a primitive type when no prefix is supplied.

The line should look like this:
newobj[(p ? p + "." : "") + f] = o[f]; // primitive

Handling of empty objects

When running dotize, I expect empty objects (such as {}, cases where Object.keys().length === 0) to effectively be removed. Since there is nothing to flatten, no variables below it can be defined. Is it intentional that empty objects remain in the resulting object?

Keys prefixed with dot when used with arrays

When using arrays, the keys become prefixed with a dot ., even when no prefix is set. For example:

dotize.convert({data: [ {obj0key: 'obj0val'}, {obj1key: 'obj1val'} ] })

This returns:

{ '.data[0].obj0key': 'obj0val', '.data[1].obj1key': 'obj1val' }

Expected return:

{ 'data[0].obj0key': 'obj0val', 'data[1].obj1key': 'obj1val' }

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.