get-reading-time 1.0.2 → 1.0.4
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 +18 -3
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ yarn add get-reading-time
|
|
|
39
39
|
|
|
40
40
|
Here’s how you can use the analyzeText function to analyze a piece of text:
|
|
41
41
|
```bash
|
|
42
|
-
import
|
|
42
|
+
import { analyzeText } from "get-reading-time/dist/index.js";
|
|
43
43
|
```
|
|
44
44
|
// Example input text
|
|
45
45
|
```javascript
|
|
@@ -47,11 +47,26 @@ const text = "This is an example of text. It contains words, sentences, and lin
|
|
|
47
47
|
|
|
48
48
|
const result = analyzeText(text);
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
// Analyze the text
|
|
51
|
+
try {
|
|
52
|
+
const result = analyzeText(text);
|
|
53
|
+
|
|
54
|
+
// Output the analysis results
|
|
55
|
+
console.log("Text Analysis Result:");
|
|
56
|
+
console.log(JSON.stringify(result, null, 2));
|
|
57
|
+
} 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
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
```
|
|
52
67
|
### Example Output
|
|
53
68
|
```json
|
|
54
|
-
|
|
69
|
+
{
|
|
55
70
|
"readingTime": {
|
|
56
71
|
"minutes": 0.05,
|
|
57
72
|
"seconds": 5.23
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
|
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
|
|
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
|
|
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
|
|
53
|
+
return matches || [];
|
|
51
54
|
}
|
|
52
55
|
function calculateReadabilityScore(text) {
|
|
53
56
|
const wordCount = calculateWordCount(text);
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "get-reading-time",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "/dist/index.js",
|
|
5
5
|
"module": "/dist/index.mjs",
|
|
6
6
|
"types": "/dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsup",
|
|
9
|
-
"start": "node dist/test.js"
|
|
9
|
+
"start": "node dist/test.js",
|
|
10
|
+
"lint": "tsc",
|
|
11
|
+
"prepare": "npm run build"
|
|
10
12
|
},
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|