Last active
July 5, 2016 15:39
-
-
Save wmakeev/a91e0239e833488c566fe0b8121cab3c to your computer and use it in GitHub Desktop.
lodash.get wrapper #tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let get = require('lodash.get') | |
const getIt = function (...args) { | |
return action => { | |
let value = get.apply(this, args) | |
if (action && value !== void 0) { | |
return action(value) | |
} else { | |
return value | |
} | |
} | |
} | |
let obj = { | |
foo: 1, | |
bar: { | |
baz: 'some', | |
biz: "200", | |
boo: { | |
far: 'deep' | |
} | |
} | |
} | |
let far = getIt(obj, 'bar.boo.far')() // 'deep' | |
let biz = getIt(obj, ['bar', 'biz'])(biz => parseInt(biz) / 100) // 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment