Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webtouch

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webtouch - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

gource.mp4

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

5

package.json
{
"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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc