dale-chall-formula
Advanced tools
Comparing version 1.0.2 to 1.0.3
51
index.js
@@ -1,14 +0,14 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = daleChall; | ||
daleChall.gradeLevel = daleChallGradeLevel; | ||
module.exports = daleChall | ||
daleChall.gradeLevel = daleChallGradeLevel | ||
var DIFFICULT_WORD_WEIGHT = 0.1579; | ||
var WORD_WEIGHT = 0.0496; | ||
var DIFFICULT_WORD_THRESHOLD = 0.05; | ||
var PERCENTAGE = 100; | ||
var ADJUSTMENT = 3.6365; | ||
var difficultWordWeight = 0.1579 | ||
var wordWeight = 0.0496 | ||
var difficultWordThreshold = 0.05 | ||
var percentage = 100 | ||
var adjustment = 3.6365 | ||
/* Grade map associated with the scores. */ | ||
var GRADE_MAP = { | ||
// Grade map associated with the scores. | ||
var gradeMap = { | ||
4: [0, 4], | ||
@@ -22,35 +22,36 @@ 5: [5, 6], | ||
NaN: [NaN, NaN] | ||
}; | ||
} | ||
function daleChall(counts) { | ||
var percentageOfDifficultWords; | ||
var score; | ||
var percentageOfDifficultWords | ||
var score | ||
if (!counts || !counts.sentence || !counts.word) { | ||
return NaN; | ||
return NaN | ||
} | ||
percentageOfDifficultWords = (counts.difficultWord || 0) / counts.word; | ||
percentageOfDifficultWords = (counts.difficultWord || 0) / counts.word | ||
score = (DIFFICULT_WORD_WEIGHT * percentageOfDifficultWords * PERCENTAGE) + | ||
(WORD_WEIGHT * counts.word / counts.sentence); | ||
score = | ||
difficultWordWeight * percentageOfDifficultWords * percentage + | ||
(wordWeight * counts.word) / counts.sentence | ||
if (percentageOfDifficultWords > DIFFICULT_WORD_THRESHOLD) { | ||
score += ADJUSTMENT; | ||
if (percentageOfDifficultWords > difficultWordThreshold) { | ||
score += adjustment | ||
} | ||
return score; | ||
return score | ||
} | ||
/* Mapping between a dale-chall score and a U.S. grade level. */ | ||
// Mapping between a dale-chall score and a U.S. grade level. | ||
function daleChallGradeLevel(score) { | ||
score = Math.floor(score); | ||
score = Math.floor(score) | ||
if (score < 5) { | ||
score = 4; | ||
score = 4 | ||
} else if (score > 9) { | ||
score = 10; | ||
score = 10 | ||
} | ||
return GRADE_MAP[score].concat(); | ||
return gradeMap[score].concat() | ||
} |
{ | ||
"name": "dale-chall-formula", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Formula to detect the grade level of text according to the (revised) Dale-Chall Readability Formula (1995)", | ||
@@ -23,23 +23,37 @@ "license": "MIT", | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.1", | ||
"browserify": "^16.0.0", | ||
"is-nan": "^1.2.1", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^4.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"nyc": "^13.0.0", | ||
"prettier": "^1.14.2", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.22.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s daleChallFormula > dale-chall-formula.js", | ||
"build-mangle": "esmangle dale-chall-formula.js > dale-chall-formula.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s daleChallFormula -o dale-chall-formula.js", | ||
"build-mangle": "browserify . -s daleChallFormula -p tinyify -o dale-chall-formula.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -46,0 +60,0 @@ "ignores": [ |
@@ -19,20 +19,11 @@ # dale-chall-formula [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```js | ||
var daleChallFormula = require('dale-chall-formula'); | ||
var daleChallFormula = require('dale-chall-formula') | ||
daleChallFormula({ | ||
word: 30, | ||
sentence: 2, | ||
difficultWord: 6 | ||
}); | ||
// 4.41208 | ||
daleChallFormula({word: 30, sentence: 2, difficultWord: 6}) // => 4.41208 | ||
daleChallFormula({ | ||
word: 30, | ||
sentence: 2 | ||
}); | ||
// 0.744 | ||
daleChallFormula({word: 30, sentence: 2}) // => 0.744 | ||
daleChallFormula() // NaN | ||
daleChallFormula() // => NaN | ||
daleChallFormula.gradeLevel(daleChallFormula(30, 2, 6)) // [9, 10] | ||
daleChallFormula.gradeLevel(daleChallFormula(30, 2, 6)) // => [9, 10] | ||
``` | ||
@@ -64,15 +55,15 @@ | ||
* [`automated-readability`](https://github.com/wooorm/automated-readability) | ||
* [`automated-readability`](https://github.com/words/automated-readability) | ||
— Uses character count instead of error-prone syllable parser | ||
* [`coleman-liau`](https://github.com/wooorm/coleman-liau) | ||
* [`coleman-liau`](https://github.com/words/coleman-liau) | ||
— Uses letter count instead of an error-prone syllable parser | ||
* [`flesch`](https://github.com/wooorm/flesch) | ||
* [`flesch`](https://github.com/words/flesch) | ||
— Uses syllable count | ||
* [`flesch-kincaid`](https://github.com/wooorm/flesch-kincaid) | ||
* [`flesch-kincaid`](https://github.com/words/flesch-kincaid) | ||
— Like `flesch-formula`, returns U.S. grade levels | ||
* [`gunning-fog`](https://github.com/wooorm/gunning-fog) | ||
* [`gunning-fog`](https://github.com/words/gunning-fog) | ||
— Uses syllable count, needs POS-tagging and NER | ||
* [`smog-formula`](https://github.com/wooorm/smog-formula) | ||
* [`smog-formula`](https://github.com/words/smog-formula) | ||
— Like `gunning-fog-index`, without needing advanced NLP | ||
* [`spache-formula`](https://github.com/wooorm/spache-formula) | ||
* [`spache-formula`](https://github.com/words/spache-formula) | ||
— Uses a dictionary, suited for lower reading levels | ||
@@ -96,3 +87,3 @@ | ||
[license]: LICENSE | ||
[license]: license | ||
@@ -103,2 +94,2 @@ [author]: http://wooorm.com | ||
[list]: https://github.com/wooorm/dale-chall | ||
[list]: https://github.com/words/dale-chall |
7138
44
9
92