Skip to content

Instantly share code, notes, and snippets.

@dralletje
Forked from JoelBesada/README.md
Last active November 30, 2015 16:05
Show Gist options
  • Save dralletje/c90995adc1d45f12ed3c to your computer and use it in GitHub Desktop.
Save dralletje/c90995adc1d45f12ed3c to your computer and use it in GitHub Desktop.
Backtick Example Command

Alert the amount of characters in the current selection

/* Just copied this from the web somewhere */
const word_count = word =>
word
.replace(/(^\s*)|(\s*$)/gi,"")
.replace(/[ ]{2,}/gi," ")
.replace(/\n /,"\n")
.split(' ').length
var selection = window.getSelection().toString()
var chars = selection.length
var words = word_count(selection)
alert(chars + " characters, " + word + " words.");
{
"name": "Count characters/words",
"description": "Count the amount of characters/words in your selection.",
"icon": "https://backtickio.s3.amazonaws.com/icons/backtick.png",
"link": "http://google.com"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment