Comparing version 0.3.0 to 0.4.0
79
index.js
@@ -8,6 +8,65 @@ var cheerio = require('cheerio') | ||
, _ = require('lodash') | ||
, cssParse = require('css-parse') | ||
; | ||
function cssURL (str) { | ||
var pre = str.indexOf('url(') | ||
if (pre !== -1) { | ||
var u = strip(str.slice(pre+'url('.length, str.indexOf(')', pre))) | ||
if (u.slice(0, 'data:'.length) === 'data:') return null | ||
return u | ||
} | ||
} | ||
function strip (str) { | ||
if (str[0] === '"' || str[0] === "'") str = str.slice(1) | ||
var end = str.length - 1 | ||
if (str[end] === '"' || str[end] === "'") str = str.slice(0, end) | ||
return str | ||
} | ||
function parseUrl (_url, from) { | ||
var u = url.parse(url.resolve(from, _url)) | ||
, str = u.protocol + '//' + u.host + u.pathname | ||
; | ||
if (u.query) str += u.search | ||
return str | ||
} | ||
function touch (_url, opts, cb) { | ||
opts.ee.emit('get', _url) | ||
function _walk (links, _url, cb) { | ||
links = _.difference(links, opts.links) | ||
links = _.uniq(links) | ||
opts.links = opts.links.concat(links) | ||
if (links.length === 0) cb(null, _url) | ||
else { | ||
var parallel = links.map(function (l) { return function (cb) {touch(l, opts, cb)} }) | ||
parallel.unshift(function (cb) {cb(null, _url)}) | ||
async.parallel(parallel, cb) | ||
} | ||
} | ||
function _css (str, _url) { | ||
var rules = cssParse(str).stylesheet.rules | ||
, links = [] | ||
; | ||
function _onrule (rule) { | ||
if (rule.declarations) { | ||
rule.declarations.forEach(function (dec) { | ||
if (dec.value) { | ||
var l = cssURL(dec.value) | ||
if (l) links.push(parseUrl(l, _url)) | ||
} | ||
}) | ||
} | ||
if (rule.rules) rule.rules.forEach(_onrule) | ||
} | ||
rules.forEach(_onrule) | ||
return links | ||
} | ||
request(_url, {timeout:opts.timeout, headers:{accept:mime.lookup(_url, 'text/html')}}, function (e, resp, body) { | ||
@@ -27,3 +86,3 @@ if (e) { | ||
function _do (txt) { | ||
var u = url.resolve(_url, txt) | ||
var u = parseUrl(txt, _url) | ||
try { | ||
@@ -47,12 +106,10 @@ var parsed = url.parse(u) | ||
links = _.difference(links, opts.links) | ||
links = _.uniq(links) | ||
opts.links = opts.links.concat(links) | ||
$('style').each(function (i, elem) { | ||
if (!elem.children.length) return | ||
links = links.concat(_css(elem.children[0].data, _url)) | ||
}) | ||
if (links.length === 0) cb(null, _url) | ||
else { | ||
var parallel = links.map(function (l) { return function (cb) {touch(l, opts, cb)} }) | ||
parallel.unshift(function (cb) {cb(null, _url)}) | ||
async.parallel(parallel, cb) | ||
} | ||
_walk(links, _url, cb) | ||
} else if (resp.headers['content-type'].indexOf('text/css') !== -1) { | ||
_walk(_css(body, _url), _url, cb) | ||
} else { | ||
@@ -89,2 +146,2 @@ cb(null, _url) | ||
module.exports = webtouch | ||
module.exports = webtouch |
{ | ||
"name": "webtouch", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Validate that a web site and all its required resources are available.", | ||
@@ -14,3 +14,4 @@ "main": "index.js", | ||
"mime": "~1.2.9", | ||
"request": "~2.22.0" | ||
"request": "~2.25.0", | ||
"css-parse": "~1.5.1" | ||
}, | ||
@@ -17,0 +18,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12435174
6
201
6
3
+ Addedcss-parse@~1.5.1
+ Addedasync@0.9.2(transitive)
+ Addedcss-parse@1.5.3(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedrequest@2.25.0(transitive)
- Removedform-data@0.0.8(transitive)
- Removedhawk@0.13.1(transitive)
- Removedhoek@0.8.5(transitive)
- Removedjson-stringify-safe@4.0.0(transitive)
- Removedrequest@2.22.0(transitive)
Updatedrequest@~2.25.0