Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

net.thauvin.erik:readingtime

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

net.thauvin.erik:readingtime

Estimated Reading Time for Blog Posts, Articles, etc.

  • 0.9.2
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

License (3-Clause BSD) Kotlin Release Maven Central Nexus Snapshot

Quality Gate Status GitHub CI CircleCI

Estimated Reading Time for Blog Posts, Articles, etc.

A simple implementation of Medium's Read Time calculation.

Examples (TL;DR)

import net.thauvin.erik.readingtime.ReadingTime

// ...

val rt = ReadingTime(htmlText)
println(rt.calcEstimatedReadTime()) // eg: 2 min read

  • View bld or Gradle Examples

To get the estimated reading time in seconds use the calcReadingTimeInSec() function.

bld

To use with bld, include the following dependency in your build file:

repositories = List.of(MAVEN_CENTRAL);

scope(compile)
    .include(dependency("net.thauvin.erik:readingtime:0.9.2"));

Be sure to use the bld Kotlin extension in your project.

Gradle, Maven, etc.

To use with Gradle, include the following dependency in your build file:

repositories {
    mavenCentral()
}

dependencies {
    implementation("net.thauvin.erik:readingtime:0.9.2")
}

Instructions for using with Maven, Ivy, etc. can be found on Maven Central.

Properties

The following properties are available:

ReadingTime(
    text,
    wpm = 275,
    postfix = "min read",
    plural = "min read",
    excludeImages = false, 
    extra = 0,
    roundingMode = RoundingMode.HALF_EVEN
)

PropertyDescription
textThe text to be evaluated. (Required)
wpmThe words per minute reading average.
postfixThe value to be appended to the reading time.
pluralThe value to be appended if the reading time is more than 1 minute.
excludeImagesImages are excluded from the reading time when set.
extraAdditional seconds to be added to the total reading time.
roundingModeThe rounding mode to apply.

Functions

A couple of useful functions are also available:

ReadingTime.wordCount(htmlText) // Returns the count of words. (HTML stripped)
ReadingTime.imgCount(htmlText) // Returns the count of images. (HTML img tags)

JSP

A JSP tag is also available for easy incorporation into web applications:

<%@taglib uri="https://erik.thauvin.net/taglibs/readingtime" prefix="t"%>
<t:readingtime
    wpm="275"
    postfix="min read"
    plural="min read"
    excludeImages="false"
    extra="0">some_text</t:readingtime>

None of the attributes are required.

FAQs

Package last updated on 26 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc