SkillAgentSearch skills...

Hyphen

Text hyphenation in Javascript.

Install / Use

/learn @ytiurin/Hyphen
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Franklin M. Liang's hyphenation algorithm

npm version<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

hyphen

Demo page

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";

(async () => {
  const text = "A certain king had a beautiful garden";

  const result = await hyphenate(text);
  // result is "A cer\u00ADtain king had a beau\u00ADti\u00ADful garden"
})();

Hyphenate HTML

Processor will automaticly skip HTML tags hyphenation.

import { hyphenate } from "hyphen/en";

(async () => {
  const text = "<blockquote>A certain king had a beautiful garden</blockquote>";

  const result = await hyphenate(text);
  // result is "<blockquote>A cer\u00ADtain king had a beau\u00ADti\u00ADful garden</blockquote>"
})();

Select language

To hypehante text in any other supported language, just change the import source. For example for German language, import a hyphenation function from a "hyphen/de" source.

import { hyphenate } from "hyphen/de";

(async () => {
  const text = "Ein gewisser König hatte einen wunderschönen Garten";

  const result = await hyphenate(text);
  // result is "Ein ge\u00ADwis\u00ADser Kö\u00ADnig hat\u00ADte einen wun\u00ADder\u00ADschö\u00ADnen Gar\u00ADten"
})();

Multilingual hyphenation

It is possible to use many langauges on the same page.

import { hyphenate as hyphenateEn } from "hyphen/en";
import { hyphenate as hyphenateDe } from "hyphen/de";

(async () => {
  const english = "A certain king had a beautiful garden";

  const englishResult = await hyphenateEn(english);
  // result is "A cer\u00ADtain king had a beau\u00ADti\u00ADful garden"

  const deutch = "Ein gewisser König hatte einen wunderschönen Garten";

  const deutchResult = await hyphenateDe(deutch);
  // result is "Ein ge\u00ADwis\u00ADser Kö\u00ADnig hat\u00ADte einen wun\u00ADder\u00ADschö\u00ADnen Gar\u00ADten"
})();

Sync version

Use a sync version when you need to write a synchronous code.

import { hyphenateSync as hyphenate } from "hyphen/en";

const text = "A certain king had a beautiful garden";

const result = hyphenate(text);
// result is "A cer\u00ADtain king had a beau\u00ADti\u00ADful garden"

Install

npm install hyphen

Install types definitions for Typescript usage.

npm install --save-dev @types/hyphen

Types definitions are created and maintained by Krisztián Balla.

Options

  • exceptions

    An Array of values with exceptions of hyphenation in words. Hard hyphen symbol - should be used to mark the position of further configured hyphenation symbol. Default value is [].

  • 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 is 5.

Example of using options

import { hyphenate } from "hyphen/en";

(async () => {
  const text = "A certain king had a beautiful garden";

  const result = await hyphenate(text, {
    hyphenChar: "-"
  });
  // result is "A cer-tain king had a beau-ti-ful garden"
})();

List of available languages

<details> <summary>Check the list</summary>
  • Afrikaans language
import { hyphenate } from "hyphen/af";
  • Albanian language
import { hyphenate } from "hyphen/sq";
  • Armenian language
import { hyphenate } from "hyphen/hy";
  • Assamese language
import { hyphenate } from "hyphen/as";
  • Basque language
import { hyphenate } from "hyphen/eu";
  • Belarusian language
import { hyphenate } from "hyphen/be";
  • Bengali language
import { hyphenate } from "hyphen/bn";
  • Bulgarian language
import { hyphenate } from "hyphen/bg";
  • Catalan language
import { hyphenate } from "hyphen/ca";
  • Coptic language
import { hyphenate } from "hyphen/cop";
  • Croatian language
import { hyphenate } from "hyphen/hr";
  • Czech language
import { hyphenate } from "hyphen/cs";
  • Danish language
import { hyphenate } from "hyphen/da";
  • Dutch language
import { hyphenate } from "hyphen/nl";
  • English, American spelling language
import { hyphenate } from "hyphen/en-us";
  • English, British spelling language
import { hyphenate } from "hyphen/en-gb";
  • Estonian language
import { hyphenate } from "hyphen/et";
  • Multiple languages using the Ethiopic scripts
import { hyphenate } from "hyphen/mul-ethi";
  • Finnish language
import { hyphenate } from "hyphen/fi";
  • Finnish language (school hyphenation)
import { hyphenate } from "hyphen/fi-x-school";
  • French language
import { hyphenate } from "hyphen/fr";
  • Friulan language
import { hyphenate } from "hyphen/fur";
  • Galician language
import { hyphenate } from "hyphen/gl";
  • Georgian language
import { hyphenate } from "hyphen/ka";
  • German, traditional spelling
import { hyphenate } from "hyphen/de-1901";
  • German, reformed spelling
import { hyphenate } from "hyphen/de-1996";
  • German, traditional Swiss spelling
import { hyphenate } from "hyphen/de-ch-1901";
  • Modern Greek, monotonic spelling
import { hyphenate } from "hyphen/el-monoton";
  • Modern Greek, polytonic spelling
import { hyphenate } from "hyphen/el-polyton";
  • Ancient Greek language
import { hyphenate } from "hyphen/grc";
  • Gujarati language
import { hyphenate } from "hyphen/gu";
  • Hindi language
import { hyphenate } from "hyphen/hi";
  • Hungarian language
import { hyphenate } from "hyphen/hu";
  • Icelandic language
import { hyphenate } from "hyphen/is";
  • Bahasa Indonesia, Indonesian language
import { hyphenate } from "hyphen/id";
  • Interlingua language
import { hyphenate } from "hyphen/ia";
  • Irish language
import { hyphenate } from "hyphen/ga";
  • Italian language
import { hyphenate } from "hyphen/it";
  • Kannada language
import { hyphenate } from "hyphen/kn";
  • Kurmanji, Northern Kurdish language
import { hyphenate } from "hyphen/kmr";
  • Latin language
import { hyphenate } from "hyphen/la";
  • Classical Latin language
import { hyphenate } from "hyphen/la-x-classic";
  • Liturgical Latin language
import { hyphenate } from "hyphen/la-x-liturgic";
  • Latvian language
import { hyphenate } from "hyphen/lv";
  • Lithuanian language
import { hyphenate } from "hyphen/lt";
  • Macedonian language
import { hyphenate } from "hyphen/mk";
  • Marathi language
import { hyphenate } from "hyphen/mr";
  • Malayalam language
import { hyphenate } from "hyphen/ml";
  • Mandarin Chinese, pinyin transliteration
import { hyphenate } from "hyphen/zh-latn-pinyin";
  • Mongolian, Cyrillic script
import { hyphenate } from "hyphen/mn-cyrl";
  • Mongolian, Cyrillic script, alternative patterns
import { hyphenate } from "hyphen/mn-cyrl-x-lmc";
  • Norwegian, norsk language
import { hyphenate } from "hyphen/no";
  • Norwegian Bokmål, bokmål, norsk bokmål language
import { hyphenate } from "hyphen/nb";
  • Norwegian Nynorsk, nynorsk language
import { hyphenate } from "hyphen/nn";
  • Occitan language
import { hyphenate } from "hyphen/oc";
  • Odia, Oriya language
import { hyphenate } from "hyphen/or";
  • Pāli language
import { hyphenate } from "hyphen/pi";
  • Panjabi, Punjabi language
import { hyphenate } from "hyphen/pa";
  • Piedmontese language
import { hyphenate } from "hyphen/pms";
  • Polish language
import { hyphenate } from "hyphen/pl";
  • Portuguese language
import { hyphenate } from "hyphen/pt";
  • Romansh language
import { hyphenate } from "hyphen/rm";
  • Romanian language
import { hyphenate } from "hyphen/ro";
  • Russian language
import { hyphenate } from "hyphen/ru";
  • Sanskrit language
import { hyphenate } from "hyphen/sa";
  • Serbian, Cyrillic script
import { hyphenate } from "hyphen/sr-cyrl";
  • Serbocroatian, Cyrillic script
import { hyphenate } from "hyphen/sh-cyrl";
  • Serbocroatian, Latin script
import { hyph
View on GitHub
GitHub Stars233
CategoryDevelopment
Updated14d ago
Forks25

Languages

JavaScript

Security Score

100/100

Audited on Mar 17, 2026

No findings