{"id":13721092,"url":"https://github.com/mnater/Hyphenopoly","last_synced_at":"2025-05-07T13:31:37.152Z","repository":{"id":5837814,"uuid":"56270491","full_name":"mnater/Hyphenopoly","owner":"mnater","description":"Hyphenation for node and Polyfill for client-side hyphenation.","archived":false,"fork":false,"pushed_at":"2025-01-27T23:22:36.000Z","size":23447,"stargazers_count":704,"open_issues_count":4,"forks_count":45,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-27T13:28:43.471Z","etag":null,"topics":["hyphenation","hyphenation-algorithm","javascript"],"latest_commit_sha":null,"homepage":"http://mnater.github.io/Hyphenopoly/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mnater.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":null,"patreon":null,"open_collective":"hyphenopoly","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2016-04-14T21:15:08.000Z","updated_at":"2025-04-06T18:11:02.000Z","dependencies_parsed_at":"2023-09-29T08:52:04.749Z","dependency_job_id":"cdc65ec1-0d90-45c3-a210-0660592a809e","html_url":"https://github.com/mnater/Hyphenopoly","commit_stats":{"total_commits":707,"total_committers":9,"mean_commits":78.55555555555556,"dds":"0.018387553041018356","last_synced_commit":"872c93e028acf040403563504f3c50085a1b6458"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnater%2FHyphenopoly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnater%2FHyphenopoly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnater%2FHyphenopoly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnater%2FHyphenopoly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnater","download_url":"https://codeload.github.com/mnater/Hyphenopoly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252655024,"owners_count":21783375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hyphenation","hyphenation-algorithm","javascript"],"created_at":"2024-08-03T01:01:12.393Z","updated_at":"2025-05-07T13:31:33.109Z","avatar_url":"https://github.com/mnater.png","language":"TypeScript","funding_links":["https://opencollective.com/hyphenopoly","https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SYNZKB8Z2FRQY","https://opencollective.com/hyphenopoly/donate"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Hyphenopoly.js\n\n[![CircleCI](https://circleci.com/gh/mnater/Hyphenopoly/tree/master.svg?style=shield)](https://circleci.com/gh/mnater/Hyphenopoly/tree/master)\n[![Coverage Status](https://coveralls.io/repos/github/mnater/Hyphenopoly/badge.svg?branch=master)](https://coveralls.io/github/mnater/Hyphenopoly?branch=master)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/de50e1ae70a64a47b0bd9b5449f89353)](https://app.codacy.com/gh/mnater/Hyphenopoly/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\nHyphenopoly.js is a __JavaScript-polyfill for hyphenation in HTML__: it hyphenates text if the user agent does not support CSS-hyphenation at all or not for the required languages and it is a __Node.js-module__.\n\nThe package consists of the following parts:\n- _Hyphenopoly_Loader.js_ (~11KB unpacked, ~2KB minified and compressed): feature-checks the client and loads other resources if necessary.\n- _Hyphenopoly.js_ (~36KB unpacked, ~5KB minified and compressed): does the whole DOM-foo and wraps wasm.\n- _wasm-Modules_ (sizes differ! e.g. en-us.wasm: ~21KB uncompressed, ~15KB compressed): core hyphenation functions and hyphenation patterns in a space saving binary format (including pattern license).\n- _hyphenopoly.module.js_: the node module to hyphenate plain text strings.\n\n## Usage (Browser)\nPlace all the code for Hyphenopoly at the top of the header (immediately after the `\u003ctitle\u003e` tag) to ensure resources are loaded as early as possible.\n\nYou'll have to insert two script blocks. In the first block, load Hyphenopoly_Loader.js as an external script.\nIn the second block, provide the initial configurations for Hyphenopoly_Loader as an inline script. This also triggers all further steps.\n\nAlso, don't forget to enable CSS hyphenation.\n\n[Example](http://mnater.github.io/Hyphenopoly/min/example.html):\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cmeta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"\u003e\n        \u003ctitle\u003eExample 1\u003c/title\u003e\n        \u003cscript src=\"./Hyphenopoly_Loader.js\"\u003e\u003c/script\u003e\n        \u003cscript\u003e\n        Hyphenopoly.config({\n            require: {\n                \"la\": \"honorificabilitudinitas\",\n                \"de\": \"Silbentrennungsalgorithmus\",\n                \"en-us\": \"Supercalifragilisticexpialidocious\"\n            },\n            setup: {\n                selectors: {\n                    \".container\": {}\n                }\n            }\n        });\n        \u003c/script\u003e\n        \u003cstyle type=\"text/css\"\u003e\n            body {\n                width:60%;\n                margin-left:20%;\n            }\n            p {\n                text-align: justify;\n                margin: 0 2em 0 0;\n            }\n            .container {\n                display: flex;\n                hyphens: auto;\n                -ms-hyphens: auto;\n                -moz-hyphens: auto;\n                -webkit-hyphens: auto;\n            }\n        \u003c/style\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eExample 1\u003c/h1\u003e\n        \u003cdiv class=\"container\"\u003e\n            \u003cp lang=\"la\"\u003eQua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\u003c/p\u003e\n            \u003cp lang=\"en-us\"\u003eFor which reason the Helvetii also surpass the rest of the Gauls in valor, as they contend with the Germans in almost daily battles, when they either repel them from their own territories, or themselves wage war on their frontiers.\u003c/p\u003e\n            \u003cp lang=\"de\"\u003eAus diesem Grund übertreffen auch die Helvetier die übrigen Gallier an Tapferkeit, weil sie sich in fast täglichen Gefechten mit den Germanen messen, wobei sie diese entweder von ihrem Gebiet fernhalten oder selbst in deren Gebiet kämpfen.\u003c/p\u003e\n        \u003c/div\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\nLet's go through this example step by step:\n\n### UTF-8\nMake sure your page is encoded as utf-8.\n\n### script blocks – load, configure and run Hyphenopoly_Loader.js\nHyphenopoly_Loader.js needs some information to run. This information is provided as a parameter object to the function `Hyphenopoly.config()`. This information is stored in a globally accessible Object called `window.Hyphenopoly`. Hyphenopoly_Loader.js and (if necessary) Hyphenopoly.js will add other methods and properties only to this object – there will be no other global variables or functions beyond this object.\n\n#### require\nThe configuration object must have exactly one property called `require` which itself is an object containing at least one nameValuePair where the name is a language code string (Some languages are region-specific. See the patterns directory for supported languages. E.g. just using `en` won't work, use `en-us`or `en-gb`) and the value is a long word string in that language (preferably more than 12 characters long).\n\nIf you want to force the usage of Hyphenopoly.js for a language (e.g. for testing purposes), write `\"FORCEHYPHENOPOLY\"` instead of the long word.\n\nHyphenopoly_Loader.js tests if the client (aka browser, aka user agent) supports CSS hyphenation for the language(s) given in `require`. In the example above, it will test if the client supports CSS-hyphenation for Latin, German and US-English.\n\nIf one of the given languages isn't supported, it automatically hides the document's contents and loads Hyphenopoly.js and the necessary WebAssembly modules.\n\nHyphenopoly.js – once loaded – will hyphenate the elements according to the settings and unhide the document when it's done.\n\nIf something goes wrong and Hyphenopoly.js is unable to unhide the document, Hyphenopoly_Loader.js has a timeout that kicks in after some time (defaults to 1000ms) and unhides the document and writes a message to the console.\n\nIf the browser supports all required languages, the script deletes the `Hyphenopoly`-object and terminates without further ado.\n\n### enable CSS-hyphenation\nHyphenopoly by default hyphenates elements (and their children) with the classname `.hyphenate`. Don't forget to enable CSS-hyphenation for the classes eventually handled by Hyphenopoly.\n\n## Usage (node)\nInstall:\n````shell\nnpm i hyphenopoly\n````\n\n````javascript\nimport hyphenopoly from \"hyphenopoly\";\n\nconst hyphenator = hyphenopoly.config({\n    \"exceptions\": {\n        \"en-us\": \"en-han-ces\"\n    },\n    \"hyphen\": \"•\",\n    \"loader\": async (file, patDir) =\u003e {\n        const {readFile} = await import(\"node:fs/promises\");\n        return readFile(new URL(file, patDir));\n    },\n    \"require\": [\"de\", \"en-us\"]\n});\n\nasync function hyphenateEn(text) {\n    const hyphenateText = await hyphenator.get(\"en-us\");\n    console.log(hyphenateText(text));\n}\n\nasync function hyphenateDe(text) {\n    const hyphenateText = await hyphenator.get(\"de\");\n    console.log(hyphenateText(text));\n}\n\nhyphenateEn(\"hyphenation enhances justification.\");\nhyphenateDe(\"Silbentrennung verbessert den Blocksatz.\");\n````\n\n## Support this project\n[![PayPal](https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SYNZKB8Z2FRQY)\n\n\u003ca href=\"https://opencollective.com/hyphenopoly/donate\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/hyphenopoly/donate/button@2x.png?color=blue\" width=300 /\u003e\n\u003c/a\u003e\n\n## Automatic hyphenation\nThe algorithm used for hyphenation was developed by Franklin M. Liang for TeX. It works more or less like this:\n\n1. Load a set of precomputed language specific patterns. The patterns are stored in a structure called a trie, which is very efficient for this task.\n2. Collect all patterns that are a substring of the word to be hyphenated.\n3. Combine the numerical values between characters: higher values overwrite lower values.\n4. Odd values are hyphenation points (except if the hyphenation point is left from `leftmin` and right from `rightmin`), replace them with a soft hyphen and drop the other values.\n5. Repeat steps 2. - 4. for all words longer than minWordLength\n\nExample:\n````text\nHyphenation\nh y p h e n a t i o n\nh y3p h\n      h e2n\n      h e n a4\n      h e n5a t\n         1n a\n          n2a t\n             1t i o\n               2i o\n                  o2n\nh0y3p0h0e2n5a4t2i0o2n\nHy-phen-ation\n````\n\nThe patterns are precomputed and available for many languages on [CTAN](https://www.ctan.org/tex-archive/language/hyphenation/) and [tex-hyphen](https://github.com/hyphenation/tex-hyphen). For Hyphenopoly.js they are converted to a succinct trie data structure (including pattern license, metadata, and the patterns).\n\nThe original patterns are computed from a large list of hyphenated words by a program called `patgen`. They aim to find some hyphenation points – not all – because it's better to miss a hyphenation point than to have some false hyphenation points. Most patterns are really good, but none are error free.\n\nThese patterns vary in size. This is mostly due to the different linguistic characteristics of the languages.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/StephanHoyer\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/54701?v=4?s=100\" width=\"100px;\" alt=\"Stephan Hoyer\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eStephan Hoyer\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=StephanHoyer\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=StephanHoyer\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"http://thomasbroadley.com\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/8731922?v=4?s=100\" width=\"100px;\" alt=\"Thomas Broadley\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eThomas Broadley\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=tbroadley\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://kailueke.gitlab.io/\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/1189130?v=4?s=100\" width=\"100px;\" alt=\"Kai Lüke\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKai Lüke\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=pothos\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"http://www.data-factory.net/\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/998558?v=4?s=100\" width=\"100px;\" alt=\"Sebastian Blank\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSebastian Blank\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-blankse\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.ghsvs.de\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/20780646?v=4?s=100\" width=\"100px;\" alt=\"ReLater\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eReLater\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-ReLater\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/julian-zatloukal\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/58230917?v=4?s=100\" width=\"100px;\" alt=\"julian-zatloukal\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ejulian-zatloukal\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=julian-zatloukal\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"http://www.neoskop.de/\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/1702250?v=4?s=100\" width=\"100px;\" alt=\"Maik Jablonski\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMaik Jablonski\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=jablonski\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/yashha\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/4728786?v=4?s=100\" width=\"100px;\" alt=\"yashha\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eyashha\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=yashha\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"http://danburzo.ro/\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/205375?v=4?s=100\" width=\"100px;\" alt=\"Dan Burzo\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDan Burzo\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=danburzo\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/CommanderRoot\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4395417?v=4?s=100\" width=\"100px;\" alt=\"Tobias Speicher\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTobias Speicher\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mnater/Hyphenopoly/commits?author=CommanderRoot\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n  \u003ctfoot\u003e\n    \n  \u003c/tfoot\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnater%2FHyphenopoly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnater%2FHyphenopoly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnater%2FHyphenopoly/lists"}