UNPKG

@codegouvfr/react-dsfr

Version:

French State Design System React integration library

42 lines 1.12 kB
import { assert } from "tsafe/assert"; import { typeGuard } from "tsafe/typeGuard"; export const cx = (...args) => { const len = args.length; let i = 0; let cls = ""; for (; i < len; i++) { const arg = args[i]; if (arg == null) continue; let toAdd; switch (typeof arg) { case "boolean": break; case "object": { if (Array.isArray(arg)) { toAdd = cx(...arg); } else { assert(!typeGuard(arg, false)); toAdd = ""; for (const k in arg) { if (arg[k] && k) { toAdd && (toAdd += " "); toAdd += k; } } } break; } default: { toAdd = arg; } } if (toAdd) { cls && (cls += " "); cls += toAdd; } } return cls; }; //# sourceMappingURL=cx.js.map