/
index.js
80 lines (69 loc) · 2.01 KB
/
index.js
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
72
73
74
75
76
77
78
79
80
var binding ;
try {
binding = require('./build/Release/htmlstrip.node')
} catch(e){
binding = require('./build/Debug/htmlstrip.node')
}
module.exports.html_strip = function(html,options){
var input;
if (typeof html == 'string'){
input = Buffer.from(html,'utf-16le');
} else if (html instanceof Buffer){
input = html;
} else {
input = Buffer.from(html.toString(),'utf-16le');
}
var buf = binding.html_strip(input, input.length, options);
return buf.toString('utf-16le',0,buf._charsWritten*2);
}
module.exports.html_strip_with_hints = function(html,options){
var input;
if (typeof html == 'string'){
input = Buffer.from(html,'utf-16le');
} else if (html instanceof Buffer){
input = html;
} else {
input = Buffer.from(html.toString(),'utf-16le');
}
var buf = binding.html_strip(input, input.length, options);
return {
text: buf.toString('utf-16le',0,buf._charsWritten*2),
hints: buf.tag_hints
};
}
module.exports.html_entities_decode = function(html){
var input;
if (typeof html == 'string'){
input = Buffer.from(html,'utf-16le');
} else if (html instanceof Buffer){
input = html;
} else {
input = Buffer.from(html.toString(),'utf-16le');
}
var buf = binding.html_entities_decode(input, input.length);
return buf.toString('utf-16le',0,buf._charsWritten*2);
}
module.exports.accented_chars_norm = function(html){
var input;
if (typeof html == 'string'){
input = Buffer.from(html,'utf-16le');
} else if (html instanceof Buffer){
input = html;
} else {
input = Buffer.from(html.toString(),'utf-16le');
}
var buf = binding.accented_chars_norm(input, input.length);
return buf.toString('utf-16le',0,buf._charsWritten*2);
}
module.exports.accented_chars_strip = function(html){
var input;
if (typeof html == 'string'){
input = Buffer.from(html,'utf-16le');
} else if (html instanceof Buffer){
input = html;
} else {
input = Buffer.from(html.toString(),'utf-16le');
}
var buf = binding.accented_chars_strip(input, input.length);
return buf.toString('utf-16le',0,buf._charsWritten*2);
}