Allow for nested objects as data/keys
See original GitHub issueFirstly, thanks so much for this lib. It’s really useful for a project I’m currently working on and the code is really easy to follow. Awesome work! 🙌
For my project I’m using nested data objects that I pass to the format
method. Right now I have to flatten the object for it to work, for example this:
var data = {
'user': 'Steve',
'members': {
'count': 10
}
};
becomes:
var data = {
'user': 'Steve',
'members.count': 10
};
This works fine but when the data object is huge, with lots of nested data we don’t care about, it becomes a bit of a performance issue.
A work around for this would be to update the interpretSimple
function to be:
function interpretSimple (id) {
return function format (args) {
var parts = id.split('.');
if (parts.length > 1) {
var i = 0;
var l = parts.length;
var a = args;
for (i; i < l; i++) {
a = a[parts[i]];
if (!a) return '' + args[id];
}
return '' + a;
}
return '' + args[id];
}
}
This would look for nested variables in an object but would fallback to how things currently work, so would be a minor update / backwards compatible.
Is this something that could be consider? If yes I can put together a PR today along with updated unit tests etc.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)
Top GitHub Comments
Awesome, thanks for the direction. Will take a look at this before making a PR.
Thank you so much, Andy. This really helps us a lot.