textstat-ts
v1.0.2
Published
TypeScript port of textstat library for text statistics and readability metrics
Downloads
289
Maintainers
Readme
textstat-ts
TypeScript port of the textstat Python library (https://github.com/textstat/textstat) for calculating various text statistics and readability metrics, with the easy words list adapted from the original implementation.
Note: Syllable counting may differ from the original Python implementation due to the use of the 'syllable' npm package. This may lead to differences in readability metrics.
Features
- Character, word, sentence, and syllable counting
- Readability scores: Flesch Reading Ease, Flesch-Kincaid Grade, SMOG Index
- Difficult word detection
- Support for English text analysis
Installation
npm install textstat-tsor with Bun:
bun add textstat-tsUsage
import { TextStatistics, textstat } from 'textstat-ts';
const text = "This is a sample text for analysis.";
// Using the default instance
console.log('Word count:', textstat.lexiconCount(text));
console.log('Flesch Reading Ease:', textstat.fleschReadingEase(text));
// Using a new instance
const stats = new TextStatistics();
console.log('Sentence count:', stats.sentenceCount(text));API
TextStatistics Class
charCount(text, ignoreSpaces?): Count characterslexiconCount(text, removepunct?, splitContractions?, splitHyphens?): Count wordssyllableCount(text): Count syllablessentenceCount(text): Count sentencesfleschReadingEase(text): Calculate Flesch Reading Ease scorefleschKincaidGrade(text): Calculate Flesch-Kincaid Grade LevelsmogIndex(text): Calculate SMOG IndexdifficultWords(text, syllableThreshold?, unique?): Count difficult words
License
MIT
