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