Socket
Socket
Sign inDemoInstall

dale-chall-formula

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 1.0.0

history.md

116

index.js

@@ -1,22 +0,39 @@

'use strict';
/**
* The constants as defined by the Dale--Chall Readability Formula.
* @author Titus Wormer
* @copyright 2014 Titus Wormer
* @license MIT
* @module dale-chall-formula
* @fileoverview Detect ease of reading according to the
* the (revised) Dale-Chall Readability Formula (1995).
*/
var DIFFICULT_WORD_WEIGHT,
WORD_WEIGHT,
DIFFICULT_WORD_THRESHOLD,
PERCENTAGE,
ADJUSTMENT;
'use strict';
DIFFICULT_WORD_WEIGHT = 0.1579;
WORD_WEIGHT = 0.0496;
DIFFICULT_WORD_THRESHOLD = 0.05;
PERCENTAGE = 100;
ADJUSTMENT = 3.6365;
/* Expose. */
module.exports = exports = daleChall;
exports.gradeLevel = daleChallGradeLevel;
/* The constants as defined by the Dale--Chall Readability Formula. */
var DIFFICULT_WORD_WEIGHT = 0.1579;
var WORD_WEIGHT = 0.0496;
var DIFFICULT_WORD_THRESHOLD = 0.05;
var PERCENTAGE = 100;
var ADJUSTMENT = 3.6365;
/* The grade map associated with the scores. */
var GRADE_MAP = {
4: [0, 4],
5: [5, 6],
6: [7, 8],
7: [9, 10],
8: [11, 12],
9: [13, 15],
10: [16, Infinity],
NaN: [NaN, NaN]
};
/**
* Get the grade level of a given value according to the Dale--Chall
* Readability Formula. More information is available at WikiPedia:
* Get the grade level of a given value according to the
* Dale--Chall Readability Formula. More information is
* available at WikiPedia:
*

@@ -31,66 +48,35 @@ * http://en.wikipedia.org/wiki/Dale–Chall_readability_formula

*/
function daleChall(counts) {
var percentageOfDifficultWords,
score;
var percentageOfDifficultWords;
var score;
if (!counts || !counts.sentence || !counts.word) {
return NaN;
}
if (!counts || !counts.sentence || !counts.word) {
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 = (DIFFICULT_WORD_WEIGHT * percentageOfDifficultWords * PERCENTAGE) +
(WORD_WEIGHT * counts.word / counts.sentence);
if (percentageOfDifficultWords > DIFFICULT_WORD_THRESHOLD) {
score += ADJUSTMENT;
}
if (percentageOfDifficultWords > DIFFICULT_WORD_THRESHOLD) {
score += ADJUSTMENT;
}
return score;
return score;
}
/**
* The grade map associated with the scores.
*/
var GRADE_MAP;
GRADE_MAP = {
4: [0, 4],
5: [5, 6],
6: [7, 8],
7: [9, 10],
8: [11, 12],
9: [13, 15],
10: [16, Infinity],
NaN: [NaN, NaN]
};
/**
* Simple 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;
} else if (score > 9) {
score = 10;
}
if (score < 5) {
score = 4;
} else if (score > 9) {
score = 10;
}
return GRADE_MAP[score].concat();
return GRADE_MAP[score].concat();
}
/**
* Export `daleChallGradeLevel`.
*/
daleChall.gradeLevel = daleChallGradeLevel;
/**
* Export `daleChall`.
*/
module.exports = daleChall;
{
"name": "dale-chall-formula",
"version": "0.1.0",
"version": "1.0.0",
"description": "Formula to detect the grade level of text according to the (revised) Dale-Chall Readability Formula (1995)",

@@ -12,23 +12,56 @@ "license": "MIT",

],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/dale-chall-formula.git"
},
"author": "Titus Wormer <tituswormer@gmail.com>",
"files": [
"index.js"
],
"repository": "https://github.com/wooorm/dale-chall-formula",
"bugs": "https://github.com/wooorm/dale-chall-formula/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
],
"dependencies": {},
"devDependencies": {
"eslint": "^0.10.0",
"istanbul": "^0.3.0",
"jscs": "^1.0.0",
"mocha": "^2.0.0"
"browserify": "^13.0.1",
"esmangle": "^1.0.1",
"is-nan": "^1.2.1",
"nyc": "^7.0.0",
"remark-cli": "^1.0.0",
"remark-comment-config": "^4.0.0",
"remark-github": "^5.0.0",
"remark-lint": "^4.0.0",
"remark-validate-links": "^4.0.0",
"tape": "^4.0.0",
"xo": "^0.16.0"
},
"scripts": {
"test": "node_modules/.bin/_mocha --reporter spec --check-leaks -u exports test.js",
"test-travis": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks -u exports test.js",
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -- test.js",
"lint-api": "node_modules/.bin/eslint index.js",
"lint-test": "node_modules/.bin/eslint test.js --env mocha",
"lint-style": "node_modules/.bin/jscs index.js test.js --reporter=inline",
"lint": "npm run lint-api && npm run lint-test && npm run lint-style",
"make": "npm run lint && npm run coverage"
"build-md": "remark . --quiet --frail",
"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",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"xo": {
"space": true,
"ignores": [
"dale-chall-formula.js",
"dale-chall-formula.min.js"
]
},
"remarkConfig": {
"output": true,
"plugins": {
"comment-config": null,
"github": null,
"lint": {
"list-item-spacing": false
},
"validate-links": null
},
"settings": {
"bullet": "*"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc