Code Monkey home page Code Monkey logo

dottie.js's People

Contributors

amarinov avatar coliff avatar dawsbot avatar dependabot[bot] avatar durango avatar firoze avatar henrikhaugboelle avatar janmeier avatar linkiwi avatar mickhansen avatar noosxe avatar redsandro avatar robboerman avatar scottrain avatar sdepold avatar simonschick avatar slavivanov avatar srinivas32 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dottie.js's Issues

transform wont work for array paths

Say I have a path like object.edges[0].node, if I try to use transform on that it will generate an object like this

{
  object: {
    'edges[0]': {
      node: undefined
    }
  }
}

I think it should take care of arrays as well and generate structure like this

{
  object: {
    'edges': [{
      node: undefined
    }]
  }
}

License

Do you plan to add a license to dottie? Might be a good idea since it is a dependency of sequelize :)

Not including attributes when transforming

When running transform it does not include the highest level attributes it seems.
Look at the example below.

{
        "customer.name": "abcd",
        "customer.age": 15,
        "client": "Lolcat"
}

After transforming this should be:

{
        "customer": {
                "name": "abcd",
                "age": 15
        },
        "client": "Lolcat"
}

What it does now:

{
        "customer": {
                "name": "abcd",
                "age": 15
        }
}

Add license to NPM

๐Ÿ‘‹ Hello, could you please update NPM with the license (MIT) for this project?

https://www.npmjs.com/package/dottie

It it currently reflecting as none, despite your GitHub license, README.md and LICENSE stating that it is MIT licensed.

dottie_-_npm

Thank you!

Does not handle well if object is null

I wish it could handle object of null better rather than throw errors.

var dottie = require('dottie');

var data = {
  key: null
};

console.log(dottie.get(data, 'key.notexist'));

Errors

/Volumes/Data/Data/Git/namnguye/forks/ccmui-ops/node_modules/dottie/dottie.js:48
                if (!hasOwnProp.call(current, piece)) {
                                ^
TypeError: Cannot convert null to object
    at hasOwnProperty (native)
    at Function.Dottie.get (/Volumes/Data/Data/Git/git.corp.adobe.com/namnguye/forks/ccmui-ops/node_modules/dottie/dottie.js:48:21)
    at Object.<anonymous> (/Volumes/Data/Data/Git/git.corp.adobe.com/namnguye/forks/ccmui-ops/ccmui-ops.js:129:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Suggestion - Support Extending Objects

It would be pretty awesome if there was a way of using dottie to extend the native Object prototype. I suggest this because there's a lot of verboicity in dottie.get(obj, 'some.property').

dottie.extend();
// Extends Object prototype

var values = {
  some: {
    nested: {
        key: 'foobar';
    }
  }
}

values.dGet('some.nested.key'); // returns 'foobar'
values.dGet('some.undefined.key') // returns undefined

values.dSet('some.nested.value', someValue);  // creates nested structure


var somePostData = {
  'user.name': 'Gummy Bear',
  'user.email': '[email protected]',
  'user.professional.title': 'King',
  'user.professional.employer': 'Candy Mountain'
};

var transformed = somePostData.dTransform();

var somePostData = {
  'user_name' : 'Mick Hansen',
  'user_email' : '[email protected]'
};

var delimited = somePostData.transform({ delimiter: "_" });

If you're OK with doing something like this I can start writing the extension code.

Remove index.js

Index.js point to a file or folder called dot, with module.exports = require('./dot');. But that file or folder doesn't exist. So their is no point in having index.js.

Getting paths with dots in some keys

I use dottie for user defined dynamic filtering on objects. I understand that there is a feature to use arrays of keys to handle path lookup like dotties.get(data, ['foo', 'bar.baz']).
However I don't know if a user is asking for ['foo', 'bar.baz'] or ['foo.bar', 'baz']. That is determined by the data that they are looking at.

For example:

User says:

'foo.bar.baz'

Data has:

{ foo: { 'bar.baz': true } }

All I can do is dotties.get(data, 'foo.bar.baz') because I do not know what the data is. So it would be great if dottie could handle this.

It could be unclear with a situation like:

{
  foo: { 'bar.baz': true },
  'foo.bar': { baz: true },
  'foo.bar.baz: true,
}

In this case I'd probably declare that if { 'foo.bar.baz' } exists then that path is used.

It may introduce an overhead in the library so it may need to be 'enabled' with an option? If I asked for 'foo.bar.baz' you would always need to check for 'foo.bar.baz' then 'foo.bar' then 'foo' etc.

I could handle this myself, but I do already use dottie in several places and really like it ;)

dottie.paths fails on empty objects

Currently dottie.paths is not working properly with nested empty objects:

console.log(dottie.paths({ a: 1, b: {} }));

Expected: ['a', 'b']
Actual: ['a']

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.