File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ var spacheFormula = require('spache-formula');
32
32
*/
33
33
34
34
var DEFAULT_TARGET_AGE = 16 ;
35
+ var WORDYNESS_THRESHOLD = 5 ;
35
36
var SURENESS_THRESHOLD = 4 / 7 ;
36
37
var SURENESS_THRESHOLD_VERY = 5 / 7 ;
37
38
var SURENESS_THRESHOLD_DEFINITELY = 6 / 7 ;
@@ -132,6 +133,11 @@ function attacher(processor, options) {
132
133
var settings = options || { } ;
133
134
var targetAge = settings . age || DEFAULT_TARGET_AGE ;
134
135
var threshold = settings . threshold || SURENESS_THRESHOLD ;
136
+ var minWords = settings . minWords ;
137
+
138
+ if ( minWords === null || minWords === undefined ) {
139
+ minWords = WORDYNESS_THRESHOLD ;
140
+ }
135
141
136
142
return function ( tree , file ) {
137
143
/**
@@ -207,6 +213,10 @@ function attacher(processor, options) {
207
213
}
208
214
} ) ;
209
215
216
+ if ( wordCount < minWords ) {
217
+ return ;
218
+ }
219
+
210
220
counts = {
211
221
'complexPolysillabicWord' : complexPolysillabicWord ,
212
222
'polysillabicWord' : polysillabicWord ,
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ Detect possibly hard to read sentences.
93
93
be warned about. This can be modified by passing in a new
94
94
threshold.
95
95
96
+ * ` minWords ` (` number ` , default: ` 5 ` )
97
+ — Minimum number of words a sentence should have when warning.
98
+ Most algorithms are designed to take a large sample of
99
+ sentences to detect the body’s reading level. This plug-in,
100
+ however, works on a per-sentence basis. This makes the results
101
+ quite skewered when said sentence has, for example, a few long
102
+ words or some unknown ones.
103
+
96
104
## License
97
105
98
106
[ MIT] [ license ] © [ Titus Wormer] [ author ]
Original file line number Diff line number Diff line change @@ -146,5 +146,31 @@ test('readability', function (t) {
146
146
) ;
147
147
} ) ;
148
148
149
+ retext ( )
150
+ . use ( readability )
151
+ . process ( 'Honorificabilitudinitatibus.' , function ( err , file ) {
152
+ t . ifError ( err , 'should not fail (#8)' ) ;
153
+
154
+ t . deepEqual (
155
+ file . messages . map ( String ) ,
156
+ [ ] ,
157
+ 'should support minWords (default)'
158
+ ) ;
159
+ } ) ;
160
+
161
+ retext ( )
162
+ . use ( readability , {
163
+ 'minWords' : 0
164
+ } )
165
+ . process ( 'Honorificabilitudinitatibus.' , function ( err , file ) {
166
+ t . ifError ( err , 'should not fail (#8)' ) ;
167
+
168
+ t . deepEqual (
169
+ file . messages . map ( String ) ,
170
+ [ '1:1-1:29: Quite hard to read sentence' ] ,
171
+ 'should support `minWords` (config)'
172
+ ) ;
173
+ } ) ;
174
+
149
175
t . end ( ) ;
150
176
} ) ;
You can’t perform that action at this time.
0 commit comments