source-tracker.js 807 B

12345678910111213141516171819202122232425262728293031
  1. function SourceTracker() {
  2. this.sources = [];
  3. }
  4. SourceTracker.prototype.store = function (filename, data) {
  5. this.sources.push(filename);
  6. return '__ESCAPED_SOURCE_CLEAN_CSS' + (this.sources.length - 1) + '__' +
  7. data +
  8. '__ESCAPED_SOURCE_END_CLEAN_CSS__';
  9. };
  10. SourceTracker.prototype.nextStart = function (data) {
  11. var next = /__ESCAPED_SOURCE_CLEAN_CSS(\d+)__/.exec(data);
  12. return next ?
  13. { index: next.index, filename: this.sources[~~next[1]] } :
  14. null;
  15. };
  16. SourceTracker.prototype.nextEnd = function (data) {
  17. return /__ESCAPED_SOURCE_END_CLEAN_CSS__/g.exec(data);
  18. };
  19. SourceTracker.prototype.removeAll = function (data) {
  20. return data
  21. .replace(/__ESCAPED_SOURCE_CLEAN_CSS\d+__/g, '')
  22. .replace(/__ESCAPED_SOURCE_END_CLEAN_CSS__/g, '');
  23. };
  24. module.exports = SourceTracker;