Check readability with retext. Applies Dale—Chall, Automated Readability, Coleman-Liau, Flesch, Gunning-Fog, SMOG, and Spache.
npm:
npm install retext-readability
var retext = require('retext');
var readability = require('retext-readability');
var report = require('vfile-reporter');
var doc = [
'The cat sat on the mat',
'',
'The constellation also contains an isolated neutron ',
'star—Calvera—and H1504+65, the hottest white dwarf yet ',
'discovered, with a surface temperature of 200,000 kelvin',
''
].join('\n');
By default, the target age is 16:
retext()
.use(readability)
.process(doc, function (err, file) {
console.log(report(err || file));
});
Yields:
3:1-5:57 warning Hard to read sentence (confidence: 4/7) retext-readability
⚠ 1 warning
...but ages can be set, for example, to 8:
retext()
.use(readability, {age: 6})
.process(doc, function (err, file) {
console.log(report(err || file));
});
Yields:
1:1-1:23 warning Hard to read sentence (confidence: 4/7) retext-readability
3:1-5:57 warning Hard to read sentence (confidence: 7/7) retext-readability
⚠ 1 warning
Detect possibly hard to read sentences.
age
(number
, default:16
) — Target age group. Note that the different algorithms provide varying results, so your milage may vary with people actually that age. 😉threshold
(number
, default:4 / 7
) — By default, 4 out of the 7 algorithms need to agree that a sentence is higher than the target age and whether it should be warned about. This can be modified by passing in a new threshold.minWords
(number
, default:5
) — Minimum number of words a sentence should have when warning. Most algorithms are designed to take a large sample of sentences to detect the body’s reading level. This plug-in, however, works on a per-sentence basis. This makes the results quite skewered when said sentence has, for example, a few long words or some unknown ones.