reading_time

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

reading-time

Go Reference

reading-time is a simple Go package to estimate the reading time of a text.

Installation

To install the package, use the following command:

go get github.com/lazarcloud/reading-time

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var FastEstimator = NewEstimator(250, 1, 10, 1, 8)

FastEstimator for faster reading.

View Source
var SlowEstimator = NewEstimator(150, 3, 15, 2, 12)

SlowEstimator for slower reading.

View Source
var StandardEstimator = NewEstimator(200, 2, 12, 1, 10)

StandardEstimator is a default estimator with common parameters for average reading speed.

Functions

This section is empty.

Types

type Estimator

type Estimator struct {
	WordsPerMinute    int
	SecondsPerLine    int
	BaseImageSeconds  int
	ImageSecondsDecay int
	ImageThreshold    int
}

Estimator holds the parameters to calculate the reading time.

func NewEstimator

func NewEstimator(wordsPerMinute, secondsPerLine, baseImageSeconds, imageSecondsDecay, imageThreshold int) *Estimator

NewEstimator creates a new Estimator object with custom parameters.

func (*Estimator) CalculateCodeTime

func (e *Estimator) CalculateCodeTime(totalLinesOfCode int) time.Duration

CalculateCodeTime calculates additional time based on lines of code.

Example
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with 3 seconds per line of code
	customEstimator := reading_time.NewEstimator(200, 3, 12, 1, 10)
	fmt.Println(customEstimator.CalculateCodeTime(10))
}
Output:
30s

func (*Estimator) CalculateImagesTime

func (e *Estimator) CalculateImagesTime(totalImages int) time.Duration

CalculateImagesTime calculates additional time based on the number of images.

Example (Basic)
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with 10 seconds base image time and decay of 2 seconds per image
	customEstimator := reading_time.NewEstimator(200, 2, 10, 2, 5)
	fmt.Println(customEstimator.CalculateImagesTime(5))
}
Output:
30s
Example (More)
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with 10 seconds base image time and decay of 2 seconds per image
	customEstimator := reading_time.NewEstimator(200, 2, 10, 2, 5)

	// Test case with a larger number of images
	fmt.Println(customEstimator.CalculateImagesTime(10))
}
Output:
40s

func (*Estimator) CalculateReadingTime

func (e *Estimator) CalculateReadingTime(totalWords, totalImages, totalLinesOfCode int) time.Duration

CalculateReadingTime calculates the total reading time.

Example (Basic)
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with 200 words per minute, 2 seconds per line, and base image time of 15 seconds
	customEstimator := reading_time.NewEstimator(200, 2, 15, 1, 8)
	readingTime := customEstimator.CalculateReadingTime(100, 5, 10)
	fmt.Println(readingTime)
}
Output:
1m55s
Example (Faster)
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Example with a faster reading custom estimator
	fasterEstimator := reading_time.NewEstimator(300, 1, 10, 1, 6)
	readingTimeFast := fasterEstimator.CalculateReadingTime(100, 5, 10)
	fmt.Println(readingTimeFast)
}
Output:
1m10s

func (*Estimator) CalculateWordsTime

func (e *Estimator) CalculateWordsTime(totalWords int) time.Duration

CalculateWordsTime calculates reading time based on word count.

Example
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with 250 words per minute
	customEstimator := reading_time.NewEstimator(250, 2, 12, 1, 10)
	fmt.Println(customEstimator.CalculateWordsTime(100))
}
Output:
24s
Example (Negative)
package main

import (
	"fmt"

	reading_time "github.com/lazarcloud/reading-time"
)

func main() {
	// Custom estimator with negative words per minute
	customEstimator := reading_time.NewEstimator(-250, 2, 12, 1, 10)
	fmt.Println(customEstimator.CalculateWordsTime(100))
}
Output:
0s

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL