@dvcol/common-utils
Version:
Typescript library for common utility functions and constants
42 lines (39 loc) • 1.17 kB
JavaScript
import {
toKebabCase
} from "./chunk-F2ODECNN.js";
// lib/common/utils/class.utils.ts
var flatten = (styles, flat = [], camel) => {
if (!styles) return flat;
if (typeof styles === "string") flat.push(styles);
else if (Array.isArray(styles)) {
styles.forEach((style) => {
if (!style) return;
flatten(style, flat, camel);
});
} else if (typeof styles === "object") {
Object.entries(styles).forEach(([key, value]) => {
if (!value) return;
if (typeof value === "string") {
if (camel) flat.push(`${toKebabCase(key)}:${value}`);
else flat.push(`${key}:${value}`);
} else flat.push(key);
});
}
return flat;
};
var parse = (args, separator = "", camel) => {
if (!args.length) return;
const flat = [];
args.forEach((arg) => flatten(arg, flat, camel));
return flat.filter(Boolean).map((style) => {
if (!separator) return style.trim();
const _style = style.trim();
return _style.endsWith(separator) ? _style.slice(0, -1) : _style;
}).join(`${separator} `);
};
var toClass = (...args) => parse(args);
var toStyle = (...args) => parse(args, ";", true);
export {
toClass,
toStyle
};