-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (61 loc) · 3.07 KB
/
index.js
File metadata and controls
71 lines (61 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { encode, decode } = require('html-entities');
const clipboardy = require('clipboardy');
const request = require('request');
let document = (new JSDOM("")).window.document;
const dataString = `<sqlpp_request>
<clientid>dpriver-9094-8133-2031</clientid>
<dbvendor>mssql</dbvendor>
<outputfmt>html2</outputfmt>
<inputsql>${encode(process.argv[2].replace(/ /g, " "))}</inputsql>
<formatoptions>
<keywordcs>Uppercase</keywordcs>
<tablenamecs>Lowercase</tablenamecs>
<columnnamecs>Lowercase</columnnamecs>
<functioncs>InitCap</functioncs>
<datatypecs>Uppercase</datatypecs>
<variablecs>Unchanged</variablecs>
<aliascs>Unchanged</aliascs>
<quotedidentifiercs>Unchanged</quotedidentifiercs>
<identifiercs>Lowercase</identifiercs>
<lnbrwithcomma>after</lnbrwithcomma>
<liststyle>stack</liststyle>
<salign>sleft</salign>
<quotechar>"</quotechar>
<maxlenincm>80</maxlenincm>
</formatoptions>
</sqlpp_request>`;
const options = {
url: 'https://www.dpriver.com/cgi-bin/ppserver',
method: 'POST',
body: dataString
};
function callback(error, response, body) {
if (!error && response.statusCode === 200) {
let htmlCode = decode(body.substr(body.indexOf("<formattedsql>")));
//basic idea for this html to text code borrowed from
//https://www.textfixer.com/html/html-to-text.php
htmlCode = htmlCode.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
htmlCode = htmlCode.replace(/<title>/gi, "<title>META TAG (title): ");
htmlCode = htmlCode.replace(/<link/gi, "<llink");
htmlCode = htmlCode.replace(/<\/li><li>/gi, "</li>\n<li>");
htmlCode = htmlCode.replace(/<li/gi, "\n• <li");
htmlCode = htmlCode.replace(/<llink/gi, "<link");
htmlCode = htmlCode.replace(/<\/li>\n/gi, "</li>");
let div = document.createElement('div');
div.innerHTML = htmlCode;
htmlCode = div.textContent;
htmlCode = htmlCode.replace(/(\n\r|\n|\r)/gm, "\n");
htmlCode = htmlCode.replace(/(\n \n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n \n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n\n\n\n\n\n\n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n\n\n\n\n\n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n\n\n\n\n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n\n\n\n)/gm, "\n\n");
htmlCode = htmlCode.replace(/(\n\n\n)/gm, "\n\n");
htmlCode = htmlCode.trim();
clipboardy.writeSync(htmlCode.replace(/ /g, " "));
}
}
request(options, callback);