@dvcol/common-utils
Version:
Typescript library for common utility functions and constants
42 lines (35 loc) • 1.31 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunkMXKBAB24cjs = require('./chunk-MXKBAB24.cjs');
// 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(`${_chunkMXKBAB24cjs.toKebabCase.call(void 0, 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);
exports.toClass = toClass; exports.toStyle = toStyle;