No Description

utils.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (function() {
  2. var list;
  3. list = require('postcss/lib/list');
  4. module.exports = {
  5. error: function(text) {
  6. var err;
  7. err = new Error(text);
  8. err.autoprefixer = true;
  9. throw err;
  10. },
  11. uniq: function(array) {
  12. var filtered, i, j, len;
  13. filtered = [];
  14. for (j = 0, len = array.length; j < len; j++) {
  15. i = array[j];
  16. if (filtered.indexOf(i) === -1) {
  17. filtered.push(i);
  18. }
  19. }
  20. return filtered;
  21. },
  22. removeNote: function(string) {
  23. if (string.indexOf(' ') === -1) {
  24. return string;
  25. } else {
  26. return string.split(' ')[0];
  27. }
  28. },
  29. escapeRegexp: function(string) {
  30. return string.replace(/[.?*+\^\$\[\]\\(){}|\-]/g, '\\$&');
  31. },
  32. regexp: function(word, escape) {
  33. if (escape == null) {
  34. escape = true;
  35. }
  36. if (escape) {
  37. word = this.escapeRegexp(word);
  38. }
  39. return RegExp("(^|[\\s,(])(" + word + "($|[\\s(,]))", "gi");
  40. },
  41. editList: function(value, callback) {
  42. var changed, join, origin;
  43. origin = list.comma(value);
  44. changed = callback(origin, []);
  45. if (origin === changed) {
  46. return value;
  47. } else {
  48. join = value.match(/,\s*/);
  49. join = join ? join[0] : ', ';
  50. return changed.join(join);
  51. }
  52. }
  53. };
  54. }).call(this);