hyphen-minified
v1.6.8
Published
Text hyphenation in Javascript. (minified)
Downloads
16
Maintainers
Readme

hyphen
Forked version: Creates minified versions of the files used in the npm package
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 hyphenor
yarn add hyphenUsage
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%tionsdebug
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. Default value is5.
Import available languages
hyphen/afAfrikaanshyphen/asAssamesehyphen/beBelarusianhyphen/bgBulgarianhyphen/bnBengalihyphen/caCatalan- ~~
hyphen/copCoptic~~ hyphen/csCzechhyphen/cuChurch Slavonichyphen/cyWelshhyphen/daDanishhyphen/de-1901German, traditional spelling- ~~
hyphen/de-1996German, reformed spelling~~ - ~~
hyphen/de-CH-1901German, traditional Swiss spelling~~ hyphen/dealiaseshyphen/de-1996hyphen/el-monotonModern Greek, monotonic spelling- ~~
hyphen/el-polytonModern Greek, polytonic spelling~~ hyphen/elaliaseshyphen/el-monoton- ~~
hyphen/en-gbEnglish, British spelling~~ hyphen/en-usEnglish, American spellinghyphen/enaliaseshyphen/en-ushyphen/esSpanishhyphen/etEstonian- ~~
hyphen/ethialiaseshyphen/mul-ethi~~ hyphen/euBasquehyphen/fiFinnishhyphen/frFrench- ~~
hyphen/furFriulan~~ hyphen/gaIrishhyphen/glGalician- ~~
hyphen/grcAncient Greek~~ hyphen/guGujaratihyphen/hiHindihyphen/hrCroatian- ~~
hyphen/hsbUpper Sorbian~~ hyphen/huHungarianhyphen/hyArmenianhyphen/iaInterlinguahyphen/idBahasa Indonesia, Indonesianhyphen/isIcelandichyphen/itItalianhyphen/kaGeorgian- ~~
hyphen/kmrKurmanji, Northern Kurdish~~ hyphen/knKannada- ~~
hyphen/la-x-classicClassical Latin~~ - ~~
hyphen/la-x-liturgicLiturgical Latin~~ hyphen/laLatinhyphen/ltLithuanianhyphen/lvLatvianhyphen/mlMalayalam- ~~
hyphen/mn-cyrl-x-lmcMongolian, Cyrillic script, alternative patterns~~ hyphen/mn-cyrlMongolian, Cyrillic scripthyphen/mnaliaseshyphen/mn-cyrlhyphen/mrMarathi- ~~
hyphen/mul-ethiMultiple languages using the Ethiopic scripts~~ hyphen/nbNorwegian Bokmål, bokmål, norsk bokmålhyphen/nlDutchhyphen/nnNorwegian Nynorsk, nynorskhyphen/noNorwegian, norskhyphen/ocOccitanhyphen/orOdia, Oriyahyphen/paPanjabi, Punjabihyphen/piPālihyphen/plPolish- ~~
hyphen/pmsPiedmontese~~ hyphen/ptPortuguesehyphen/rmRomanshhyphen/roRomanianhyphen/ruRussianhyphen/saSanskrithyphen/sh-cyrlSerbocroatian, Cyrillic script- ~~
hyphen/sh-latnSerbocroatian, Latin script~~ hyphen/shaliaseshyphen/sh-cyrlhyphen/skSlovakhyphen/slSlovenianhyphen/sr-cyrlSerbian, Cyrillic scripthyphen/sraliaseshyphen/sr-cyrlhyphen/svSwedishhyphen/taTamilhyphen/teTeluguhyphen/thThaihyphen/tkTurkmenhyphen/trTurkishhyphen/ukUkrainianhyphen/zh-latn-pinyinMandarin Chinese, pinyin transliterationhyphen/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.
