GithubHelp home page GithubHelp logo

untemps / solid-readotron Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 0.0 858 KB

SolidJS component to display an estimated reading time

Home Page: https://solid-readotron.vercel.app/

Shell 1.28% JavaScript 81.34% HTML 4.79% CSS 12.59%
read-o-meter speed-reading-time reading-time reading-time-estimator reading-rates solid solidjs solid-js solid-components component

solid-readotron's Introduction

Svelte component to display an estimated reading time


npm GitHub Workflow Status Codecov

Demo

๐Ÿ”ดย LIVE DEMOย :red_circle:

Example

Installation

yarn add @untemps/solid-readotron

Usage

Basic usage

<main>
	<Readotron selector=".text" />
	<section class="text">...</section>
</main>

API

Props Type Default Description
selector string (required) Selector of the element which contains the content to parse. See Selector
lang string 'default' Lang of the content. See Lang
template string '%time% min read' Display template which contains dynamic tokens to be replaced by the parsed values. See Template

Selector

selector prop is mandatory as it points to which element contains the text content to parse. You can utilize any selector supported by the Web API querySelector function.
If several elements match the selector, it only parses the text of the first element in the array.

Lang

'lang' is an optional prop that designates the language of the text to parse. The component implements the @untemps/read-per-minute underhand package which returns an estimation based on the lang (language).
Reading rates by lang come from "How many words do we read per minute? A review and meta-analysis of reading rate" by Marc Brysbaert - Department of Experimental Psychology Ghent University

Lang Rate
default 200
ar 181
zh 260
nl 228
en 236
fi 195
fr 214
de 260
he 224
it 285
ko 226
es 278
sv 218

If a lang is not defined or the provided lang is not listed, the default value (200) will be applied.

Example

<main>
	<Readotron selector=".text" lang="en" />
	<section class="text">...</section>
</main>

Template

You can customize the Readotron display by using the template prop: a template is a string with one or more tokens delimited with %

Available tokens

Token Description
time Estimated reading time (in minutes)
words Number of words

Example

<main>
	<Readotron selector=".text" template="Reading Time: %time% minutes (%words% words)" />
	<section class="text">...</section>
</main>

Children

Another way to customize the Readotron display is to pass down a function as children.

Available arguments

Token Description
time Estimated reading time (in minutes)
words Number of words
error Parsing error if available

Example

<main>
    <Readotron selector=".text">
      {(time, words, error) => (
      <Show when={!error} fallback={<span class='error'>Oops</span>}>
        <span class='readotron'>
          {time} min read ({words} words)
        </span>
      </Show>``
      )}
    </Readotron>
    <section class="text">
        ...
    </section>
</main>

Development

The component can be served for development purpose on http://localhost:10001/ running:

yarn dev

Contributing

Contributions are warmly welcomed:

  • Fork the repository
  • Create a feature branch
  • Develop the feature AND write the tests (or write the tests AND develop the feature)
  • Commit your changes using Angular Git Commit Guidelines
  • Submit a Pull Request

solid-readotron's People

Contributors

semantic-release-bot avatar untemps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

solid-readotron's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.