Open abdavid opened 4 years ago
What's about this:
function getValue(obj, path, defaultValue = undefined) {
if (!path || typeof path !== "string" ) return null;
let i;
path = path.split(".");
for (i = 0; i < path.length; i++) {
if (!obj[path[i]]) {obj = null; break;}
obj = obj[path[i]];
}
return obj || defaultValue;
}
Benchmark result:
propsoal x 4,046,174 ops/sec ±0.76% (90 runs sampled)
native x 1,466,649 ops/sec ±0.54% (92 runs sampled)
Fastest is propsoal
See #433 for context.
Describe the solution you'd like Remove usage of
_.get
throughout Moleculer.Describe alternatives you've considered Source: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
Another suggestion could be https://github.com/hughfdjackson/delve though I would maybe recommend adopting the code since the lib has not been updated for the last five years, and it from jsPerf tests I could find still outperforms
_.get
(https://jsperf.com/lodash-get-vs-monster-method/5)Additional context https://github.com/moleculerjs/moleculer/search?q=_.get&unscoped_q=_.get