mickhansen / dottie.js Goto Github PK
View Code? Open in Web Editor NEWFast and safe nested object access and manipulation in JavaScript
License: MIT License
Fast and safe nested object access and manipulation in JavaScript
License: MIT License
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
}]
}
}
get(key) should return a null value if value is actually null, not undefined.
Do you plan to add a license to dottie? Might be a good idea since it is a dependency of sequelize :)
if a key has dot in name, how do I access to it?
var values = {
some: {
'nested.with.dot': {
key: 'foobar';
}
}
}
dottie.get(values, 'some.nested.with.dot.key');
Is this originally a fork from https://github.com/deoxxa/dotty ?
Is it backwards compatible?
travis, tests, etc.
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
}
}
๐ 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.
Thank you!
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
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.
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.
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 ;)
Currently dottie.paths
is not working properly with nested empty objects:
console.log(dottie.paths({ a: 1, b: {} }));
Expected: ['a', 'b']
Actual: ['a']
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.