get-reading-time 1.0.3 → 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 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
- - **Reading Time**: Estimates how long it will take to read the given text based on a default or custom reading speed (words per minute).
9
-
10
- - **Word Count**: Counts the number of words in the text.
11
-
12
- - **Character Count**: Counts the number of characters (excluding spaces) in the text.
13
-
14
- - **Sentence Count**: Counts the number of sentences based on punctuation marks.
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
- ``` bash
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 = "This is an example of text. It contains words, sentences, and links like https://example.com.";
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 = analyzeText(text);
43
+ const result = analyzeText(text);
49
44
 
50
45
  // Analyze the text
51
46
  try {
52
- const result = analyzeText(text);
47
+ const result = analyzeText(text);
53
48
 
54
- // Output the analysis results
55
- console.log("Text Analysis Result:");
56
- console.log(JSON.stringify(result, null, 2));
49
+ // Output the analysis results
50
+ console.log("Text Analysis Result:");
51
+ console.log(JSON.stringify(result, null, 2));
57
52
  } catch (error) {
58
- // Narrow the type of error to Error
59
- if (error instanceof Error) {
60
- console.error("Error analyzing text:", error.message);
61
- } else {
62
- console.error("Unknown error:", error);
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
- json{
70
- "readingTime": {
71
- "minutes": 0.05,
72
- "seconds": 5.23
73
- },
74
- "wordCount": 13,
75
- "characterCount": 68,
76
- "sentenceCount": 2,
77
- "linkCount": 1,
78
- "readabilityScore": 78.5,
79
- "sentiment": "Positive",
80
- "keywords": ["example", "text", "words", "sentences", "links"]
65
+ {
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
- - text: The text to be analyzed (required).
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 @@ json{
93
92
 
94
93
  Analyzes the provided text and returns an object containing:
95
94
 
96
- - readingTime: Estimated reading time in minutes and seconds.
97
-
98
- - wordCount: Total word count.
99
-
100
- - characterCount: Total character count (excluding spaces).
101
-
102
- - sentenceCount: Total sentence count.
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
- - **cleanTextInput(text: string)**: Cleans and normalizes the input text.
116
-
117
- - **calculateWordCount(text: string)**: Counts the number of words.
118
-
119
- - **calculateCharacterCount(text: string)**: Counts the number of characters (excluding spaces).
120
-
121
- - **calculateSentenceCount(text: string)**: Counts the number of sentences based on punctuation.
122
-
123
- - **countLinks(text: string)**: Counts the number of links (URLs) in the text.
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)].
package/dist/index.d.mts CHANGED
@@ -7,6 +7,7 @@ interface TextAnalysisResult {
7
7
  characterCount: number;
8
8
  sentenceCount: number;
9
9
  linkCount: number;
10
+ links: string[];
10
11
  readabilityScore: number;
11
12
  sentiment: string;
12
13
  keywords: string[];
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ interface TextAnalysisResult {
7
7
  characterCount: number;
8
8
  sentenceCount: number;
9
9
  linkCount: number;
10
+ links: string[];
10
11
  readabilityScore: number;
11
12
  sentiment: string;
12
13
  keywords: string[];
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ function analyzeText(text, wordsPerMinute = DEFAULT_READING_SPEED) {
44
44
  const characterCount = calculateCharacterCount(cleanText);
45
45
  const sentenceCount = calculateSentenceCount(cleanText);
46
46
  const { minutes, seconds } = calculateReadingTime(wordCount, wordsPerMinute);
47
- const linkCount = countLinks(cleanText);
47
+ const links = countLinks(cleanText);
48
48
  const readabilityScore = calculateReadabilityScore(cleanText);
49
49
  const sentiment = analyzeSentiment(cleanText);
50
50
  const keywords = extractKeywords(cleanText);
@@ -53,7 +53,10 @@ function analyzeText(text, wordsPerMinute = DEFAULT_READING_SPEED) {
53
53
  wordCount,
54
54
  characterCount,
55
55
  sentenceCount,
56
- linkCount,
56
+ linkCount: links.length,
57
+ // Link count remains for backward compatibility
58
+ links,
59
+ // Add all links in the result
57
60
  readabilityScore,
58
61
  sentiment,
59
62
  keywords
@@ -81,7 +84,7 @@ function calculateReadingTime(wordCount, wordsPerMinute) {
81
84
  function countLinks(text) {
82
85
  const linkRegex = /https?:\/\/[^\s]+/g;
83
86
  const matches = text.match(linkRegex);
84
- return matches ? matches.length : 0;
87
+ return matches || [];
85
88
  }
86
89
  function calculateReadabilityScore(text) {
87
90
  const wordCount = calculateWordCount(text);
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ function analyzeText(text, wordsPerMinute = DEFAULT_READING_SPEED) {
10
10
  const characterCount = calculateCharacterCount(cleanText);
11
11
  const sentenceCount = calculateSentenceCount(cleanText);
12
12
  const { minutes, seconds } = calculateReadingTime(wordCount, wordsPerMinute);
13
- const linkCount = countLinks(cleanText);
13
+ const links = countLinks(cleanText);
14
14
  const readabilityScore = calculateReadabilityScore(cleanText);
15
15
  const sentiment = analyzeSentiment(cleanText);
16
16
  const keywords = extractKeywords(cleanText);
@@ -19,7 +19,10 @@ function analyzeText(text, wordsPerMinute = DEFAULT_READING_SPEED) {
19
19
  wordCount,
20
20
  characterCount,
21
21
  sentenceCount,
22
- linkCount,
22
+ linkCount: links.length,
23
+ // Link count remains for backward compatibility
24
+ links,
25
+ // Add all links in the result
23
26
  readabilityScore,
24
27
  sentiment,
25
28
  keywords
@@ -47,7 +50,7 @@ function calculateReadingTime(wordCount, wordsPerMinute) {
47
50
  function countLinks(text) {
48
51
  const linkRegex = /https?:\/\/[^\s]+/g;
49
52
  const matches = text.match(linkRegex);
50
- return matches ? matches.length : 0;
53
+ return matches || [];
51
54
  }
52
55
  function calculateReadabilityScore(text) {
53
56
  const wordCount = calculateWordCount(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "get-reading-time",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "/dist/index.js",
5
5
  "module": "/dist/index.mjs",
6
6
  "types": "/dist/index.d.ts",