Add getDeep method to utils

This commit is contained in:
Philip Giuliani 2018-05-30 16:59:11 +02:00
parent e3bae562fc
commit 41c7dff0e8
2 changed files with 6 additions and 1 deletions

View File

@ -10,7 +10,7 @@ const i18n = {
return '';
}
let string = key.split('.').reduce((o,i) => o[i] || {}, config.i18n);
let string = utils.getDeep(config.i18n, key);
if (utils.is.empty(string)) {
return '';

View File

@ -728,6 +728,11 @@ const utils = {
return JSON.parse(JSON.stringify(object));
},
// Get a nested value in an object
getDeep(object, value) {
return value.split('.').reduce((obj, key) => obj[key] || {}, object);
},
// Get the closest value in an array
closest(array, value) {
if (!utils.is.array(array) || !array.length) {