Ask HN: How does Medium calculate how long it will take to read a post?

Medium and many other sites have a calculation for how long it might take you to read that particular post. How is that calculated and is there a library to add that to any site?