No Description

escape-store.js 825B

1234567891011121314151617181920212223242526272829303132
  1. module.exports = function EscapeStore(placeholderRoot) {
  2. placeholderRoot = 'ESCAPED_' + placeholderRoot + '_CLEAN_CSS';
  3. var placeholderToData = {};
  4. var dataToPlaceholder = {};
  5. var count = 0;
  6. var nextPlaceholder = function() {
  7. return '__' + placeholderRoot + (count++) + '__';
  8. };
  9. var pattern = '(__' + placeholderRoot + '\\d{1,}__)';
  10. return {
  11. placeholderPattern: pattern,
  12. placeholderRegExp: new RegExp(pattern, 'g'),
  13. store: function(data) {
  14. var placeholder = dataToPlaceholder[data];
  15. if (!placeholder) {
  16. placeholder = nextPlaceholder();
  17. placeholderToData[placeholder] = data;
  18. dataToPlaceholder[data] = placeholder;
  19. }
  20. return placeholder;
  21. },
  22. restore: function(placeholder) {
  23. return placeholderToData[placeholder];
  24. }
  25. };
  26. };