equinox-web-components
Version:
Equinox design for the web using StencilJS
35 lines (32 loc) • 867 B
JavaScript
;
const getAbbr = (str) => {
if (str) {
return str.split(' ').length >= 2 ? str.match(/\b(\w)/g).join('') : str.substr(0, 2);
}
else {
return "";
}
};
const deserializeJSON = (json, component = 'unknown') => {
try {
json = json.split(""").join("\"");
return JSON.parse(json);
}
catch (e) {
console.log(json, e);
alert(`Error while trying to parse JSON in ${component} component`);
}
};
const findDeep = (obj, keyToFind, value) => {
if (obj[keyToFind] === value) {
console.log(obj);
}
for (const key in obj) {
if (typeof obj[key] === 'object') {
findDeep(obj[key], keyToFind, value);
}
}
};
exports.deserializeJSON = deserializeJSON;
exports.findDeep = findDeep;
exports.getAbbr = getAbbr;