DEV Community

ryan senn
ryan senn

Posted on

Text readability library in Elm

I am happy to announce the release of an Elm package that will evaluate text according to the Dale-Chall and Coleman-Liau readability formula.

The package can be found in the official Elm package repository: https://package.elm-lang.org/packages/ryan-senn/elm-readability/latest/

The reason I created this package is part of a new project of mine. I tend to start to build tools etc. and give them up un-completed or un-polished. I have realised that the best way for me to push through is to have them released online. They basically have to leave my local environment or will be doomed and forgotten.

Part of my SEO strategy at work requires me to use a Word Counter tool. There are plenty of them online that I have used, but I wanted to create my own minimalistic version going forward. A quick prototype attempt turned out successful, so I set out to build this properly. This includes splitting the readability package out of the Word Counter project and open sourcing it.

The Word Counter tool is now online and it turned out just like I had hoped. I also took this opportunity to try out Bulma CSS.

The Dale-Chall formula uses a list of 3k common words that are identified as simple. Luckily for me, there was an NPM package that contained the list. One tricky bit is that the list doesn't include plurals, so I needed a script to generate a list including plurals. I was in luck again as there is a NPM package that does just that. All there was left to do is remove any duplicates and write an Elm file.

Another challenge was performance. Scanning the entire text, splitting it into words and search for the 6k simple words was a little heavy. Changing the simple words lookup from a List to a Dict String () helped big times.

The other improvement was adding a debounce. No need to re-calculate everything on every keystroke. I found that a debounce of 200ms was a good compromise for the statistics on the right. Lucky me again, Elm has a nice library for it: jinjor/elm-debounce.

My next goal is to polish a CLI tool that I built to find the google ranking of websites for certain keywords and display backlinks from other top 100 pages. It should work very nicely with Elixir/Phoenix web-sockets and Elm.

Top comments (1)

Collapse
 
nikoldimit profile image
Nikolas

This is super. We have compiled a list of libraries and APIs for readability and we will see how to extend to include this:

apyhub.com/blog/exploring-readabil...