Conversation
|
@marseille I don't understand what you mean by "uniform". Can you add some docs? |
|
Sure, I can elaborate a bit more. I did have an example or two in the readme.md and the test.js that explain a bit, maybe they will help. When I used the maxDepth option on an object, I did not see it apply the same depth to each key of an object. Instead I saw it count the number of objects it would flatten. If I specified an object with three keys, and first key having a depth of 3 - only the first key would be flattened. The rest of the keys would be untouched, if we were to use maxDepth 3. That does not work well for my use case, I'd like every key in the object flattened to the same depth, if specified. Let's say you have an object - var hello_hash = {
hello: {
world: {again: 'good morning'}
},
salut: {
monde: {encore: {bonne: 'matin'}}
},
konnichiwa: { sekai: { mou: { ohayou: 'gozaimasu' } } }
}
flatten(hello_hash, {maxDepth: 3})
/*
hello_hash =>
{
hello.world.again': 'good morning',
salut: {
monde: { encore: {bonne:'matin' } },
}
konnichiwa: { sekai: { mou: {ohayou: 'gozaimasu' } } }
}
*/We can see here that the first key 'hello' was flattened, but none of the other keys were flattened. It looks like it flattened 3 objects, as per maxDepth, and then it was done working on the object. Another object demonstrating uniformFlatten - var hello_hash = {
hello: {
world: {again: 'good morning'}
},
salut: {
monde: {encore: {bonne: 'matin'}}
},
konnichiwa: { sekai: { mou: { ohayou: 'gozaimasu' } } }
}
flatten(hello_hash, {maxDepth: 3, uniformFlatten:true})
/*
hello_hash =>
{ 'hello.world.again': 'good morning',
'salut.monde.encore': { bonne: 'matin' },
'konnichiwa.sekai.mou': { ohayou: 'gozaimasu' } }
*/Now we can see that every key in the object has been flattened to the same depth. We specified maxDepth: 3, as a result, every key has flattened 3 levels deep. Uniformly flattened, if you will. This works very well for me and I can see it being useful in the future as well. It's possible the name might be confusing, does that clarify what I meant by uniform? |
|
May I have an update on the status of this pull request? Is there additional information I could provide to help clarify any concerns? |
This addition adds uniform flattening when you specify uniformFlatten:true and a maxDepth.
I was finding in my project that I needed to flatten an object but that it needed to be consistently flattened across the board.