get-reading-time 1.3.2 → 1.3.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/dist/index.d.mts CHANGED
@@ -45,7 +45,7 @@ interface TextAnalysisResult {
45
45
  */
46
46
  declare function analyzeText(text: string, wordsPerMinute?: number): TextAnalysisResult;
47
47
 
48
- type ApiResponse$2 = {
48
+ type ApiResponse$3 = {
49
49
  /** The corrected text output */
50
50
  content?: string;
51
51
  /** Error message if the request fails */
@@ -65,10 +65,10 @@ type ApiResponse$2 = {
65
65
  * console.log(result.content); // "Hello, how are you?"
66
66
  * ```
67
67
  */
68
- declare function getPunch(text: string): Promise<ApiResponse$2>;
68
+ declare function getPunch(text: string): Promise<ApiResponse$3>;
69
69
 
70
70
  type SupportedLanguages = "English" | "Spanish" | "French" | "German" | "Finnish" | "Chinese" | "Japanese" | "Arabic" | "Russian" | "Hindi" | "Bengali" | "Portuguese" | "Korean" | "Italian" | "Dutch" | "Turkish" | "Polish" | "Swedish" | "Thai" | "Greek" | "Hebrew" | "Vietnamese" | "Indonesian" | "Filipino" | "Romanian" | "Czech" | "Hungarian" | "Danish" | "Norwegian" | "Ukrainian" | "Malay" | "Urdu" | "Persian (Farsi)" | "Tamil" | "Telugu" | "Marathi" | "Gujarati" | "Punjabi" | "Swahili" | "Hausa" | "Yoruba" | "Zulu" | "Burmese" | "Khmer" | "Lao";
71
- type ApiResponse$1 = {
71
+ type ApiResponse$2 = {
72
72
  /** The translated content */
73
73
  content?: string;
74
74
  /** Error message, if any */
@@ -89,7 +89,29 @@ type ApiResponse$1 = {
89
89
  * console.log(result.content); // "Bonjour, monde!"
90
90
  * ```
91
91
  */
92
- declare function langTrans(content: string, language: SupportedLanguages): Promise<ApiResponse$1>;
92
+ declare function langTrans(content: string, language: SupportedLanguages): Promise<ApiResponse$2>;
93
+
94
+ type ApiResponse$1 = {
95
+ /** The corrected text output */
96
+ content?: string;
97
+ /** Error message if the request fails */
98
+ error?: string;
99
+ /** HTTP Status Code (200 = Success, 500 = Error) */
100
+ status_code: number;
101
+ };
102
+ /**
103
+ * ✨ Fixes capitalization and punctuation in a given text.
104
+ *
105
+ * @param text - The text that needs correction.
106
+ * @returns A Promise resolving to an object with the corrected text or an error message.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const result = await askAI("How are you?").then((result) => result.content);;
111
+ * console.log(result.content); // "I am good"
112
+ * ```
113
+ */
114
+ declare function askAI(text: string): Promise<ApiResponse$1>;
93
115
 
94
116
  /**
95
117
  * Represents the final response returned by the tableMaker function.
@@ -148,4 +170,4 @@ declare class aiTexGen {
148
170
  private formatErrorDetails;
149
171
  }
150
172
 
151
- export { aiTexGen, analyzeText, getPunch, langTrans, tableMaker };
173
+ export { aiTexGen, analyzeText, askAI, getPunch, langTrans, tableMaker };
package/dist/index.d.ts CHANGED
@@ -45,7 +45,7 @@ interface TextAnalysisResult {
45
45
  */
46
46
  declare function analyzeText(text: string, wordsPerMinute?: number): TextAnalysisResult;
47
47
 
48
- type ApiResponse$2 = {
48
+ type ApiResponse$3 = {
49
49
  /** The corrected text output */
50
50
  content?: string;
51
51
  /** Error message if the request fails */
@@ -65,10 +65,10 @@ type ApiResponse$2 = {
65
65
  * console.log(result.content); // "Hello, how are you?"
66
66
  * ```
67
67
  */
68
- declare function getPunch(text: string): Promise<ApiResponse$2>;
68
+ declare function getPunch(text: string): Promise<ApiResponse$3>;
69
69
 
70
70
  type SupportedLanguages = "English" | "Spanish" | "French" | "German" | "Finnish" | "Chinese" | "Japanese" | "Arabic" | "Russian" | "Hindi" | "Bengali" | "Portuguese" | "Korean" | "Italian" | "Dutch" | "Turkish" | "Polish" | "Swedish" | "Thai" | "Greek" | "Hebrew" | "Vietnamese" | "Indonesian" | "Filipino" | "Romanian" | "Czech" | "Hungarian" | "Danish" | "Norwegian" | "Ukrainian" | "Malay" | "Urdu" | "Persian (Farsi)" | "Tamil" | "Telugu" | "Marathi" | "Gujarati" | "Punjabi" | "Swahili" | "Hausa" | "Yoruba" | "Zulu" | "Burmese" | "Khmer" | "Lao";
71
- type ApiResponse$1 = {
71
+ type ApiResponse$2 = {
72
72
  /** The translated content */
73
73
  content?: string;
74
74
  /** Error message, if any */
@@ -89,7 +89,29 @@ type ApiResponse$1 = {
89
89
  * console.log(result.content); // "Bonjour, monde!"
90
90
  * ```
91
91
  */
92
- declare function langTrans(content: string, language: SupportedLanguages): Promise<ApiResponse$1>;
92
+ declare function langTrans(content: string, language: SupportedLanguages): Promise<ApiResponse$2>;
93
+
94
+ type ApiResponse$1 = {
95
+ /** The corrected text output */
96
+ content?: string;
97
+ /** Error message if the request fails */
98
+ error?: string;
99
+ /** HTTP Status Code (200 = Success, 500 = Error) */
100
+ status_code: number;
101
+ };
102
+ /**
103
+ * ✨ Fixes capitalization and punctuation in a given text.
104
+ *
105
+ * @param text - The text that needs correction.
106
+ * @returns A Promise resolving to an object with the corrected text or an error message.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const result = await askAI("How are you?").then((result) => result.content);;
111
+ * console.log(result.content); // "I am good"
112
+ * ```
113
+ */
114
+ declare function askAI(text: string): Promise<ApiResponse$1>;
93
115
 
94
116
  /**
95
117
  * Represents the final response returned by the tableMaker function.
@@ -148,4 +170,4 @@ declare class aiTexGen {
148
170
  private formatErrorDetails;
149
171
  }
150
172
 
151
- export { aiTexGen, analyzeText, getPunch, langTrans, tableMaker };
173
+ export { aiTexGen, analyzeText, askAI, getPunch, langTrans, tableMaker };
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ var index_exports = {};
52
52
  __export(index_exports, {
53
53
  aiTexGen: () => aiTexGen,
54
54
  analyzeText: () => analyzeText,
55
+ askAI: () => askAI,
55
56
  getPunch: () => getPunch,
56
57
  langTrans: () => langTrans,
57
58
  tableMaker: () => tableMaker
@@ -250,9 +251,42 @@ function langTrans(content, language) {
250
251
  });
251
252
  }
252
253
 
253
- // src/utils/tableMaker.ts
254
+ // src/utils/askAI.ts
254
255
  var import_axios3 = __toESM(require("axios"));
255
256
  var API_URL3 = "https://ai.hackclub.com/chat/completions";
257
+ function askAI(text) {
258
+ return __async(this, null, function* () {
259
+ var _a, _b, _c, _d, _e, _f;
260
+ try {
261
+ const response = yield import_axios3.default.post(API_URL3, {
262
+ messages: [
263
+ {
264
+ role: "user",
265
+ content: `"${text}"`
266
+ }
267
+ ],
268
+ temperature: 0
269
+ // Keep corrections consistent
270
+ });
271
+ const correctedText = (_d = (_c = (_b = (_a = response.data.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message) == null ? void 0 : _c.content) == null ? void 0 : _d.trim();
272
+ if (!correctedText) {
273
+ console.warn("API returned no content.");
274
+ return { content: "No content generated", status_code: 200 };
275
+ }
276
+ return { content: correctedText, status_code: 200 };
277
+ } catch (error) {
278
+ console.error("Error :", error);
279
+ return {
280
+ error: ((_f = (_e = error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.error) || "Failed to get response from the AI server.",
281
+ status_code: 500
282
+ };
283
+ }
284
+ });
285
+ }
286
+
287
+ // src/utils/tableMaker.ts
288
+ var import_axios4 = __toESM(require("axios"));
289
+ var API_URL4 = "https://ai.hackclub.com/chat/completions";
256
290
  function tableMaker(content) {
257
291
  return __async(this, null, function* () {
258
292
  var _a, _b, _c, _d, _e, _f, _g;
@@ -260,7 +294,7 @@ function tableMaker(content) {
260
294
  return { error: "Input data cannot be empty.", status_code: 400 };
261
295
  }
262
296
  try {
263
- const response = yield import_axios3.default.post(API_URL3, {
297
+ const response = yield import_axios4.default.post(API_URL4, {
264
298
  messages: [
265
299
  {
266
300
  role: "user",
@@ -314,7 +348,7 @@ function formatMarkdownTable(table) {
314
348
  }
315
349
 
316
350
  // src/utils/aiTexGen.ts
317
- var import_axios4 = __toESM(require("axios"));
351
+ var import_axios5 = __toESM(require("axios"));
318
352
  var aiTexGen = class {
319
353
  // Constructor initializes the API URL
320
354
  constructor() {
@@ -345,7 +379,7 @@ var aiTexGen = class {
345
379
  this.validateInputs(topic, wordCount);
346
380
  const formatInstruction = markdown ? "Use proper Markdown formatting." : "Use plain text formatting.";
347
381
  const prompt = `Write a detailed article about ${topic}, aiming for a maximum of ${wordCount} words. ${formatInstruction}`;
348
- const response = yield import_axios4.default.post(this.apiUrl, {
382
+ const response = yield import_axios5.default.post(this.apiUrl, {
349
383
  messages: [
350
384
  {
351
385
  role: "user",
@@ -392,6 +426,7 @@ var aiTexGen = class {
392
426
  0 && (module.exports = {
393
427
  aiTexGen,
394
428
  analyzeText,
429
+ askAI,
395
430
  getPunch,
396
431
  langTrans,
397
432
  tableMaker
package/dist/index.mjs CHANGED
@@ -211,9 +211,42 @@ function langTrans(content, language) {
211
211
  });
212
212
  }
213
213
 
214
- // src/utils/tableMaker.ts
214
+ // src/utils/askAI.ts
215
215
  import axios3 from "axios";
216
216
  var API_URL3 = "https://ai.hackclub.com/chat/completions";
217
+ function askAI(text) {
218
+ return __async(this, null, function* () {
219
+ var _a, _b, _c, _d, _e, _f;
220
+ try {
221
+ const response = yield axios3.post(API_URL3, {
222
+ messages: [
223
+ {
224
+ role: "user",
225
+ content: `"${text}"`
226
+ }
227
+ ],
228
+ temperature: 0
229
+ // Keep corrections consistent
230
+ });
231
+ const correctedText = (_d = (_c = (_b = (_a = response.data.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message) == null ? void 0 : _c.content) == null ? void 0 : _d.trim();
232
+ if (!correctedText) {
233
+ console.warn("API returned no content.");
234
+ return { content: "No content generated", status_code: 200 };
235
+ }
236
+ return { content: correctedText, status_code: 200 };
237
+ } catch (error) {
238
+ console.error("Error :", error);
239
+ return {
240
+ error: ((_f = (_e = error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.error) || "Failed to get response from the AI server.",
241
+ status_code: 500
242
+ };
243
+ }
244
+ });
245
+ }
246
+
247
+ // src/utils/tableMaker.ts
248
+ import axios4 from "axios";
249
+ var API_URL4 = "https://ai.hackclub.com/chat/completions";
217
250
  function tableMaker(content) {
218
251
  return __async(this, null, function* () {
219
252
  var _a, _b, _c, _d, _e, _f, _g;
@@ -221,7 +254,7 @@ function tableMaker(content) {
221
254
  return { error: "Input data cannot be empty.", status_code: 400 };
222
255
  }
223
256
  try {
224
- const response = yield axios3.post(API_URL3, {
257
+ const response = yield axios4.post(API_URL4, {
225
258
  messages: [
226
259
  {
227
260
  role: "user",
@@ -275,7 +308,7 @@ function formatMarkdownTable(table) {
275
308
  }
276
309
 
277
310
  // src/utils/aiTexGen.ts
278
- import axios4 from "axios";
311
+ import axios5 from "axios";
279
312
  var aiTexGen = class {
280
313
  // Constructor initializes the API URL
281
314
  constructor() {
@@ -306,7 +339,7 @@ var aiTexGen = class {
306
339
  this.validateInputs(topic, wordCount);
307
340
  const formatInstruction = markdown ? "Use proper Markdown formatting." : "Use plain text formatting.";
308
341
  const prompt = `Write a detailed article about ${topic}, aiming for a maximum of ${wordCount} words. ${formatInstruction}`;
309
- const response = yield axios4.post(this.apiUrl, {
342
+ const response = yield axios5.post(this.apiUrl, {
310
343
  messages: [
311
344
  {
312
345
  role: "user",
@@ -352,6 +385,7 @@ var aiTexGen = class {
352
385
  export {
353
386
  aiTexGen,
354
387
  analyzeText,
388
+ askAI,
355
389
  getPunch,
356
390
  langTrans,
357
391
  tableMaker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "get-reading-time",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "main": "/dist/index.js",
5
5
  "module": "/dist/index.mjs",
6
6
  "types": "/dist/index.d.ts",
@@ -93,8 +93,7 @@
93
93
  },
94
94
  "dependencies": {
95
95
  "axios": "^1.7.9",
96
- "cohere-ai": "^7.15.0",
97
96
  "sentiment": "^5.0.2",
98
97
  "tsup": "^8.3.5"
99
98
  }
100
- }
99
+ }