Skip to content

Commit

Permalink
Merge pull request #107 from MasterOfTheTiger/words-per-minute
Browse files Browse the repository at this point in the history
Changed time calculation from characters per second to words per minute.
Users will need to update if they've set "characters per second" to a custom value.
  • Loading branch information
davidlday authored Jan 17, 2019
2 parents 5048982 + 4117ebf commit 5cbe50d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Counts the words and characters in your current document and displays them in th
- Option to exclude markdown `<!-- html comments -->` and `{>> critic markup comments <<}` from count
- Option to exclude markdown `> blockquotes` from count
- Option to show the total price per word for the document. Currency symbol can be changed in Settings.
- Option to display the time to read estimation based on character count
- Option to display the time to read estimation based on word count


![A screenshot of your spankin' package](https://cloud.githubusercontent.com/assets/584259/19187373/62f97ad8-8c8b-11e6-85aa-1282f94f509b.gif)
Expand Down
6 changes: 3 additions & 3 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ module.exports =
type: 'boolean'
default: false
order: 14
charactersPerSeconds:
title: 'Characters per second'
wordsPerMinute:
title: 'Words per minute'
description: 'This helps you estimating the duration of your text for reading.'
type: 'number'
default: 1000
default: 200
order: 15
showprice:
title: 'Show price estimation'
Expand Down
20 changes: 9 additions & 11 deletions lib/wordcount-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ class WordcountView
@wordregex = require('./wordcount-regex')();


charactersToHMS: (c) ->
# 1- Convert to seconds:
temp = c * 60
seconds = temp / atom.config.get('wordcount.charactersPerSeconds')
# 2- Extract hours:
#var hours = parseInt( seconds / 3600 ); // 3,600 seconds in 1 hour
seconds = seconds % 3600
# seconds remaining after extracting hours
# 3- Extract minutes:
charactersToHMS: (words) ->
# 1- calculate minutes and seconds for reading
wpm = atom.config.get('wordcount.wordsPerMinute')
minutes = words / wpm
seconds = minutes * 60
# 2- recalculate minutes based on seconds
minutes = parseInt(seconds / 60)
# 60 seconds in 1 minute
# 4- Keep only seconds not extracted to minutes:
# 3- Calculate remainder of seconds without minutes
seconds = Math.round(seconds % 60)
# 4- Return time
minutes = ('0' + minutes).slice(-2)
seconds = ('0' + seconds).slice(-2)
minutes + ':' + seconds
Expand All @@ -44,7 +42,7 @@ class WordcountView
str = ''
str += "<span class='wordcount-words'>#{wordCount || 0} W</span>" if atom.config.get 'wordcount.showwords'
str += ("<span class='wordcount-chars'>#{charCount || 0} C</span>") if atom.config.get 'wordcount.showchars'
str += ("<span class='wordcount-time'>#{ @charactersToHMS charCount || 0}</span>") if atom.config.get 'wordcount.showtime'
str += ("<span class='wordcount-time'>#{ @charactersToHMS wordCount || 0}</span>") if atom.config.get 'wordcount.showtime'
priceResult = wordCount*atom.config.get 'wordcount.wordprice'
str += ("<span class='wordcount-price'>#{priceResult.toFixed(2) || 0} </span>") + atom.config.get 'wordcount.currencysymbol' if atom.config.get 'wordcount.showprice'
@divWords.innerHTML = str
Expand Down

0 comments on commit 5cbe50d

Please sign in to comment.