UNPKG

equinox-web-components

Version:

Equinox design for the web using StencilJS

43 lines (40 loc) 1.15 kB
'use strict'; 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 findPath = (obj, name, val, currentPath = []) => { let matchingPath; if (!obj || typeof obj !== 'object') return; if (obj[name] === val) return [...currentPath, name]; for (const key of Object.keys(obj)) { if (key === name && obj[key] === val) { matchingPath = currentPath; } else { matchingPath = findPath(obj[key], name, val, [...currentPath, key]); } if (matchingPath) break; } return matchingPath; }; exports.deserializeJSON = deserializeJSON; exports.findPath = findPath; exports.getAbbr = getAbbr;