A hyphenation library based on LibreOffice dictionaries, inspired by pyphen.
Tip
See also:
- @lunarisapp/language for core linguistic breakdown: vowels, consonants, words, and sentences.
- @lunarisapp/stats for text statistics (e.g. word count, sentence count, etc.).
- @lunarisapp/readability for text readability scores (e.g. Flesch Reading Ease).
- Browser & Node.js support
- Multi-language support
- TypeScript support
npm install @lunarisapp/hyphen
import { TextHyphen } from '@lunarisapp/hyphen';
const textHyphen = new TextHyphen({
lang: 'en_US', // optional, en_US by default
left: 2, // optional, 2 by default
right: 2, // optional, 2 by default
});
// Gets the textHyphenation points for a word.
// Result: [2, 6]
textHyphen.positions('hyphenation');
// Wraps a word with hyphens at the given positions.
// Result: 'hy-phenation'
textHyphen.wrap('hy-phenation', 3);
// Gets the hyphenation variants for a word.
// Result: [['hy', 'phenation'], ['hyphen', 'ation']]
textHyphen.variants('hyphenation');
// Inserts hyphens in all possible positions.
// Result: 'hy-phen-ation'
textHyphen.inserted('hyphenation');