@lunarisapp/readability
Version:
A library for calculating readability scores of texts
333 lines (314 loc) • 9.58 kB
TypeScript
import { Language } from '@lunarisapp/language';
export { Language } from '@lunarisapp/language';
/**
* Calculate the automated readability index for text.
* https://en.wikipedia.org/wiki/Automated_readability_index
*/
declare function automatedReadabilityIndex(params: {
chars: number;
words: number;
sentences: number;
}): number;
/**
* Calculate the Coleman-Liau index for text.
* https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
*/
declare function colemanLiauIndex(params: {
letters: number;
sentences: number;
}): number;
/**
* Calculate Crawford's formula for text (Spanish only).
* https://www.spanishreadability.com/the-crawford-score-for-spanish-texts
*/
declare function crawford(params: {
words: number;
sentences: number;
syllables: number;
}): number;
/**
* Calculate the Fernandez Huerta readability formula for text (Spanish only).
* https://www.spanishreadability.com/the-fernandez-huerta-readability-formula
*/
declare function fernandezHuerta(params: {
words: number;
sentences: number;
syllables: number;
}): number;
/**
* Calculate the Flesch-Kincaid grade level for text.
* https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
* TODO: can we support multiple languages?
*/
declare function fleschKincaidGrade(params: {
sentences: number;
syllablesPerWord: number;
}): number;
/**
* Calculate the Flesch reading ease test for text.
* https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch_reading_ease
*/
declare function fleschReadingEase(params: {
sentences: number;
syllablesPerWord: number;
coefficients?: {
base?: number;
sentences?: number;
syllablesPerWord?: number;
};
}): number;
/**
* Calculate the Gulpease index for text (Italian only).
* https://it.wikipedia.org/wiki/Indice_Gulpease
*/
declare function gulpeaseIndex(params: {
sentences: number;
chars: number;
words: number;
}): number;
/**
* Calculate the Gunning Fog index for text.
* https://en.wikipedia.org/wiki/Gunning_fog_index
*/
declare function gunningFog(params: {
avgWordsPerSentence: number;
difficultWords: number;
totalWords: number;
}): number;
/**
* Calculate Gutierrez Polini's readability formula for text (Spanish only).
* https://www.spanishreadability.com/gutierrez-de-polinis-readability-formula
*/
declare function gutierrezPolini(params: {
words: number;
sentences: number;
letters: number;
}): number;
/**
* Calculate the Linsear Write formula for text.
* https://en.wikipedia.org/wiki/Linsear_Write
*/
declare function linsearWriteFormula(params: {
sentences: number;
syllablesPerWords: number[];
}): number;
/**
* Calculate the LIX ratio.
* https://readable.com/readability/lix-rix-readability-formulas/
* @param params
*/
declare function lix(params: {
words: number;
longWords: number;
wordsPerSentence: number;
}): number;
/**
* Calculate the McAlpine EFLAW score.
* https://www.angelfire.com/nd/nirmaldasan/journalismonline/fpetge.html
*/
declare function mcalpineEflaw(params: {
words: number;
sentences: number;
miniWords: number;
}): number;
/**
* Calculate the RIX ratio.
* https://readable.com/readability/lix-rix-readability-formulas/
* @param params
*/
declare function rix(params: {
longWords: number;
sentences: number;
}): number;
/**
* Calculate the SMOG index for text.
* https://en.wikipedia.org/wiki/SMOG
*/
declare function smogIndex(params: {
sentences: number;
polysyllables: number;
}): number;
/**
* Calculate the Szigriszt Pazos readability formula for text (Spanish only).
* Szigriszt Pazos, Francisco (1992). Sistemas predictivos de legibilidad del mensaje escrito: fórmula de perspicuidad.
*/
declare function szigrisztPazos(params: {
totalSyllables: number;
totalWords: number;
totalSentences: number;
freBase: number;
}): number;
declare const VARIANTS: {
1: {
ms: number;
sl: number;
iw: number;
es: number;
base: number;
};
2: {
ms: number;
sl: number;
iw: number;
es: number;
base: number;
};
3: {
ms: number;
sl: number;
iw: number;
es: number;
base: number;
};
4: {
ms: number;
sl: number;
iw: number;
es: number;
base: number;
};
};
type WienerSachtextformelVariant = keyof typeof VARIANTS;
/**
* Calculate the Wiener Sachtextformel for text (german).
* https://de.wikipedia.org/wiki/Lesbarkeitsindex#Wiener_Sachtextformel
*/
declare function wienerSachtextformel(params: {
words: number;
sentences: number;
longWords: number;
polysyllables: number;
monosyllables: number;
variant: WienerSachtextformelVariant;
}): number;
declare class TextReadability {
private readonly cache;
private readonly cacheEnabled;
private lang;
private textStats;
constructor(props?: {
lang?: Language;
cache?: boolean;
});
private getCfg;
/**
* Set the language for the text statistics.
* @param lang
*/
setLang(lang: Language): void;
/**
* Calculate the Flesch reading ease test for text.
* https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch_reading_ease
* @param text
*/
fleschReadingEase(text: string): number;
private computeFleschReadingEase;
/**
* Calculate the Flesch-Kincaid grade level for text.
* https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
* TODO: can we support multiple languages?
* @param text
*/
fleschKincaidGrade(text: string): number;
private computeFleschKincaidGrade;
/**
* Calculate the SMOG index for text.
* https://en.wikipedia.org/wiki/SMOG
* @param text
*/
smogIndex(text: string): number;
private computeSmogIndex;
/**
* Calculate the Gunning Fog index for text.
* https://en.wikipedia.org/wiki/Gunning_fog_index
* @param text
*/
gunningFog(text: string): number;
private computeGunningFog;
/**
* Calculate the Coleman-Liau index for text.
* https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
* @param text
*/
colemanLiauIndex(text: string): number;
private computeColemanLiauIndex;
/**
* Calculate the automated readability index for text.
* https://en.wikipedia.org/wiki/Automated_readability_index
* @param text
*/
automatedReadabilityIndex(text: string): number;
private computeAutomatedReadabilityIndex;
/**
* Calculate the Linsear Write formula for text.
* https://en.wikipedia.org/wiki/Linsear_Write
* @param text
* @param sample Number of words to sample from the text
*/
linsearWriteFormula(text: string, sample?: number): number;
private computeLinsearWriteFormula;
/**
* Calculate Gutierrez Polini's readability formula for text (Spanish only).
* https://www.spanishreadability.com/gutierrez-de-polinis-readability-formula
* @param text
*/
gutierrezPolini(text: string): number;
private computeGutierrezPolini;
/**
* Calculate Crawford's formula for text (Spanish only).
* https://www.spanishreadability.com/the-crawford-score-for-spanish-texts
* @param text
*/
crawford(text: string): number;
private computeCrawford;
/**
* Calculate the Fernandez Huerta readability formula for text (Spanish only).
* https://www.spanishreadability.com/the-fernandez-huerta-readability-formula
* @param text
*/
fernandezHuerta(text: string): number;
private computeFernandezHuerta;
/**
* Calculate the Szigriszt Pazos readability formula for text (Spanish only).
* @param text
*/
szigrisztPazos(text: string): number;
private computeSzigrisztPazos;
/**
* Calculate the Gulpease index for text (Italian only).
* https://it.wikipedia.org/wiki/Indice_Gulpease
* @param text
*/
gulpeaseIndex(text: string): number;
private computeGulpeaseIndex;
/**
* Calculate the RIX ratio.
* https://readable.com/readability/lix-rix-readability-formulas/
* @param text
*/
rix(text: string): number;
private computeRix;
/**
* Calculate the LIX ratio.
* https://readable.com/readability/lix-rix-readability-formulas/
* @param text
*/
lix(text: string): number;
private computeLix;
/**
* Calculate the Wiener Sachtextformel for text (german).
* https://de.wikipedia.org/wiki/Lesbarkeitsindex#Wiener_Sachtextformel
* @param text
* @param variant
*/
wienerSachtextformel(text: string, variant?: WienerSachtextformelVariant): number;
private computeWienerSachtextformel;
/**
* Calculate the McAlpine EFLAW score for text.
* https://www.angelfire.com/nd/nirmaldasan/journalismonline/fpetge.html
* @param text
*/
mcalpineEflaw(text: string): number;
private computeMcalpineEflaw;
}
export { TextReadability, VARIANTS, type WienerSachtextformelVariant, automatedReadabilityIndex, colemanLiauIndex, crawford, fernandezHuerta, fleschKincaidGrade, fleschReadingEase, gulpeaseIndex, gunningFog, gutierrezPolini, linsearWriteFormula, lix, mcalpineEflaw, rix, smogIndex, szigrisztPazos, wienerSachtextformel };