You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
691 B

4 years ago
  1. var SUPPORTED_COMPACT_BLOCK_MATCHER = /^@media\W/;
  2. function tidyBlock(values, spaceAfterClosingBrace) {
  3. var withoutSpaceAfterClosingBrace;
  4. var i;
  5. for (i = values.length - 1; i >= 0; i--) {
  6. withoutSpaceAfterClosingBrace = !spaceAfterClosingBrace && SUPPORTED_COMPACT_BLOCK_MATCHER.test(values[i][1]);
  7. values[i][1] = values[i][1]
  8. .replace(/\n|\r\n/g, ' ')
  9. .replace(/\s+/g, ' ')
  10. .replace(/(,|:|\() /g, '$1')
  11. .replace(/ \)/g, ')')
  12. .replace(/'([a-zA-Z][a-zA-Z\d\-_]+)'/, '$1')
  13. .replace(/"([a-zA-Z][a-zA-Z\d\-_]+)"/, '$1')
  14. .replace(withoutSpaceAfterClosingBrace ? /\) /g : null, ')');
  15. }
  16. return values;
  17. }
  18. module.exports = tidyBlock;