Documentation Index
Fetch the complete documentation index at: https://persian-tools.usestrict.dev/llms.txt
Use this file to discover all available pages before exploring further.
Text Analyzer
Analyze Persian text to extract detailed statistics including character count, word count, and line count.
Basic Usage
import { textAnalyzer } from "@persian-tools/persian-tools";
const text = `
سلام به همه
این یک متن آزمایشی است
`;
const stats = textAnalyzer(text);
console.log(stats);
// {
// characters: 35,
// words: 7,
// lines: 2
// }
API Reference
Object containing text statistics
Total character count (excluding whitespace)
Examples
Reading Time Estimator
import { textAnalyzer } from "@persian-tools/persian-tools";
const estimateReadingTime = (content: string): number => {
const analysis = textAnalyzer(content);
const wordsPerMinute = 200; // Average Persian reading speed
return Math.ceil(analysis.words / wordsPerMinute);
};
console.log(estimateReadingTime("سلام ".repeat(500)));
// 3 (minutes)
Content Summary
import { textAnalyzer } from "@persian-tools/persian-tools";
const generateContentSummary = (content: string) => {
const stats = textAnalyzer(content);
return {
summary: `${stats.words} کلمه، ${stats.characters} حرف`,
readingTime: Math.ceil(stats.words / 200),
lineCount: stats.lines,
};
};
import { textAnalyzer } from "@persian-tools/persian-tools";
const validateTextLength = (text: string, maxChars: number) => {
const stats = textAnalyzer(text);
return {
isValid: stats.characters <= maxChars,
remaining: maxChars - stats.characters,
current: stats.characters,
};
};
console.log(validateTextLength("سلام دنیا", 20));
// { isValid: true, remaining: 11, current: 9 }
Use Cases
Show reading time and stats:const article = {
title: 'عنوان مقاله',
content: '...',
stats: textAnalyzer(content),
readingTime: Math.ceil(textAnalyzer(content).words / 200)
};
Type Definition
interface TextAnalysis {
characters: number;
words: number;
lines: number;
}
function textAnalyzer(text: string): TextAnalysis;