browser-cli
Advanced tools
Comparing version 0.0.1 to 0.0.2
109
index.js
console.log('######'); | ||
var util = require('util'); | ||
var request = require('request'); | ||
var htmlparser = require('htmlparser'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var repl = require('repl'); | ||
setTimeout(function() { | ||
console.log('\033[2J\033[0f'); | ||
}, 2000); | ||
function clear() { | ||
console.log('\033[2J\033[0f'); | ||
} | ||
function getStatusString(status) { | ||
switch(status) { | ||
case -1: return 'error'; | ||
case 0: return 'none'; | ||
case 1: return 'request'; | ||
case 2: return 'parse'; | ||
case 3: return 'render'; | ||
} | ||
} | ||
function Window(option) { | ||
this.option = option; | ||
this.status = 0; | ||
this.tagid = 0; | ||
this.document = {}; | ||
this.trace = []; | ||
this.cursor = this.document; | ||
// Just for debugging | ||
this.rli = repl.start('>'); | ||
} | ||
util.inherits(Window, EventEmitter); | ||
Window.prototype.request = function(url) { | ||
var self = this; | ||
this.url = url; | ||
this.status = 1; | ||
this._render(); | ||
request(this.url, function(error, response, body) { | ||
self.status = response.statusCode === 200 ? 2 : -1; | ||
self._render()._parse(body); | ||
console.log(self.document); | ||
self.title = self.document.html.head.title.value.slice(0, 50)+'...'; | ||
self.body = self.document.html.body; | ||
self._render(); | ||
console.log(JSON.stringify(self.document, null,2)); | ||
}); | ||
}; | ||
Window.prototype._parse = function(content) { | ||
var self = this; | ||
var handler = new htmlparser.DefaultHandler(function(err, dom) { | ||
dom.forEach(parseDomNode); | ||
function parseDomNode(node) { | ||
// break branch | ||
if (node.type !== 'tag') { | ||
if (node.type === 'text') self.cursor.value = node.data; | ||
return; | ||
} | ||
if (!/html|head|title|body/i.test(node.name)) { | ||
node.name = util.format('%s_%d', node.name, self.tagid++); | ||
} | ||
self.cursor[node.name] = {}; | ||
if (node.children) { | ||
self.trace.push(self.cursor); | ||
self.cursor = self.cursor[node.name]; | ||
if (typeof node.children.forEach === 'function') | ||
node.children.forEach(parseDomNode); | ||
else | ||
parseDomNode(node.children); | ||
self.cursor = self.trace.pop(); | ||
} | ||
} | ||
}); | ||
var parser = new htmlparser.Parser(handler); | ||
parser.parseComplete(content); | ||
self.status = 3; | ||
}; | ||
Window.prototype.render = | ||
Window.prototype._render = function() { | ||
clear(); | ||
switch (this.status) { | ||
case -1: | ||
case 0: | ||
case 1: | ||
console.log(util.format(' \033[90murl: %s\033[0m', this.url)); | ||
break; | ||
case 2: | ||
console.log(util.format(' \033[36murl: %s\033[0m', this.url)); | ||
break; | ||
case 3: | ||
console.log(util.format(' \033[36murl: %s\033[0m', this.url)); | ||
console.log(util.format(' \033[36mtitle:\033[0m \033[90m%s\033[0m', this.title)); | ||
console.log(util.format(' \033[90m%s\033[0m', '==============================')); | ||
break; | ||
default: | ||
console.log('Null'); | ||
} | ||
return this; | ||
}; | ||
exports.Window = Window; |
{ | ||
"name": "browser-cli", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "html render in your shell", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "tape test/*.js", | ||
"demo": "node demo" | ||
}, | ||
@@ -17,2 +18,9 @@ "repository": { | ||
], | ||
"dependencies": { | ||
"request": "*", | ||
"htmlparser": "*" | ||
}, | ||
"devDependencies": { | ||
"tape": "*" | ||
}, | ||
"author": "Yorkie Neil <yorkiefixer@gmail.com>", | ||
@@ -19,0 +27,0 @@ "license": "MIT", |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3835
5
98
0
2
1
3
1
+ Addedhtmlparser@*
+ Addedrequest@*
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhtmlparser@1.7.7(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)