// Utility function to get access nested object properties securely // // Usage: // const invoiceName = get(account, "user.invoiceAddress.name") // // Instead of: // const invoiceName = (account && account.user && account.user.invoiceAddress && account.user.invoiceAddress.name) || null // https://stackoverflow.com/a/23809123/1410020 const get = (obj, key) => key .split(".") .reduce((o, x) => (typeof o == "undefined" || o === null) ? o : o[x], obj)