Skip to content

Instantly share code, notes, and snippets.

@Archakov06
Created April 22, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archakov06/0e2e6575e93af601a107dcb9410dcb00 to your computer and use it in GitHub Desktop.
Save Archakov06/0e2e6575e93af601a107dcb9410dcb00 to your computer and use it in GitHub Desktop.
// Source: https://github.com/zewish/oget
'use strict';
export default (obj, path, def) => {
let res = path
.replace(/\[/g, '.')
.replace(/\]/g, '')
.replace(/^\./, '')
.split('.')
.reduce((prev, curr) => {
return prev && prev[curr]
}, obj);
return (res === undefined)
? def
: res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment