tidy-block.js 691 B

1234567891011121314151617181920212223
  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;