extract-import-url-and-media.js 854 B

1234567891011121314151617181920212223242526272829303132333435
  1. var split = require('../utils/split');
  2. var BRACE_PREFIX = /^\(/;
  3. var BRACE_SUFFIX = /\)$/;
  4. var IMPORT_PREFIX_PATTERN = /^@import/i;
  5. var QUOTE_PREFIX_PATTERN = /['"]\s*/;
  6. var QUOTE_SUFFIX_PATTERN = /\s*['"]/;
  7. var URL_PREFIX_PATTERN = /^url\(\s*/i;
  8. var URL_SUFFIX_PATTERN = /\s*\)/i;
  9. function extractImportUrlAndMedia(atRuleValue) {
  10. var uri;
  11. var mediaQuery;
  12. var stripped;
  13. var parts;
  14. stripped = atRuleValue
  15. .replace(IMPORT_PREFIX_PATTERN, '')
  16. .trim()
  17. .replace(URL_PREFIX_PATTERN, '(')
  18. .replace(URL_SUFFIX_PATTERN, ')')
  19. .replace(QUOTE_PREFIX_PATTERN, '')
  20. .replace(QUOTE_SUFFIX_PATTERN, '');
  21. parts = split(stripped, ' ');
  22. uri = parts[0]
  23. .replace(BRACE_PREFIX, '')
  24. .replace(BRACE_SUFFIX, '');
  25. mediaQuery = parts.slice(1).join(' ');
  26. return [uri, mediaQuery];
  27. }
  28. module.exports = extractImportUrlAndMedia;