You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 862B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. var getImports = require('get-imports');
  3. /**
  4. * Get path from @import
  5. *
  6. * @param {String} str
  7. * @api private
  8. */
  9. function path(str) {
  10. return /(?:url\()(?:.*?)(?:\))|(["\'])(?:[^"\')]+)\1/ig.exec(str)[0]
  11. .replace(/(?:url\()/ig, '')
  12. .replace(/(?:\))/g, '')
  13. .replace(/(?:["\'])/g, '')
  14. .trim();
  15. }
  16. /**
  17. * Get condition from @import
  18. *
  19. * @param {String} str
  20. * @api private
  21. */
  22. function condition(str) {
  23. return str.replace(/(?:url\()(?:.*?)(?:\))|(["\'])(?:[^"\')]+)\1/ig, '')
  24. .replace(/(?:@import)(?:\s)*/g, '')
  25. .trim();
  26. }
  27. /**
  28. * Parse @import statements
  29. *
  30. * @param {String} str
  31. * @api public
  32. */
  33. module.exports = function (str) {
  34. var imports = getImports(str);
  35. return imports.map(function (imp) {
  36. imp = imp.replace(/(?:;)$/g, '');
  37. return {
  38. path: path(imp),
  39. condition: condition(imp),
  40. rule: imp
  41. };
  42. });
  43. };