Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/css-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var _ = require('lodash');

var embeddedRegexp = /data:(.*?);base64,/;
var commentRegexp = /\/\*([\s\S]*?)\*\//g;
var urlsRegexp = /((?:@import\s+)?url\s*\(['"]?)(\S*?)(['"]?\s*\))|(@import\s+['"]?)([^;'"]+)/ig;
Expand All @@ -10,20 +8,23 @@ function isEmbedded (src) {

function getUrls (text) {
var urls = [];
var urlMatch;
var urlMatch, url, isEmbeddedUrl, isDuplicatedUrl;

text = text.replace(commentRegexp, '');

while (urlMatch = urlsRegexp.exec(text)) {
// Match 2 group if '[@import] url(path)', match 5 group if '@import path'
urls.push(urlMatch[2]||urlMatch[5]);
url = urlMatch[2] || urlMatch[5];

isEmbeddedUrl = isEmbedded(url);
isDuplicatedUrl = urls.indexOf(url) !== -1;

if (url && !isEmbeddedUrl && !isDuplicatedUrl) {
urls.push(url);
}
}

return _.chain(urls)
.compact()
.reject(isEmbedded)
.uniq()
.value();
return urls;
}

module.exports = getUrls;
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"homepage": "https://github.com/s0ph1e/node-css-url-parser",
"author": "s0ph1e",
"license": "MIT",
"dependencies": {
"lodash": "^4.0.0"
},
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.4.5",
Expand Down