From 96d0745da05c1052b69f3be91fe852315d84a274 Mon Sep 17 00:00:00 2001 From: Russell Warner Date: Thu, 15 Sep 2016 13:50:25 -0700 Subject: [PATCH] Added time to read functionality --- index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e2c1059..48587a9 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ // 1:1 API Fork of TextStatistics.php by Dave Child (Thanks mate!) // https://github.com/DaveChild/Text-Statistics - (function(glob) { function cleanText(text) { @@ -128,6 +127,19 @@ return (this.wordsWithThreeSyllables(text,countProperNouns) / this.wordCount(text)) * 100; }; + TextStatistics.prototype.timeToRead = function(text) { + var wordsPerMinute = 275; + var text = text ? cleanText(text) : this.text; + var textDifficulty = 1; // holding place for argument + var readTime = text.trim().split(/\s+/g).length / (wordsPerMinute * textDifficulty) + var message = "Less than a minute." + if (readTime < 1) { + return message; + } else { + return readTime.toFixed(2); + } + }; + TextStatistics.prototype.syllableCount = function(word) { var syllableCount = 0, prefixSuffixCount = 0,