Ei kuvausta

empty-removal.js 777B

123456789101112131415161718192021222324252627282930
  1. module.exports = function EmptyRemoval(data) {
  2. var stripEmpty = function(cssData) {
  3. var tempData = [];
  4. var nextEmpty = 0;
  5. var cursor = 0;
  6. for (; nextEmpty < cssData.length;) {
  7. nextEmpty = cssData.indexOf('{}', cursor);
  8. if (nextEmpty == -1)
  9. break;
  10. var startsAt = nextEmpty - 1;
  11. while (cssData[startsAt] && cssData[startsAt] != '}' && cssData[startsAt] != '{' && cssData[startsAt] != ';')
  12. startsAt--;
  13. tempData.push(cssData.substring(cursor, startsAt + 1));
  14. cursor = nextEmpty + 2;
  15. }
  16. return tempData.length > 0 ?
  17. stripEmpty(tempData.join('') + cssData.substring(cursor, cssData.length)) :
  18. cssData;
  19. };
  20. return {
  21. process: function() {
  22. return stripEmpty(data);
  23. }
  24. };
  25. };