Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Works like underscore-contrib's getPath function.
- // Takes a promise that will resolve to an object and a dot notation string specifying a path.
- //
- // Cannot know if path exists in resolved value - returned promise will reject with a TypeError if you
- // specify a subkey of a nonexistent key, and undefined for a single
- // nonexistent key.
- function promiseForPath(promise, path) {
- var k = path.split('.');
- return k.reduce(function(memo, item){
- return memo.get(item);
- }, promise);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement