( strings: TemplateStringsArray, ...keys: readonly string[] )
| 1 | export function css( |
| 2 | strings: TemplateStringsArray, |
| 3 | ...keys: readonly string[] |
| 4 | ): string { |
| 5 | const lastIndex = strings.length - 1 |
| 6 | const str = |
| 7 | // Convert template literal into a single line string |
| 8 | strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') + |
| 9 | strings[lastIndex] |
| 10 | |
| 11 | return ( |
| 12 | str |
| 13 | // Remove comments |
| 14 | .replace(/\/\*[\s\S]*?\*\//g, '') |
| 15 | // Remove whitespace, tabs, and newlines |
| 16 | .replace(/\s+/g, ' ') |
| 17 | // Remove spaces before and after semicolons, and spaces after commas |
| 18 | .replace(/\s*([:;,{}])\s*/g, '$1') |
| 19 | // Remove extra semicolons |
| 20 | .replace(/;+}/g, '}') |
| 21 | // Trim leading and trailing whitespaces |
| 22 | .trim() |
| 23 | ) |
| 24 | } |
no test coverage detected