Word count

Count the numbers of words and sentences in your text. Find the longest word and the average word length.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
({
  make: (content) => {
    const wrx = /[a-z-]+/gi
    const srx = / [a-z][^\.]+\.(\s+|$)/gi
    const wrd = content.match(wrx) || []
    const sen = content.match(srx) || []

    const title = wrd.length + " word" + (wrd.length === 1 ? "" : "s")

    let body = ""

    if (wrd.length && sen.length > 1) {
      const avg = +(wrd.length / (sen.length || 1)).toFixed(1)
      body += `There are ${sen.length} sentences, with an average length of ${avg} words per sentence. `
    }

    if (wrd.length) {
      const big = wrd.sort((a, b) => (a.length < b.length ? 1 : -1))[0]
      body += `The longest word is "${big}". `
      body += `It is ${big.length} letters long.`
    }

    return {
      type: "card",
      title,
      body,
    }
  },
})