get-reading-time 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -84
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
|
|
2
1
|
# Text Analysis Tool
|
|
3
2
|
|
|
4
3
|
A simple text analysis tool that provides insights into text such as reading time, word count, sentiment, readability score, link count, and SEO-friendly keywords.
|
|
5
4
|
|
|
6
5
|
## Features
|
|
7
6
|
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
- **Link Count**: Detects and counts the number of URLs in the text.
|
|
17
|
-
|
|
18
|
-
- **Readability Score**: Calculates the Flesch Reading Ease score to evaluate the text's readability.
|
|
19
|
-
|
|
20
|
-
- **Sentiment Analysis**: Analyzes the sentiment of the text (Positive, Negative, or Neutral).
|
|
21
|
-
|
|
22
|
-
- **SEO-friendly Keywords**: Extracts the top 5 SEO-friendly keywords or key phrases (bi-grams and tri-grams) from the text.
|
|
23
|
-
|
|
7
|
+
- **Reading Time**: Estimates how long it will take to read the given text based on a default or custom reading speed (words per minute).
|
|
8
|
+
- **Word Count**: Counts the number of words in the text.
|
|
9
|
+
- **Character Count**: Counts the number of characters (excluding spaces) in the text.
|
|
10
|
+
- **Sentence Count**: Counts the number of sentences based on punctuation marks.
|
|
11
|
+
- **Link Count**: Detects and counts the number of URLs in the text.
|
|
12
|
+
- **Readability Score**: Calculates the Flesch Reading Ease score to evaluate the text's readability.
|
|
13
|
+
- **Sentiment Analysis**: Analyzes the sentiment of the text (Positive, Negative, or Neutral).
|
|
14
|
+
- **SEO-friendly Keywords**: Extracts the top 5 SEO-friendly keywords or key phrases (bi-grams and tri-grams) from the text.
|
|
24
15
|
|
|
25
16
|
## Installation
|
|
26
17
|
|
|
27
18
|
To install the package from npm, run:
|
|
28
|
-
|
|
19
|
+
|
|
20
|
+
```bash
|
|
29
21
|
npm i get-reading-time
|
|
30
22
|
```
|
|
31
23
|
|
|
32
|
-
|
|
33
24
|
Or using yarn:
|
|
25
|
+
|
|
34
26
|
```bash
|
|
35
27
|
yarn add get-reading-time
|
|
36
28
|
```
|
|
@@ -38,54 +30,61 @@ yarn add get-reading-time
|
|
|
38
30
|
## Usage
|
|
39
31
|
|
|
40
32
|
Here’s how you can use the analyzeText function to analyze a piece of text:
|
|
33
|
+
|
|
41
34
|
```bash
|
|
42
35
|
import { analyzeText } from "get-reading-time/dist/index.js";
|
|
43
36
|
```
|
|
37
|
+
|
|
44
38
|
// Example input text
|
|
39
|
+
|
|
45
40
|
```javascript
|
|
46
|
-
const text =
|
|
41
|
+
const text = `This is an example of text. It contains words, sentences, and links like there are https://linkedin.com/in/06nurahmed https://github.com/nurahmed123`;
|
|
47
42
|
|
|
48
|
-
const result =
|
|
43
|
+
const result = analyzeText(text);
|
|
49
44
|
|
|
50
45
|
// Analyze the text
|
|
51
46
|
try {
|
|
52
|
-
|
|
47
|
+
const result = analyzeText(text);
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
// Output the analysis results
|
|
50
|
+
console.log("Text Analysis Result:");
|
|
51
|
+
console.log(JSON.stringify(result, null, 2));
|
|
57
52
|
} catch (error) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
// Narrow the type of error to Error
|
|
54
|
+
if (error instanceof Error) {
|
|
55
|
+
console.error("Error analyzing text:", error.message);
|
|
56
|
+
} else {
|
|
57
|
+
console.error("Unknown error:", error);
|
|
58
|
+
}
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
```
|
|
61
|
+
|
|
67
62
|
### Example Output
|
|
63
|
+
|
|
68
64
|
```json
|
|
69
65
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
"readingTime": {
|
|
67
|
+
"minutes": 0.09,
|
|
68
|
+
"seconds": 5.1
|
|
69
|
+
},
|
|
70
|
+
"wordCount": 17,
|
|
71
|
+
"characterCount": 132,
|
|
72
|
+
"sentenceCount": 3,
|
|
73
|
+
"linkCount": 2,
|
|
74
|
+
"links": [
|
|
75
|
+
"https://linkedin.com/in/06nurahmed",
|
|
76
|
+
"https://github.com/nurahmed123"
|
|
77
|
+
],
|
|
78
|
+
"readabilityScore": 21.93039215686275,
|
|
79
|
+
"sentiment": "Neutral",
|
|
80
|
+
"keywords": ["example", "text.", "contains", "words,", "sentences,"]
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
|
+
|
|
83
84
|
## Parameters
|
|
84
85
|
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
- wordsPerMinute: The reading speed in words per minute (optional, default is 200 words per minute).
|
|
88
|
-
|
|
86
|
+
- text: The text to be analyzed (required).
|
|
87
|
+
- wordsPerMinute: The reading speed in words per minute (optional, default is 200 words per minute).
|
|
89
88
|
|
|
90
89
|
## Functions
|
|
91
90
|
|
|
@@ -93,45 +92,27 @@ try {
|
|
|
93
92
|
|
|
94
93
|
Analyzes the provided text and returns an object containing:
|
|
95
94
|
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
-
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
|
|
104
|
-
- linkCount: Number of links (URLs) in the text.
|
|
105
|
-
|
|
106
|
-
- readabilityScore: Flesch Reading Ease score (higher is easier to read).
|
|
107
|
-
|
|
108
|
-
- sentiment: Sentiment of the text (Positive, Negative, or Neutral).
|
|
109
|
-
|
|
110
|
-
- keywords: Top 5 SEO-friendly keywords or key phrases.
|
|
111
|
-
|
|
95
|
+
- readingTime: Estimated reading time in minutes and seconds.
|
|
96
|
+
- wordCount: Total word count.
|
|
97
|
+
- characterCount: Total character count (excluding spaces).
|
|
98
|
+
- sentenceCount: Total sentence count.
|
|
99
|
+
- linkCount: Number of links (URLs) in the text.
|
|
100
|
+
- readabilityScore: Flesch Reading Ease score (higher is easier to read).
|
|
101
|
+
- sentiment: Sentiment of the text (Positive, Negative, or Neutral).
|
|
102
|
+
- keywords: Top 5 SEO-friendly keywords or key phrases.
|
|
112
103
|
|
|
113
104
|
### Helper Functions
|
|
114
105
|
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
|
|
125
|
-
- **calculateReadabilityScore(text: string)**: Calculates the Flesch Reading Ease score.
|
|
126
|
-
|
|
127
|
-
- **analyzeSentiment(text: string)**: Analyzes sentiment using Sentiment.js.
|
|
128
|
-
|
|
129
|
-
- **extractKeywords(text: string)**: Extracts the top 5 SEO-friendly keywords or key phrases.
|
|
130
|
-
|
|
131
|
-
- **extractNGrams(words: string[])**: Extracts bi-grams and tri-grams from the list of words.
|
|
132
|
-
|
|
133
|
-
- **isStopWord(word: string, stopWords: Set<string>)**: Checks if a word is a stop word to exclude from keyword extraction.
|
|
134
|
-
|
|
106
|
+
- **cleanTextInput(text: string)**: Cleans and normalizes the input text.
|
|
107
|
+
- **calculateWordCount(text: string)**: Counts the number of words.
|
|
108
|
+
- **calculateCharacterCount(text: string)**: Counts the number of characters (excluding spaces).
|
|
109
|
+
- **calculateSentenceCount(text: string)**: Counts the number of sentences based on punctuation.
|
|
110
|
+
- **countLinks(text: string)**: Counts the number of links (URLs) in the text.
|
|
111
|
+
- **calculateReadabilityScore(text: string)**: Calculates the Flesch Reading Ease score.
|
|
112
|
+
- **analyzeSentiment(text: string)**: Analyzes sentiment using Sentiment.js.
|
|
113
|
+
- **extractKeywords(text: string)**: Extracts the top 5 SEO-friendly keywords or key phrases.
|
|
114
|
+
- **extractNGrams(words: string[])**: Extracts bi-grams and tri-grams from the list of words.
|
|
115
|
+
- **isStopWord(word: string, stopWords: Set<string>)**: Checks if a word is a stop word to exclude from keyword extraction.
|
|
135
116
|
|
|
136
117
|
## Contributing
|
|
137
118
|
|
|
@@ -143,4 +124,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
143
124
|
|
|
144
125
|
## Contact
|
|
145
126
|
|
|
146
|
-
For any questions or inquiries, feel free to contact [[06nurahmed@gmail.com](06nurahmed@gmail.com)].
|
|
127
|
+
For any questions or inquiries, feel free to contact [[06nurahmed@gmail.com](06nurahmed@gmail.com)].
|