17 lines
668 B
JavaScript
17 lines
668 B
JavaScript
const fs = require('fs');
|
|
const h = fs.readFileSync('15-frontend.html', 'utf8');
|
|
let art = (h.match(/<article>([\s\S]*)<\/article>/) || [, ''])[1];
|
|
art = art.replace(/<pre[\s\S]*?<\/pre>/g, ' ')
|
|
.replace(/<nav class="pager">[\s\S]*?<\/nav>/g, ' ')
|
|
.replace(/<p class="foot">[\s\S]*?<\/p>/g, ' ')
|
|
.replace(/<p class="chapnav">[\s\S]*?<\/p>/g, ' ');
|
|
art = art.replace(/<[^>]+>/g, '').replace(/\s+/g, '');
|
|
let cjk = 0, ascii = 0, punct = 0, other = 0;
|
|
for (const ch of art) {
|
|
const c = ch.codePointAt(0);
|
|
if (c >= 0x4e00 && c <= 0x9fff) cjk++;
|
|
else if (c >= 0x20 && c <= 0x7e) ascii++;
|
|
else punct++;
|
|
}
|
|
console.log({ total: art.length, cjk, ascii, punct });
|