hyphen-minified
v1.6.8
Published
Text hyphenation in Javascript. (minified)
Downloads
13
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 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
Boolean
indicating, if script should output debug info to console. Default isfalse
.hyphenChar
A
String
sets a value of the soft hyphen character. Default value is\u00AD
.minWordLength
A
Number
sets the minimum length of the word, intended for hyphenation. Default value is5
.
Import available languages
hyphen/af
Afrikaanshyphen/as
Assamesehyphen/be
Belarusianhyphen/bg
Bulgarianhyphen/bn
Bengalihyphen/ca
Catalan- ~~
hyphen/cop
Coptic~~ hyphen/cs
Czechhyphen/cu
Church Slavonichyphen/cy
Welshhyphen/da
Danishhyphen/de-1901
German, traditional spelling- ~~
hyphen/de-1996
German, reformed spelling~~ - ~~
hyphen/de-CH-1901
German, traditional Swiss spelling~~ hyphen/de
aliaseshyphen/de-1996
hyphen/el-monoton
Modern Greek, monotonic spelling- ~~
hyphen/el-polyton
Modern Greek, polytonic spelling~~ hyphen/el
aliaseshyphen/el-monoton
- ~~
hyphen/en-gb
English, British spelling~~ hyphen/en-us
English, American spellinghyphen/en
aliaseshyphen/en-us
hyphen/es
Spanishhyphen/et
Estonian- ~~
hyphen/ethi
aliaseshyphen/mul-ethi
~~ hyphen/eu
Basquehyphen/fi
Finnishhyphen/fr
French- ~~
hyphen/fur
Friulan~~ hyphen/ga
Irishhyphen/gl
Galician- ~~
hyphen/grc
Ancient Greek~~ hyphen/gu
Gujaratihyphen/hi
Hindihyphen/hr
Croatian- ~~
hyphen/hsb
Upper Sorbian~~ hyphen/hu
Hungarianhyphen/hy
Armenianhyphen/ia
Interlinguahyphen/id
Bahasa Indonesia, Indonesianhyphen/is
Icelandichyphen/it
Italianhyphen/ka
Georgian- ~~
hyphen/kmr
Kurmanji, Northern Kurdish~~ hyphen/kn
Kannada- ~~
hyphen/la-x-classic
Classical Latin~~ - ~~
hyphen/la-x-liturgic
Liturgical Latin~~ hyphen/la
Latinhyphen/lt
Lithuanianhyphen/lv
Latvianhyphen/ml
Malayalam- ~~
hyphen/mn-cyrl-x-lmc
Mongolian, Cyrillic script, alternative patterns~~ hyphen/mn-cyrl
Mongolian, Cyrillic scripthyphen/mn
aliaseshyphen/mn-cyrl
hyphen/mr
Marathi- ~~
hyphen/mul-ethi
Multiple languages using the Ethiopic scripts~~ hyphen/nb
Norwegian Bokmål, bokmål, norsk bokmålhyphen/nl
Dutchhyphen/nn
Norwegian Nynorsk, nynorskhyphen/no
Norwegian, norskhyphen/oc
Occitanhyphen/or
Odia, Oriyahyphen/pa
Panjabi, Punjabihyphen/pi
Pālihyphen/pl
Polish- ~~
hyphen/pms
Piedmontese~~ hyphen/pt
Portuguesehyphen/rm
Romanshhyphen/ro
Romanianhyphen/ru
Russianhyphen/sa
Sanskrithyphen/sh-cyrl
Serbocroatian, Cyrillic script- ~~
hyphen/sh-latn
Serbocroatian, Latin script~~ hyphen/sh
aliaseshyphen/sh-cyrl
hyphen/sk
Slovakhyphen/sl
Slovenianhyphen/sr-cyrl
Serbian, Cyrillic scripthyphen/sr
aliaseshyphen/sr-cyrl
hyphen/sv
Swedishhyphen/ta
Tamilhyphen/te
Teluguhyphen/th
Thaihyphen/tk
Turkmenhyphen/tr
Turkishhyphen/uk
Ukrainianhyphen/zh-latn-pinyin
Mandarin Chinese, pinyin transliterationhyphen/zh
aliaseshyphen/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.