ytiurin / Hyphen
Programming Languages
Labels
Projects that are alternatives of or similar to Hyphen
hyphen
This is a text hyphenation library, based on Franklin M. Liang's hyphenation algorithm. In core of the algorithm lies a set of hyphenation patterns. They are extracted from hand-hyphenated dictionaries. Patterns for this library were taken from ctan.org and ported to Javascript.
import { hyphenate } from "hyphen/en";
hyphenate("A certain king had a beautiful garden").then(result => {
// A cer[-]tain king had a beau[-]ti[-]ful garden
// [-] is soft hyphen
});
Install
npm install hyphen
or
yarn add hyphen
Usage
import {
hyphenate,
hyphenateHTML,
hyphenateHTMLSync,
hyphenateSync
} from "hyphen/en";
hyphenate("Plain text - hyphenate everything").then(result => {
// Plain text - hy[-]phen[-]ate every[-]thing
});
hyphenateHTML("<blockquote>HTML tags are NOT hyphenated</blockquote>").then(
result => {
// <blockquote>HTML tags are NOT hy[-]phen[-]at[-]ed</blockquote>
}
);
hyphenateHTMLSync("<blockquote>Sync version of `hyphenateHTML`</blockquote>");
// <blockquote>Sync ver[-]sion of `hy[-]phen[-]ate[-]HTML`</blockquote>
hyphenateSync("Sync version of `hyphenate`");
// Sync ver[-]sion of `hy[-]phen[-]ate`
Options
hyphenate("Options", { debug: true, hyphenChar: "%", minWordLength: 5 });
// Op%tions
-
debug
A
Booleanindicating, if script should output debug info to console. Default isfalse. -
hyphenChar
A
Stringsets a value of the soft hyphen character. Default value is\u00AD. -
minWordLength
A
Numbersets the minimum length of the word, intended for hyphenation. This value can't be less than5(for the performance consideration). Default value is5.
Import available languages
-
hyphen/afAfrikaans -
hyphen/asAssamese -
hyphen/beBelarusian -
hyphen/bgBulgarian -
hyphen/bnBengali -
hyphen/caCatalan -
hyphen/copCoptic -
hyphen/csCzech -
hyphen/cuChurch Slavonic -
hyphen/cyWelsh -
hyphen/daDanish -
hyphen/de-1901German, traditional spelling -
hyphen/de-1996German, reformed spelling -
hyphen/de-CH-1901German, traditional Swiss spelling -
hyphen/dealiaseshyphen/de-1996 -
hyphen/el-monotonModern Greek, monotonic spelling -
hyphen/el-polytonModern Greek, polytonic spelling -
hyphen/elaliaseshyphen/el-monoton -
hyphen/en-gbEnglish, British spelling -
hyphen/en-usEnglish, American spelling -
hyphen/enaliaseshyphen/en-us -
hyphen/esSpanish -
hyphen/etEstonian -
hyphen/ethialiaseshyphen/mul-ethi -
hyphen/euBasque -
hyphen/fiFinnish -
hyphen/frFrench -
hyphen/furFriulan -
hyphen/gaIrish -
hyphen/glGalician -
hyphen/grcAncient Greek -
hyphen/guGujarati -
hyphen/hiHindi -
hyphen/hrCroatian -
hyphen/hsbUpper Sorbian -
hyphen/huHungarian -
hyphen/hyArmenian -
hyphen/iaInterlingua -
hyphen/idBahasa Indonesia, Indonesian -
hyphen/isIcelandic -
hyphen/itItalian -
hyphen/kaGeorgian -
hyphen/kmrKurmanji, Northern Kurdish -
hyphen/knKannada -
hyphen/la-x-classicClassical Latin -
hyphen/la-x-liturgicLiturgical Latin -
hyphen/laLatin -
hyphen/ltLithuanian -
hyphen/lvLatvian -
hyphen/mlMalayalam -
hyphen/mn-cyrl-x-lmcMongolian, Cyrillic script, alternative patterns -
hyphen/mn-cyrlMongolian, Cyrillic script -
hyphen/mnaliaseshyphen/mn-cyrl -
hyphen/mrMarathi -
hyphen/mul-ethiMultiple languages using the Ethiopic scripts -
hyphen/nbNorwegian Bokmål, bokmål, norsk bokmål -
hyphen/nlDutch -
hyphen/nnNorwegian Nynorsk, nynorsk -
hyphen/noNorwegian, norsk -
hyphen/ocOccitan -
hyphen/orOdia, Oriya -
hyphen/paPanjabi, Punjabi -
hyphen/piPāli -
hyphen/plPolish -
hyphen/pmsPiedmontese -
hyphen/ptPortuguese -
hyphen/rmRomansh -
hyphen/roRomanian -
hyphen/ruRussian -
hyphen/saSanskrit -
hyphen/sh-cyrlSerbocroatian, Cyrillic script -
hyphen/sh-latnSerbocroatian, Latin script -
hyphen/shaliaseshyphen/sh-cyrl -
hyphen/skSlovak -
hyphen/slSlovenian -
hyphen/sr-cyrlSerbian, Cyrillic script -
hyphen/sraliaseshyphen/sr-cyrl -
hyphen/svSwedish -
hyphen/taTamil -
hyphen/teTelugu -
hyphen/thThai -
hyphen/tkTurkmen -
hyphen/trTurkish -
hyphen/ukUkrainian -
hyphen/zh-latn-pinyinMandarin Chinese, pinyin transliteration -
hyphen/zhaliaseshyphen/zh-latn-pinyin
Factory function
import createHyphenator from "hyphen";
import patterns from "hyphen/patterns/en-us";
const hyphenate = createHyphenator(patterns, { async: true });
const hyphenateHTML = createHyphenator(patterns, { async: true, html: true });
const hyphenateHTMLSync = createHyphenator(patterns, { html: true });
const hyphenateSync = createHyphenator(patterns);
Note: This original factory function surves mostly for the backwards compatibility reasons.
Text hyphenation in CSS
The CSS hyphens property is intended to add hyphenation support to modern browsers without Javascript:
p {
hyphens: auto;
}
It is part of the CSS Text Level 3 specification. The browser compatibility list can be found on the related MDN page.
Alternatives
Check other great hyphenation libraries:
- Hyphenator.js does client-side hyphenation of HTML-Documents.
- Hypher A fast and small hyphenation engine.

