### Install reading-time-estimator with NPM Source: https://github.com/lbenie/reading-time-estimator/blob/main/README.md Use this command to add the reading-time-estimator package to your project via NPM. ```bash npm install reading-time-estimator ``` -------------------------------- ### Install reading-time-estimator with Yarn Source: https://github.com/lbenie/reading-time-estimator/blob/main/README.md Use this command to add the reading-time-estimator package to your project via Yarn. ```bash yarn add reading-time-estimator ``` -------------------------------- ### Import ReadingTime with CommonJS Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Shows how to import and use the `readingTime` function in a CommonJS environment, with a concise example. ```javascript const { readingTime } = require('reading-time-estimator') const text = 'Some content to analyze' const result = readingTime(text, { wordsPerMinute: 200 }) console.log(result) ``` -------------------------------- ### Usage Example for German Locale Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use German translations with the readingTime function. ```typescript import { readingTime } from 'reading-time-estimator' import { de } from 'reading-time-estimator/i18n/de' const result = readingTime('Deutscher Text zum Lesen', { language: 'de', translations: { de } }) // Result: { minutes: ..., words: ..., text: '... Minute Lesedauer' or 'weniger als eine Minute Lesedauer' } ``` -------------------------------- ### Usage Example for Italian Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use the Italian locale for reading time estimation. Ensure the 'it' locale is included in the translations object. ```typescript import { readingTime } from 'reading-time-estimator' import { it } from 'reading-time-estimator/i18n/it' const result = readingTime('Testo in italiano da leggere', { language: 'it', translations: { it } }) // Result: { minutes: ..., words: ..., text: '... min di lettura' or 'meno di un minuto di lettura' } ``` -------------------------------- ### Usage Example for Brazilian Portuguese Locale Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use Brazilian Portuguese translations with the readingTime function. ```typescript import { readingTime } from 'reading-time-estimator' import { ptBr } from 'reading-time-estimator/i18n/pt-br' const result = readingTime('Texto em português brasileiro', { language: 'pt-br', translations: { 'pt-br': ptBr } }) // Result: { minutes: ..., words: ..., text: '... min de leitura' or 'menos de um minuto de leitura' } ``` -------------------------------- ### Example: Short English Text Calculation Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates the calculation for a short English text with default options. Shows the step-by-step breakdown leading to the final result. ```typescript readingTime("Hello world", {}) // Step 1: options = { wordsPerMinute: 200, language: "en", translations: {}, ... } // Step 2: words = 2 // Step 3: minutes = Math.round(2 / 200) = 0 // Step 4: isLessThanOne = true // Step 5: translation = en.less = "less than a minute read" // Step 6: text = "" + "less than a minute read" = "less than a minute read" // Step 7: return { minutes: 0, words: 2, text: "less than a minute read" } ``` -------------------------------- ### Tokenization Examples Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/tokenization-and-text-processing.md Illustrates how the tokenizer handles various text inputs, including English, contractions, accented characters, mixed scripts, CJK text, and numbers. ```typescript // Basic English "Hello world" → ["Hello", "world"] (2 tokens) ``` ```typescript // Contractions and hyphens "don't mother-in-law" → ["don't", "mother-in-law"] (2 tokens) ``` ```typescript // Accented characters "café naïve" → ["café", "naïve"] (2 tokens) ``` ```typescript // Mixed scripts "Hello 世界 world" → ["Hello", "世", "界", "world"] (4 tokens) ``` ```typescript // CJK heavy "中文テキスト" → ["中", "文", "テ", "キ", "ス", "ト"] (6 tokens) ``` ```typescript // Numbers "Price: $12.50 or €15,99" → ["Price", "12.50", "15", "99"] (4 tokens after stripping currency symbols via sanitizer) ``` -------------------------------- ### Provide Custom Translations (Simplified Chinese Example) Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md For Simplified Chinese, import `zhCn` and map it to the `'zh-cn'` key in the `translations` object. ```typescript import { readingTime } from 'reading-time-estimator' import { zhCn } from 'reading-time-estimator/i18n/zh-cn' const result = readingTime('文本', { language: 'zh-cn', translations: { 'zh-cn': zhCn } }) console.log(result.text) // Output: "小于一分钟" or "X分钟" ``` -------------------------------- ### Usage Example for Indonesian Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use the Indonesian locale for reading time estimation. Ensure the 'id' locale is included in the translations object. ```typescript import { readingTime } from 'reading-time-estimator' import { id } from 'reading-time-estimator/i18n/id' const result = readingTime('Teks dalam bahasa Indonesia untuk dibaca', { language: 'id', translations: { id } }) // Result: { minutes: ..., words: ..., text: '... menit dibaca' or 'kurang dari satu menit dibaca' } ``` -------------------------------- ### Usage Example for Vietnamese Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use the Vietnamese locale for reading time estimation. Ensure the 'vi' locale is included in the translations object. ```typescript import { readingTime } from 'reading-time-estimator' import { vi } from 'reading-time-estimator/i18n/vi' const result = readingTime('Văn bản tiếng Việt để đọc', { language: 'vi', translations: { vi } }) // Result: { minutes: ..., words: ..., text: '... phút đọc' or 'dưới một phút đọc' } ``` -------------------------------- ### Example: Resolve Translation - English Provided Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates retrieving the default translation string when English is explicitly provided in the translations map. ```typescript // English provided resolveTranslation('en', false, { en: {...} }) // → Returns en.default ``` -------------------------------- ### Examples for IsLessThanAMinute Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates the behavior of the `isLessThanAMinute` function with various minute inputs, showing its output for values below, at, and above one minute. Useful for verifying the function's logic. ```typescript isLessThanAMinute(0) // true isLessThanAMinute(0.5) // true isLessThanAMinute(0.99) // true isLessThanAMinute(1.0) // false isLessThanAMinute(1.5) // false isLessThanAMinute(10) // false ``` -------------------------------- ### Provide Custom Translations (Japanese Example) Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md To use Japanese, import the `ja` translation object and pass it within the `translations` map. ```typescript import { readingTime } from 'reading-time-estimator' import { ja } from 'reading-time-estimator/i18n/ja' const result = readingTime('テキスト', { language: 'ja', translations: { ja } }) console.log(result.text) // Output: "1分未満の読み取り" or "X最小読み取り" ``` -------------------------------- ### Example: Resolve Translation - English Requested, Not in Map Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates the fallback to built-in English when English is requested but no translations are provided at all. ```typescript // English requested but not in map (shouldn't happen) resolveTranslation('en', false, undefined) // → Uses built-in English ``` -------------------------------- ### Custom HTML Sanitizer Options Example Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/tokenization-and-text-processing.md Shows how to pass custom `htmlSanitizerOptions` to the `readingTime` function to control which HTML tags and attributes are allowed. ```typescript import { readingTime } from 'reading-time-estimator' const html = '
Hello world
' const result = readingTime(html, { htmlSanitizerOptions: { allowedTags: [], allowedAttributes: {} } }) // Output: { minutes: 0, words: 2, text: 'less than a minute read' } ``` -------------------------------- ### Provide Custom Translations (Spanish Example) Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md Import the Spanish translation object and include it in the `translations` map to set the output language to Spanish. ```typescript import { readingTime } from 'reading-time-estimator' import { es } from 'reading-time-estimator/i18n/es' const result = readingTime('Algo de texto', { language: 'es', translations: { es } }) console.log(result.text) // Output: "menos de un minuto leyendo" or "X min de lectura" ``` -------------------------------- ### TypeScript: Normalization Example Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/tokenization-and-text-processing.md Illustrates the effect of space mapping and whitespace collapsing on strings with ideographic spaces, and the effect of NFC normalization on accented characters. ```typescript // Input: "Hello world" (two ideographic spaces) // After step 2: "Hello world" (two ASCII spaces) // After step 5: "Hello world" (one ASCII space) // Input: "café̈" (e + combining diaeresis) // After step 1: "café" (canonical form) ``` -------------------------------- ### Single Locale Usage Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Use this example to analyze content with a single, specified locale. Ensure the locale is imported and passed to the readingTime function. ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' const result = readingTime('Text content', { language: 'en', translations: { en } }) ``` -------------------------------- ### Multilingual Blog Platform Reading Time Estimation Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/comprehensive-examples.md Integrate reading time estimation for a multilingual blog platform by providing the correct language and translations. This example demonstrates handling English, French, and Spanish content. ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' import { fr } from 'reading-time-estimator/i18n/fr' import { es } from 'reading-time-estimator/i18n/es' interface LocalizedPost { id: string title: string content: string language: 'en' | 'fr' | 'es' } class BlogService { private translations = { en, fr, es } getReadingTime(post: LocalizedPost) { return readingTime(post.content, { language: post.language, translations: this.translations }) } formatPost(post: LocalizedPost) { const reading = this.getReadingTime(post) return { ...post, readingTime: reading, meta: `${reading.words} words • ${reading.text}` } } } const service = new BlogService() const englishPost: LocalizedPost = { id: '1', title: 'TypeScript Guide', content: 'TypeScript is a typed superset of JavaScript...', language: 'en' } const formatted = service.formatPost(englishPost) console.log(formatted.meta) // "356 words • 2 min read" ``` -------------------------------- ### Markdown to Text Conversion Example Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/tokenization-and-text-processing.md Demonstrates using the `readingTime` function with Markdown input. The output shows the intermediate parsed HTML and the final sanitized text. ```typescript import { readingTime } from 'reading-time-estimator' const markdown = '# Title\n\nThis is **bold** and *italic* text.' const result = readingTime(markdown) // Parsed to: "This is bold and italic text.
" // Sanitized to: "Title This is bold and italic text." ``` -------------------------------- ### Usage Example for Japanese Locale Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Demonstrates how to import and use Japanese translations with the readingTime function. Supports Hiragana, Katakana, and Kanji characters, with each CJK character counted as one word. ```typescript import { readingTime } from 'reading-time-estimator' import { ja } from 'reading-time-estimator/i18n/ja' const result = readingTime('日本語のテキスト', { language: 'ja', translations: { ja } }) // Result: { minutes: ..., words: ..., text: '... 最小読み取り' or '1分未満の読み取り' } ``` -------------------------------- ### Multilingual Reading Time Estimation Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/README.md This example demonstrates how to estimate reading time in different languages by importing and using translation objects. Ensure the correct language code and translations are provided. ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' import { fr } from 'reading-time-estimator/i18n/fr' import { es } from 'reading-time-estimator/i18n/es' const translations = { en, fr, es } function getReadingTime(articleText, language) { return readingTime(articleText, { language, translations }) } console.log(getReadingTime(text, 'en').text) // "4 min read" console.log(getReadingTime(text, 'fr').text) // "4 min de lecture" console.log(getReadingTime(text, 'es').text) // "4 min de lectura" ``` -------------------------------- ### Example: Long French Text Calculation Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Illustrates the calculation for a longer French text, including custom language and translations. Shows how to import and use French translation data. ```typescript import { fr } from 'reading-time-estimator/i18n/fr' readingTime("Lorem ipsum dolor sit amet... (1000 words)", { language: 'fr', translations: { fr } }) // Step 1: options = { wordsPerMinute: 200, language: "fr", translations: { fr }, ... } // Step 2: words = 1000 // Step 3: minutes = Math.round(1000 / 200) = 5 // Step 4: isLessThanOne = false // Step 5: translation = fr.default = "min de lecture" // Step 6: text = "5 " + "min de lecture" = "5 min de lecture" // Step 7: return { minutes: 5, words: 1000, text: "5 min de lecture" } ``` -------------------------------- ### Multiple Locale Overrides with TranslationMap Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/types.md Example demonstrating how to override translations for multiple locales (French and Spanish). This allows for granular control over different language outputs. ```typescript // Multiple locales const translations: TranslationMap = { fr: { less: 'moins d\'une minute', default: 'min de lecture' }, es: { less: 'menos de un minuto', default: 'min de lectura' } } ``` -------------------------------- ### Example: Resolve Translation - French Provided Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates retrieving the default translation string when the requested language (French) is explicitly provided in the translations map. ```typescript // French provided resolveTranslation('fr', false, { fr: {...} }) // → Returns fr.default ``` -------------------------------- ### Analyze Text in All Supported Languages Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/comprehensive-examples.md This example shows how to analyze a given text across all 18 supported languages by aggregating all translation objects. It returns an array of results, one for each language. ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' import { fr } from 'reading-time-estimator/i18n/fr' import { es } from 'reading-time-estimator/i18n/es' import { zhCn } from 'reading-time-estimator/i18n/zh-cn' import { zhTw } from 'reading-time-estimator/i18n/zh-tw' import { ja } from 'reading-time-estimator/i18n/ja' import { de } from 'reading-time-estimator/i18n/de' import { ptBr } from 'reading-time-estimator/i18n/pt-br' import { tr } from 'reading-time-estimator/i18n/tr' import { ro } from 'reading-time-estimator/i18n/ro' import { bn } from 'reading-time-estimator/i18n/bn' import { sk } from 'reading-time-estimator/i18n/sk' import { cs } from 'reading-time-estimator/i18n/cs' import { ru } from 'reading-time-estimator/i18n/ru' import { vi } from 'reading-time-estimator/i18n/vi' import { it } from 'reading-time-estimator/i18n/it' import { id } from 'reading-time-estimator/i18n/id' import { hi } from 'reading-time-estimator/i18n/hi' const allTranslations = { en, fr, es, 'zh-cn': zhCn, 'zh-tw': zhTw, ja, de, 'pt-br': ptBr, tr, ro, bn, sk, cs, ru, vi, it, id, hi } function analyzeInAllLanguages(text) { const languages = Object.keys(allTranslations) return languages.map(lang => ({ language: lang, result: readingTime(text, { language, translations: allTranslations }) })) } const results = analyzeInAllLanguages('Some content to analyze') // Returns array with reading time in all 18 languages ``` -------------------------------- ### Import Locales for Tree-Shaking Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/README.md Import specific language locales from the i18n directory to enable tree-shaking and reduce bundle size. Examples include English, French, Spanish, and Chinese. ```typescript import { en } from 'reading-time-estimator/i18n/en' import { fr } from 'reading-time-estimator/i18n/fr' import { es } from 'reading-time-estimator/i18n/es' import { zhCn } from 'reading-time-estimator/i18n/zh-cn' ``` -------------------------------- ### Basic Reading Time Estimation Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/comprehensive-examples.md Use the simplest form of the `readingTime` function to get an estimate for an article. This requires only the article text as input. ```typescript import { readingTime } from 'reading-time-estimator' const article = 'JavaScript is a versatile programming language. It powers interactive web applications.' const result = readingTime(article) console.log(result) // { minutes: 0, words: 16, text: 'less than a minute read' } ``` -------------------------------- ### English Locale Usage Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Use the English locale by importing it and passing it to the readingTime function. This example shows how to set the language to 'en' and provide the English translations. ```typescript export const en: I18n ``` ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' const result = readingTime('Some text', { language: 'en', translations: { en } }) // Result: { minutes: ..., words: ..., text: '... min read' or 'less than a minute read' } ``` -------------------------------- ### French Locale Usage Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/locales.md Use the French locale by importing it and passing it to the readingTime function. This example demonstrates setting the language to 'fr' and providing the French translations. ```typescript export const fr: I18n ``` ```typescript import { readingTime } from 'reading-time-estimator' import { fr } from 'reading-time-estimator/i18n/fr' const result = readingTime('Du texte en français', { language: 'fr', translations: { fr } }) // Result: { minutes: ..., words: ..., text: '... min de lecture' or 'moins d\'une minute de lecture' } ``` -------------------------------- ### Example: Resolve Translation - French Requested, Not Provided Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Demonstrates the fallback mechanism when the requested language (French) is not found in the translations map. It will attempt to use `translations.en` or the built-in English. ```typescript // French requested but not provided resolveTranslation('fr', false, { es: {...} }) // → Falls back to translations.en if available, else built-in en ``` -------------------------------- ### Estimate Reading Time with Custom Markdown Parser Options Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/comprehensive-examples.md Calculate reading time for Markdown content using custom parser options. This example enables line breaks by setting `breaks: true`. ```typescript import { readingTime } from 'reading-time-estimator' const markdown = ` Line 1 Line 2 Line 3 ` // With breaks: true, newlines are converted toHello
' const result = readingTime(html, { htmlSanitizerOptions: { allowedTags: [], allowedAttributes: {} } }) console.log(result) // Output: { minutes: 0, words: 1, text: 'less than a minute read' } // Script tags completely removed, only "Hello" counted ``` -------------------------------- ### Provide Custom Translations (French Example) Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md To use a language other than English, import its translation object and provide it in the `translations` map. The `language` option must match the key in the `translations` map. ```typescript import { readingTime } from 'reading-time-estimator' import { fr } from 'reading-time-estimator/i18n/fr' const result = readingTime('Un peu de texte', { language: 'fr', translations: { fr } }) console.log(result.text) // Output: "moins d'une minute de lecture" or "X min de lecture" ``` -------------------------------- ### Edge Cases for GetNumberOfWords Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/implementation-details.md Illustrates how `getNumberOfWords` handles various edge cases, including empty input, whitespace-only input, double spaces, and CJK text. These examples are useful for testing and understanding the robustness of the word counting mechanism. ```typescript // Empty input → 0 words getNumberOfWords("") // Whitespace only → 0 words getNumberOfWords(" ") // Double spaces (tokenizes to ["word", "", "word"]) → 2 words getNumberOfWords("word word") // CJK text (each character is a token) → counts characters getNumberOfWords("中文") // → 2 ``` -------------------------------- ### Import Main Entry Point Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Illustrates how to import the main `readingTime` function and related types from the library. ```typescript import { readingTime } from 'reading-time-estimator' import type { ReadingTime, Options, SupportedLanguages } from 'reading-time-estimator' ``` -------------------------------- ### Configure User-Facing Blog with Custom Strings Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md Customize the output text by providing your own translations for 'less' and 'default' read time indicators. ```typescript import { readingTime } from 'reading-time-estimator' const customTranslations = { en: { less: '⚡ Quick read', default: 'min read' } } const result = readingTime('Article content...', { wordsPerMinute: 200, language: 'en', translations: customTranslations }) console.log(result.text) // "⚡ Quick read" or "X min read" ``` -------------------------------- ### Import Main Entry Point and Types Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/README.md Import the primary `readingTime` function and associated types like `ReadingTime` and `Options` from the main library entry point. ```typescript import { readingTime, type ReadingTime, type Options } from 'reading-time-estimator' ``` -------------------------------- ### Package.json Exports Configuration Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Defines the main and internationalization entry points for the library, specifying types and module formats for import and require. ```json { "exports": { ".": { "types": "./dist/types/reading-time-estimator.d.ts", "import": "./dist/index.js", "require": "./dist/index.cjs" }, "./i18n/en": { "types": "./dist/types/i18n/en.d.ts", "import": "./dist/i18n/en/locale.js", "require": "./dist/i18n/en/locale.cjs" }, "./i18n/fr": { ... }, "./i18n/es": { ... }, "./i18n/zh-cn": { ... }, "./i18n/zh-tw": { ... }, "./i18n/ja": { ... }, "./i18n/de": { ... }, "./i18n/pt-br": { ... }, "./i18n/tr": { ... }, "./i18n/ro": { ... }, "./i18n/bn": { ... }, "./i18n/sk": { ... }, "./i18n/cs": { ... }, "./i18n/ru": { ... }, "./i18n/vi": { ... }, "./i18n/it": { ... }, "./i18n/id": { ... }, "./i18n/hi": { ... }, "./package.json": "./package.json" } } ``` -------------------------------- ### Single Locale Override with TranslationMap Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/types.md Example of overriding translations for a single locale (French). Only the specified language's translations will be custom. ```typescript // Single locale override const translations: TranslationMap = { fr: { less: 'custom French less', default: 'custom French default' } } ``` -------------------------------- ### Configure for Multilingual Blog Platform Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/configuration-and-options.md Import and provide multiple language translations to handle content in different languages. A helper function can abstract the language selection. ```typescript import { readingTime } from 'reading-time-estimator' import { en } from 'reading-time-estimator/i18n/en' import { fr } from 'reading-time-estimator/i18n/fr' import { es } from 'reading-time-estimator/i18n/es' const translations = { en, fr, es } function getReadingTime(content, language) { return readingTime(content, { wordsPerMinute: 200, language, translations }) } console.log(getReadingTime('Some content', 'en')) // English output console.log(getReadingTime('Du contenu', 'fr')) // French output console.log(getReadingTime('Algún contenido', 'es')) // Spanish output ``` -------------------------------- ### Import Locales with CommonJS Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Import specific locale modules using CommonJS syntax. This is suitable for Node.js environments or older build setups. ```javascript const { en } = require('reading-time-estimator/i18n/en') const { fr } = require('reading-time-estimator/i18n/fr') ``` -------------------------------- ### Get Number of Words Function Signature Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/tokenization-and-text-processing.md Defines the function signature for counting words in a given string, accepting sanitizer and markdown options. ```typescript const getNumberOfWords = ( data: string, sanitizerOptions: ReadonlyHello world
' const result = readingTime(html) console.log(result) // Output: { minutes: 0, words: 2, text: 'less than a minute read' } // Parsed as: "Hello world" ``` -------------------------------- ### typesVersions for Locale Subpath Resolution Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Use the 'typesVersions' field in package.json to ensure correct type resolution for locale subpaths. ```json { "typesVersions": { "*": { "i18n/*": [ "./dist/types/i18n/*" ] } } } ``` -------------------------------- ### Handle Empty and Whitespace Content Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/comprehensive-examples.md The estimator correctly returns 0 minutes and 0 words for empty strings, whitespace-only strings, and strings with only newlines. ```typescript import { readingTime } from 'reading-time-estimator' const empty = '' const whitespace = ' ' const onlyNewlines = '\n\n\n' console.log(readingTime(empty)) // { minutes: 0, words: 0, text: 'less than a minute read' } console.log(readingTime(whitespace)) // { minutes: 0, words: 0, text: 'less than a minute read' } console.log(readingTime(onlyNewlines)) // { minutes: 0, words: 0, text: 'less than a minute read' } ``` -------------------------------- ### TypeScript Module Resolution Configuration Source: https://github.com/lbenie/reading-time-estimator/blob/main/_autodocs/exports-and-entry-points.md Configure TypeScript's module resolution to 'node' and module format to 'esnext' for optimal compatibility. ```json { "compilerOptions": { "moduleResolution": "node", "module": "esnext" } } ```