Text Readability & Analysis Toolkit for TypeScript
Zero dependencies. 8 readability formulas. Sentiment analysis. Keyword extraction. SEO scoring. CLI included. Works out of the box.
$ npm install textlens
- Zero dependencies
- 8 readability formulas
- Sentiment analysis
- TypeScript-first
- Node.js ≥ 16
- CLI included
Quick start
import { analyze } from 'textlens';
const result = analyze('Your text goes here...');
result.statistics.words; // word count
result.readability.consensusGrade; // grade level (avg of 8 formulas)
result.readingTime.minutes; // estimated reading time
result.sentiment.label; // 'positive' | 'negative' | 'neutral'
result.keywords; // TF-IDF ranked keywords
8 readability formulas, one consensus grade
TextLens computes all major readability indices and averages them into a single consensus grade level—no need to pick one formula.
import { readability } from 'textlens';
const scores = readability(text);
scores.fleschReadingEase; // 0–100 (higher = easier)
scores.fleschKincaidGrade; // US grade level
scores.colemanLiauIndex; // character-based
scores.automatedReadabilityIndex;
scores.gunningFogIndex;
scores.smogIndex;
scores.daleChallScore;
scores.linsearWriteFormula;
scores.consensusGrade; // weighted average
Sentiment analysis
AFINN-165 lexicon-based sentiment scoring with confidence values and word-level breakdown.
import { sentiment } from 'textlens';
const result = sentiment('This library is amazing and incredibly useful!');
result.score; // 7
result.label; // 'positive'
result.confidence; // 0.87
result.positive; // ['amazing', 'incredibly', 'useful']
Keywords, SEO & more
Keyword extraction
TF-IDF ranked keywords with density analysis for unigrams, bigrams, and trigrams.
import { keywords, density } from 'textlens';
keywords(text, { topN: 5 });
density(text).bigrams;
SEO scoring
Content quality score (A–F grade) with actionable issues and suggestions.
import { seoScore } from 'textlens';
const seo = seoScore(text, {
keyword: 'typescript'
});
seo.score; // 0–100
seo.grade; // 'A'–'F'
Reading time
Estimated reading time with configurable WPM and image time adjustment.
import { readingTime } from 'textlens';
readingTime(text);
// { minutes: 3, seconds: 42 }
Summarization
Extractive summarization using sentence ranking. Pick the most important sentences.
import { summarize } from 'textlens';
summarize(text, { sentences: 3 });
// top 3 sentences
CLI included
Analyze files or piped input directly from your terminal.
# Analyze a file
$ textlens article.txt
# JSON output
$ textlens article.txt --json
# Pipe from stdin
$ cat article.txt | textlens --all
Get started
$ npm install textlens