reading_time 1.0.0+2

reading_time #

Build Status

A small dart library that predicts ( more like calculates ) reading time like medium does . reading_time helps you calculate / estimate reading time for any text . It is very useful if you are building an article listing , news or blog like app or website with dart . It is the dart port of the original reading-time module ( FOR JS ) by Nicolas.

There are virtually no locale limit . It is using 200 (wpm) because an average reader can read 200 words per minute .

Example #

import 'package:reading_time/reading_time.dart';

// from https://www.lipsum.com/feed/html
const EXAMPLE_TEXT = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tempus tempor lacus id commodo. Nullam fermentum vitae nisi eget scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse elementum at sapien vitae rutrum. Vestibulum id ex et sem vehicula fermentum sed non tortor. Integer iaculis, justo et blandit sagittis, odio ligula molestie sem, eu lobortis metus nibh quis nibh. Fusce ornare varius tellus, ac porta est. In eleifend iaculis erat vel iaculis. Maecenas sit amet aliquet diam. Proin eu semper tortor. Maecenas accumsan rutrum erat, ornare ullamcorper ipsum hendrerit quis. Sed at pulvinar erat.

In et cursus dui. In viverra tincidunt maximus. Etiam sit amet lobortis mauris, eget sollicitudin augue. Mauris finibus felis nisl. Mauris id lorem blandit ligula faucibus rhoncus. Sed molestie ipsum id nisl vestibulum vehicula. Proin dictum mi iaculis velit aliquet rhoncus. Suspendisse elementum maximus velit, ut elementum sem cursus ac. Phasellus efficitur congue odio, sit amet suscipit lacus convallis pulvinar. Etiam posuere dolor at nunc bibendum venenatis. Nam ac justo risus. Etiam ac metus sit amet diam malesuada maximus. Quisque odio arcu, cursus eget suscipit id, hendrerit non nisl. Fusce lacinia eu ipsum non mattis.

Mauris bibendum pellentesque quam. Sed bibendum malesuada orci, vel aliquam sem. Nunc sit amet ante id eros finibus cursus eget pharetra mi. Quisque eleifend accumsan lorem, id interdum felis rhoncus quis. Morbi a auctor risus. Nam placerat, nisl dapibus commodo facilisis, tellus metus semper odio, vel fringilla nisi mi id sapien. Etiam eget turpis sed ante venenatis accumsan ut non velit. Integer ut tellus placerat, tempus erat sit amet, scelerisque turpis. Aliquam velit leo, dictum quis dictum vitae, congue a turpis. Integer gravida risus ante.

Aenean ac nunc lacinia, vehicula purus at, malesuada nulla. Sed fermentum ante eu nisl pulvinar vehicula. Phasellus sem ante, cursus ut nisl sit amet, sagittis mollis magna. Quisque dapibus blandit tincidunt. Donec condimentum leo viverra egestas lobortis. Nulla pharetra ex ex, non laoreet ligula sodales sed. Donec tortor elit, feugiat et nunc et, sagittis eleifend metus. Nullam erat turpis, tincidunt sed quam sit amet, condimentum tincidunt leo. Curabitur imperdiet pharetra libero a cursus. Donec massa nisi, faucibus nec ornare sed, eleifend at dolor. Cras ullamcorper auctor nisl in porta.

Maecenas eleifend lobortis lectus vitae porttitor. Suspendisse at ex nec ante lobortis lacinia. In id diam aliquet nunc rhoncus placerat quis et quam. Nulla ut egestas diam. Quisque varius, nisi eget ullamcorper tincidunt, lacus eros fringilla nunc, vitae faucibus lacus diam at leo. Cras magna enim, interdum eget consectetur non, volutpat sit amet ex. Quisque mollis eget risus ac aliquam. Integer ultricies lorem neque.
""";

main(List<String> args) {
  var reader = readingTime(EXAMPLE_TEXT);
  print(reader['words']); // 433
  print(reader['text']); // 2 min read
  print(reader['time']); // 129900.0
  print(reader['minutes']); // 2.165
}

If the text is too small , the text property will return 'less than a minute'

Args #

By default readingTime takes one positional argument and one optional wordsPerMinute argument which takes an int value. It will return a Map . You can check the code at "lib/reading_time.dart" file .

Map properties #

It returns a map , you can access it's properties like this readingTime(text)['text'] . Here are all the properties it exposes .

{
  'text': String,
  'minutes': double,
  'time': double,
  'words': int
}

1.0.0+2 #

  • Fixed code errors

1.0.0+1 #

  • Fixed readme

1.0.0 #

  • Dart 2.0 support!
  • Fallback for 0 min read

example/example.dart

import 'package:reading_time/reading_time.dart';

const EXAMPLE_TEXT = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tempus tempor lacus id commodo. Nullam fermentum vitae nisi eget scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse elementum at sapien vitae rutrum. Vestibulum id ex et sem vehicula fermentum sed non tortor. Integer iaculis, justo et blandit sagittis, odio ligula molestie sem, eu lobortis metus nibh quis nibh. Fusce ornare varius tellus, ac porta est. In eleifend iaculis erat vel iaculis. Maecenas sit amet aliquet diam. Proin eu semper tortor. Maecenas accumsan rutrum erat, ornare ullamcorper ipsum hendrerit quis. Sed at pulvinar erat.

In et cursus dui. In viverra tincidunt maximus. Etiam sit amet lobortis mauris, eget sollicitudin augue. Mauris finibus felis nisl. Mauris id lorem blandit ligula faucibus rhoncus. Sed molestie ipsum id nisl vestibulum vehicula. Proin dictum mi iaculis velit aliquet rhoncus. Suspendisse elementum maximus velit, ut elementum sem cursus ac. Phasellus efficitur congue odio, sit amet suscipit lacus convallis pulvinar. Etiam posuere dolor at nunc bibendum venenatis. Nam ac justo risus. Etiam ac metus sit amet diam malesuada maximus. Quisque odio arcu, cursus eget suscipit id, hendrerit non nisl. Fusce lacinia eu ipsum non mattis.

Mauris bibendum pellentesque quam. Sed bibendum malesuada orci, vel aliquam sem. Nunc sit amet ante id eros finibus cursus eget pharetra mi. Quisque eleifend accumsan lorem, id interdum felis rhoncus quis. Morbi a auctor risus. Nam placerat, nisl dapibus commodo facilisis, tellus metus semper odio, vel fringilla nisi mi id sapien. Etiam eget turpis sed ante venenatis accumsan ut non velit. Integer ut tellus placerat, tempus erat sit amet, scelerisque turpis. Aliquam velit leo, dictum quis dictum vitae, congue a turpis. Integer gravida risus ante.

Aenean ac nunc lacinia, vehicula purus at, malesuada nulla. Sed fermentum ante eu nisl pulvinar vehicula. Phasellus sem ante, cursus ut nisl sit amet, sagittis mollis magna. Quisque dapibus blandit tincidunt. Donec condimentum leo viverra egestas lobortis. Nulla pharetra ex ex, non laoreet ligula sodales sed. Donec tortor elit, feugiat et nunc et, sagittis eleifend metus. Nullam erat turpis, tincidunt sed quam sit amet, condimentum tincidunt leo. Curabitur imperdiet pharetra libero a cursus. Donec massa nisi, faucibus nec ornare sed, eleifend at dolor. Cras ullamcorper auctor nisl in porta.

Maecenas eleifend lobortis lectus vitae porttitor. Suspendisse at ex nec ante lobortis lacinia. In id diam aliquet nunc rhoncus placerat quis et quam. Nulla ut egestas diam. Quisque varius, nisi eget ullamcorper tincidunt, lacus eros fringilla nunc, vitae faucibus lacus diam at leo. Cras magna enim, interdum eget consectetur non, volutpat sit amet ex. Quisque mollis eget risus ac aliquam. Integer ultricies lorem neque.
""";

main(List<String> args) {
  var reader = readingTime(EXAMPLE_TEXT);
  print(reader['words']); // 433
  print(reader['text']); // 2 min read
  print(reader['time']); // 129900.0
  print(reader['minutes']); // 2.165
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  reading_time: ^1.0.0+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:reading_time/reading_time.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
10
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Aug 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:reading_time/reading_time.dart.

Health suggestions

Fix lib/reading_time.dart. (-1 points)

Analysis of lib/reading_time.dart reported 2 hints:

line 51 col 49: DO use curly braces for all flow control structures.

line 53 col 48: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.36.0 <3.0.0
Dev dependencies
test >=0.12.18