Configure hyphenopoly in synchronous mode
masterIf your codebase cannot handle asynchronous code, you can enable synchronous mode by setting "sync": true in the configuration object.
When sync is true:
hyphenopoly.config()returns aMapof hyphenator functions directly (instead of aMapof Promises).- You must provide a
loaderSyncfunction instead of aloaderfunction. - Note that
loaderSynccannot use inherently asynchronous methods likefetchorhttps.
import hyphenopoly from "hyphenopoly";
import {readFileSync} from "node:fs";
function loaderSync(file, patDir) {
return readFileSync(new URL(file, patDir));
}
const hyphenator = hyphenopoly.config({
"exceptions": {
"en-us": "en-han-ces"
},
"hyphen": "•",
loaderSync,
"require": ["de", "en-us"],
"sync": true
});
// hyphenator is a Map of functions
const hy1 = hyphenator.get("en-us")("hyphenation enhances justification.");
const hy2 = hyphenator.get("de")("Silbentrennung verbessert den Blocksatz.");
console.log(hy1);
console.log(hy2);