File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 1- var _ = require ( 'lodash' ) ;
2-
31var embeddedRegexp = / d a t a : ( .* ?) ; b a s e 6 4 , / ;
42var commentRegexp = / \/ \* ( [ \s \S ] * ?) \* \/ / g;
53var urlsRegexp = / ( (?: @ i m p o r t \s + ) ? u r l \s * \( [ ' " ] ? ) ( \S * ?) ( [ ' " ] ? \s * \) ) | ( @ i m p o r t \s + [ ' " ] ? ) ( [ ^ ; ' " ] + ) / ig;
@@ -10,20 +8,23 @@ function isEmbedded (src) {
108
119function getUrls ( text ) {
1210 var urls = [ ] ;
13- var urlMatch ;
11+ var urlMatch , url , isEmbeddedUrl , isDuplicatedUrl ;
1412
1513 text = text . replace ( commentRegexp , '' ) ;
1614
1715 while ( urlMatch = urlsRegexp . exec ( text ) ) {
1816 // Match 2 group if '[@import] url(path)', match 5 group if '@import path'
19- urls . push ( urlMatch [ 2 ] || urlMatch [ 5 ] ) ;
17+ url = urlMatch [ 2 ] || urlMatch [ 5 ] ;
18+
19+ isEmbeddedUrl = isEmbedded ( url ) ;
20+ isDuplicatedUrl = urls . indexOf ( url ) !== - 1 ;
21+
22+ if ( url && ! isEmbeddedUrl && ! isDuplicatedUrl ) {
23+ urls . push ( url ) ;
24+ }
2025 }
2126
22- return _ . chain ( urls )
23- . compact ( )
24- . reject ( isEmbedded )
25- . uniq ( )
26- . value ( ) ;
27+ return urls ;
2728}
2829
2930module . exports = getUrls ;
Original file line number Diff line number Diff line change 2525 "homepage" : " https://github.com/s0ph1e/node-css-url-parser" ,
2626 "author" : " s0ph1e" ,
2727 "license" : " MIT" ,
28- "dependencies" : {
29- "lodash" : " ^4.0.0"
30- },
3128 "devDependencies" : {
3229 "coveralls" : " ^2.11.2" ,
3330 "istanbul" : " ^0.4.5" ,
You can’t perform that action at this time.
0 commit comments