/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/libs/editor/src/utils/styles.js
36 строк
924 B
Raul Martin
refactor: echo 27: Introducing biome (#5759)
29 апр 2024, 11:39
Не верифицирован
29 апр 2024, 11:39
2660ec9
Код
Авторство
О чём код?
/** * Parses a string of inline styles into a JavaScript object with casing for React * * @see TemplateEngine via MIT Licensed https://github.com/NervJS/taro/blob/master/packages/taro-components-rn/src/utils/index.ts * * @param {string} styles * @returns {Object} */ export function styleToProp(styles) { if (!styles) return null; return styles .split(";") .filter((style) => style.split(":")[0] && style.split(":")[1]) .map((style) => [ style .split(":")[0] .trim() .replace(/-./g, (c) => c.substr(1).toUpperCase()), style.split(":").slice(1).join(":").trim(), ]) .reduce( (styleObj, style) => ({ ...styleObj, [style[0]]: style[1], }), {}, ); } export function asVars(obj) { if (!obj) return null; return Object.entries(obj).reduce((vars, [key, val]) => { vars[`--${key}`] = val; return vars; }, {}); }