get-reading-time
Version:
Get Reading Time is a powerful, all-in-one text analysis tool designed for developers, content creators, and SEO professionals. It provides comprehensive insights into your text by calculating reading time, word count, character count, sentence count, and
174 lines (167 loc) • 6.46 kB
TypeScript
/**
* Represents the result of the text analysis.
*/
interface TextAnalysisResult {
/** Estimated reading time (minutes and seconds) */
readingTime: {
minutes: number;
seconds: number;
};
/** Total word count */
wordCount: number;
/** Total character count (excluding spaces) */
characterCount: number;
/** Total sentence count */
sentenceCount: number;
/** Total number of links found */
linkCount: number;
/** Array of detected links */
links: string[];
/** Flesch Reading Ease score */
readabilityScore: number;
/** Overall sentiment ("Positive", "Negative", or "Neutral") */
sentiment: string;
/** Top 5 SEO-friendly keywords or key phrases */
keywords: string[];
}
/**
* Analyzes the given text and returns various metrics, including reading time, word count,
* character count, sentence count, link count, readability score, sentiment, and keywords.
*
* @param text - The text to be analyzed.
* @param wordsPerMinute - The reading speed (optional, defaults to DEFAULT_READING_SPEED).
* @returns A TextAnalysisResult object with detailed analysis metrics.
*
* @throws {Error} Throws an error if the input text is not a valid string.
*
* @example
* ```typescript
* const text = "This is an example text with a link: https://example.com";
* const result = analyzeText(text);
* console.log(result.readingTime); // { minutes: 0.05, seconds: 3.00 }
* console.log(result.wordCount); // 10
* console.log(result.links); // ["https://example.com"]
* ```
*/
declare function analyzeText(text: string, wordsPerMinute?: number): TextAnalysisResult;
type ApiResponse$3 = {
/** The corrected text output */
content?: string;
/** Error message if the request fails */
error?: string;
/** HTTP Status Code (200 = Success, 500 = Error) */
status_code: number;
};
/**
* ✨ Fixes capitalization and punctuation in a given text.
*
* @param text - The text that needs correction.
* @returns A Promise resolving to an object with the corrected text or an error message.
*
* @example
* ```typescript
* const result = await getPunch("hELLo, HOW Are YOU?");
* console.log(result.content); // "Hello, how are you?"
* ```
*/
declare function getPunch(text: string): Promise<ApiResponse$3>;
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";
type ApiResponse$2 = {
/** The translated content */
content?: string;
/** Error message, if any */
error?: string;
/** Status code: 200 (success) or 500 (error) */
status_code: number;
};
/**
* 🌎 Translates a given text into a specified language.
*
* @param content - The text you want to translate.
* @param language - The target language for translation. Use one of the supported languages.
* @returns A Promise resolving to an object with the translated text or an error message.
*
* @example
* ```typescript
* const result = await langTrans("Hello, world!", "French");
* console.log(result.content); // "Bonjour, monde!"
* ```
*/
declare function langTrans(content: string, language: SupportedLanguages): Promise<ApiResponse$2>;
type ApiResponse$1 = {
/** The corrected text output */
content?: string;
/** Error message if the request fails */
error?: string;
/** HTTP Status Code (200 = Success, 500 = Error) */
status_code: number;
};
/**
* ✨ Fixes capitalization and punctuation in a given text.
*
* @param text - The text that needs correction.
* @returns A Promise resolving to an object with the corrected text or an error message.
*
* @example
* ```typescript
* const result = await askAI("How are you?").then((result) => result.content);;
* console.log(result.content); // "I am good"
* ```
*/
declare function askAI(text: string): Promise<ApiResponse$1>;
/**
* Represents the final response returned by the tableMaker function.
*/
interface ApiResponse {
/** The well-formatted Markdown table */
content?: string;
/** Error message if the request fails */
error?: string;
/** HTTP Status Code (200 = Success, 500 = Error) */
status_code: number;
}
/**
* Converts raw text data into a well-formatted Markdown table.
*
* This function sends the provided text to an AI service, which converts it into a
* clean, aligned Markdown table. The response is then post-processed to ensure that
* each column is uniformly spaced.
*
* @param content - The raw text data to be converted into a Markdown table.
* @returns A Promise that resolves to an object containing the formatted Markdown table or an error message.
*
* @example
* ```typescript
* const rawData = `This is bob and his age is 25 and lives in Los Angeles. Moreover, Alice lives in New York and her age is 30.`;
* const result = await tableMaker(rawData);
* console.log(result.content);
* // Expected output:
* // | Name | Age | City |
* // |-------|-----|-------------|
* // | Alice | 30 | New York |
* // | Bob | 25 | Los Angeles |
* ```
*/
declare function tableMaker(content: string): Promise<ApiResponse>;
interface GenerateResponse {
topic: string;
content: string;
}
declare class aiTexGen {
private apiUrl;
constructor();
private validateInputs;
/**
* Generates content based on the topic and word count.
*
* @param topic The topic for the article (e.g., "Artificial Intelligence").
* @param wordCount The maximum number of words for the article (default is 100).
* @param markdown If true, returns the content in Markdown format (default is false).
* @returns A promise that resolves with the topic and generated content.
*/
generateContent(topic: string, wordCount?: number, markdown?: boolean): Promise<GenerateResponse>;
private processContent;
private createErrorResponse;
private formatErrorDetails;
}
export { aiTexGen, analyzeText, askAI, getPunch, langTrans, tableMaker };