{"ScriptPreparationCode":"var str = \u0027style\u0027;\r\nvar obj = {\r\n \t \u0027style-2\u0027: true,\r\n \t \u0027style-3\u0027: false,\r\n \t \u0027style-4\u0027: true,\r\n}\r\nvar arr = [\u0027style-5\u0027, \u0027style-6\u0027]","TestCases":[{"Name":"classnames","Code":"let result = window.classNames(str, obj, arr, \u0027test classname\u0027)","IsDeferred":false},{"Name":"clsx","Code":"let result = window.clsx(str, obj, arr, \u0027test classname\u0027)","IsDeferred":false},{"Name":"Array based","Code":"function ts(...args){\r\n let template = [];\r\n args.forEach(arg =\u003E {\r\n \tif (typeof arg === \u0027string\u0027) {\r\n template.push(arg); \r\n return; \r\n }\r\n \r\n \tif (arg.join) {\r\n template = [...template, ...arg]; \r\n return;\r\n }\r\n \r\n let entries = Object.entries(arg);\r\n if (entries.length) {\r\n entries.forEach(entry =\u003E {\r\n if(entry[1]) template.push(entry[0]) \r\n })\r\n }\r\n })\r\n return template.join(\u0027 \u0027);\r\n}\r\nlet result = ts(str, obj, arr, \u0027test classname\u0027)","IsDeferred":false},{"Name":"String based (return struct)","Code":"function ts(...args){\r\n let template = \u0027\u0027;\r\n args.forEach(arg =\u003E {\r\n \tif (typeof arg === \u0027string\u0027) { \r\n template \u002B= \u0027 \u0027\u002Barg;\r\n return; \r\n }\r\n \tif (arg.join) { \r\n arg.forEach((e) =\u003E { \r\n template \u002B= \u0027 \u0027 \u002B e; \r\n }) \r\n return;\r\n }\r\n let entries = Object.entries(arg);\r\n if (entries.length) {\r\n entries.forEach(entry =\u003E {\r\n if(entry[1]) template \u002B= \u0027 \u0027 \u002B entry[0]\r\n })\r\n }\r\n })\r\n return template;\r\n}\r\nlet result = ts(str, obj, arr, \u0027test classname\u0027)","IsDeferred":false},{"Name":"String based (if-else struct)","Code":"function ts(...args){\r\n let template = \u0027\u0027;\r\n args.forEach(arg =\u003E {\r\n \tif (typeof arg === \u0027string\u0027) { \r\n template \u002B= \u0027 \u0027\u002Barg;\r\n } else if (arg.join) { \r\n arg.forEach((e) =\u003E { \r\n template \u002B= \u0027 \u0027 \u002B e; \r\n }) \r\n } else {\r\n let entries = Object.entries(arg);\r\n if (entries.length) {\r\n entries.forEach(entry =\u003E {\r\n if(entry[1]) template \u002B= \u0027 \u0027 \u002B entry[0]\r\n })\r\n }\r\n }\r\n })\r\n return template;\r\n}\r\nlet result = ts(str, obj, arr, \u0027test classname\u0027)","IsDeferred":false},{"Name":"Entries, filter, map, join","Code":"let objStyle = Object.entries(obj).filter((style)=\u003Estyle[1]).map(style =\u003E style[0]).join(\u0027 \u0027);\r\nlet arrComb = arr.join(\u0027 \u0027)\r\nlet result = \u0060${str} ${objStyle} ${arrComb} test classname\u0060","IsDeferred":false},{"Name":"String literally","Code":"var literal = \u0060style ${true ? \u0022style-2\u0022 : \u0022\u0022} ${false ? \u0022style-3\u0022 : \u0022\u0022} ${true ? \u0022style-4\u0022 : \u0022\u0022} style-5 style-6\u0060","IsDeferred":false},{"Name":"Recursive tagged template literal","Code":"const toCls = (arg) =\u003E {\r\n if (typeof arg === \u0027boolean\u0027)\r\n return \u0022\u0022;\r\n if (typeof arg === \u0027string\u0027)\r\n return \u0060 ${arg}\u0060;\r\n if (Array.isArray(arg))\r\n return arg.map(a =\u003E toCls(a));\r\n if (typeof arg === \u0027object\u0027)\r\n return toCls(Object.entries(arg).filter(e =\u003E e[1]).map(e =\u003E e[0]));\r\n throw new Error(\u0022Invalid arg: \u0060${arg}\u0060\u0022);\r\n};\r\nconst cls = (s, ...args) =\u003E {\r\n //console.log(s)\r\n //console.log(args)\r\n let classNames = \u0022\u0022;\r\n args.forEach((expr, i) =\u003E {\r\n if (s[i] != \u0022\u0022 \u0026\u0026 s[i] != \u0022 \u0022)\r\n classNames \u002B= \u0060 ${s[i]}\u0060;\r\n classNames \u002B= toCls(expr);\r\n });\r\n classNames \u002B= s[s.length - 1];\r\n return classNames;\r\n};\r\n\r\nlet result = cls\u0060${str} ${obj} ${arr} test classname\u0060;","IsDeferred":false}]}