get-reading-time 1.2.0 → 1.2.2
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 +43 -0
- package/dist/index.d.mts +6 -11
- package/dist/index.d.ts +6 -11
- package/dist/index.js +23 -16
- package/dist/index.mjs +23 -16
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
# Text Analysis Tool
|
|
2
3
|
|
|
3
4
|
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.
|
|
@@ -13,6 +14,7 @@ A simple text analysis tool that provides insights into text such as reading tim
|
|
|
13
14
|
- **Sentiment Analysis**: Analyzes the sentiment of the text (Positive, Negative, or Neutral).
|
|
14
15
|
- **SEO-friendly Keywords**: Extracts the top 5 SEO-friendly keywords or key phrases (bi-grams and tri-grams) from the text.
|
|
15
16
|
- **aiTexGen**: Allows users to generate content based on a search prompt using the Cohere AI API, with a specified word count.
|
|
17
|
+
- **Automatic Punctuation and Capitalization**: Automatically adds proper punctuation and capitalizes the beginning of sentences in a provided text.
|
|
16
18
|
|
|
17
19
|
## Installation
|
|
18
20
|
|
|
@@ -126,6 +128,46 @@ testGenerateContent();
|
|
|
126
128
|
}
|
|
127
129
|
```
|
|
128
130
|
|
|
131
|
+
### Automatic Punctuation and Capitalization
|
|
132
|
+
|
|
133
|
+
You can now pass an article to the `analyzeText` function, and it will automatically fix punctuation and capitalize the first letter of sentences. This feature helps to improve the readability of raw text.
|
|
134
|
+
|
|
135
|
+
#### Example Code
|
|
136
|
+
Import the package and follow the steps:
|
|
137
|
+
```javascript
|
|
138
|
+
import { getPunch } from 'get-reading-time/dist/index.js';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
// Example to test with a string
|
|
143
|
+
const content = "once a lion a fox and a wolf went hunting they ultimately spotted a stag and killed him for their food while sharing the hunt quarter me this stag roared the lion and other animals skinned and cut the spoil into four equal parts";
|
|
144
|
+
async function GetPunch() {
|
|
145
|
+
try {
|
|
146
|
+
// Call the getPunch function with content
|
|
147
|
+
const result = await getPunch(content);
|
|
148
|
+
|
|
149
|
+
// Check the result and log it as a formatted JSON response
|
|
150
|
+
if (result.status_code === 200) {
|
|
151
|
+
console.log(JSON.stringify(result, null, 2));
|
|
152
|
+
} else {
|
|
153
|
+
console.error("Error:", JSON.stringify(result, null, 2));
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
// Handle unexpected errors
|
|
157
|
+
console.error("Unexpected Error:", error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Run the test
|
|
161
|
+
GetPunch();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Example Output
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"content": "Once a Lion, a Fox and a Wolf went hunting, they ultimately found a stag and killed him for their food while sharing the hunt quarter me. This stag roared the Lion and other animals skinned and cut the spoil into four equal parts.",
|
|
168
|
+
"status_code": 200
|
|
169
|
+
}
|
|
170
|
+
```
|
|
129
171
|
## Parameters
|
|
130
172
|
|
|
131
173
|
- text: The text to be analyzed (required).
|
|
@@ -162,6 +204,7 @@ Generates content based on the given topic and word count using the Cohere AI AP
|
|
|
162
204
|
- **extractNGrams(words: string[])**: Extracts bi-grams and tri-grams from the list of words.
|
|
163
205
|
- **isStopWord(word: string, stopWords: Set<string>)**: Checks if a word is a stop word to exclude from keyword extraction.
|
|
164
206
|
- **generateContent(words: string[])**: Genarate text based on the query and word limit.
|
|
207
|
+
- **autoPunctuateAndCapitalize(text: string)**: Adds punctuation and capitalization to the content.
|
|
165
208
|
|
|
166
209
|
## Contributing
|
|
167
210
|
|
package/dist/index.d.mts
CHANGED
|
@@ -14,18 +14,13 @@ interface TextAnalysisResult {
|
|
|
14
14
|
}
|
|
15
15
|
declare function analyzeText(text: string, wordsPerMinute?: number): TextAnalysisResult;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @returns {{ original: string, formatted: string }} - A JSON object with the original and formatted strings.
|
|
23
|
-
* @throws {TypeError} If the input is not a valid non-empty string.
|
|
24
|
-
*/
|
|
25
|
-
declare const getPunch: (article: string) => {
|
|
26
|
-
original: string;
|
|
27
|
-
formatted: string;
|
|
17
|
+
type ApiResponse = {
|
|
18
|
+
formatted_text?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
status_code: number;
|
|
21
|
+
content?: string;
|
|
28
22
|
};
|
|
23
|
+
declare function getPunch(next: string): Promise<ApiResponse>;
|
|
29
24
|
|
|
30
25
|
declare class AiTexGen {
|
|
31
26
|
private cohereClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,18 +14,13 @@ interface TextAnalysisResult {
|
|
|
14
14
|
}
|
|
15
15
|
declare function analyzeText(text: string, wordsPerMinute?: number): TextAnalysisResult;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @returns {{ original: string, formatted: string }} - A JSON object with the original and formatted strings.
|
|
23
|
-
* @throws {TypeError} If the input is not a valid non-empty string.
|
|
24
|
-
*/
|
|
25
|
-
declare const getPunch: (article: string) => {
|
|
26
|
-
original: string;
|
|
27
|
-
formatted: string;
|
|
17
|
+
type ApiResponse = {
|
|
18
|
+
formatted_text?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
status_code: number;
|
|
21
|
+
content?: string;
|
|
28
22
|
};
|
|
23
|
+
declare function getPunch(next: string): Promise<ApiResponse>;
|
|
29
24
|
|
|
30
25
|
declare class AiTexGen {
|
|
31
26
|
private cohereClient;
|
package/dist/index.js
CHANGED
|
@@ -186,22 +186,29 @@ function isStopWord(word, stopWords) {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// src/utils/getPunch.ts
|
|
189
|
-
var
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
189
|
+
var import_axios = __toESM(require("axios"));
|
|
190
|
+
var API_URL = "https://7732-34-19-6-112.ngrok-free.app";
|
|
191
|
+
var SECRET_CODE = "amrseccode";
|
|
192
|
+
function getPunch(next) {
|
|
193
|
+
return __async(this, null, function* () {
|
|
194
|
+
var _a;
|
|
195
|
+
try {
|
|
196
|
+
const response = yield import_axios.default.post(API_URL, {
|
|
197
|
+
secret_code: SECRET_CODE,
|
|
198
|
+
content: next
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
content: response.data.formatted_text || "No content returned",
|
|
202
|
+
status_code: 200
|
|
203
|
+
};
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
error: ((_a = error.response) == null ? void 0 : _a.data) || "Failed to get response from the server.",
|
|
207
|
+
status_code: 500
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
205
212
|
|
|
206
213
|
// src/utils/aiTexGen.ts
|
|
207
214
|
var import_cohere_ai = require("cohere-ai");
|
package/dist/index.mjs
CHANGED
|
@@ -149,22 +149,29 @@ function isStopWord(word, stopWords) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/utils/getPunch.ts
|
|
152
|
-
import
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
152
|
+
import axios from "axios";
|
|
153
|
+
var API_URL = "https://7732-34-19-6-112.ngrok-free.app";
|
|
154
|
+
var SECRET_CODE = "amrseccode";
|
|
155
|
+
function getPunch(next) {
|
|
156
|
+
return __async(this, null, function* () {
|
|
157
|
+
var _a;
|
|
158
|
+
try {
|
|
159
|
+
const response = yield axios.post(API_URL, {
|
|
160
|
+
secret_code: SECRET_CODE,
|
|
161
|
+
content: next
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
content: response.data.formatted_text || "No content returned",
|
|
165
|
+
status_code: 200
|
|
166
|
+
};
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return {
|
|
169
|
+
error: ((_a = error.response) == null ? void 0 : _a.data) || "Failed to get response from the server.",
|
|
170
|
+
status_code: 500
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
168
175
|
|
|
169
176
|
// src/utils/aiTexGen.ts
|
|
170
177
|
import { CohereClientV2 } from "cohere-ai";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "get-reading-time",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"main": "/dist/index.js",
|
|
5
5
|
"module": "/dist/index.mjs",
|
|
6
6
|
"types": "/dist/index.d.ts",
|
|
@@ -148,7 +148,6 @@
|
|
|
148
148
|
"dependencies": {
|
|
149
149
|
"axios": "^1.7.9",
|
|
150
150
|
"cohere-ai": "^7.15.0",
|
|
151
|
-
"compromise": "^14.14.3",
|
|
152
151
|
"sentiment": "^5.0.2",
|
|
153
152
|
"tsup": "^8.3.5"
|
|
154
153
|
}
|