Skip to content

Commit

Permalink
refactor: same as before for module
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed Nov 28, 2023
1 parent c387712 commit 3af1137
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions hyphenopoly.module.js
Expand Up @@ -337,27 +337,19 @@ function createWordHyphenator(lo, lang) {
* @returns {string} The hyphenated compound word
*/
function hyphenateCompound(word) {
const zeroWidthSpace = "\u200B";
let parts = null;
let wordHyphenator = null;
if (H.c.compound === "auto" ||
H.c.compound === "all") {
wordHyphenator = createWordHyphenator(lo, lang);
parts = word.split("-").map((p) => {
if (p.length >= H.c.minWordLength) {
return wordHyphenator(p);
}
return p;
});
if (H.c.compound === "auto") {
word = parts.join("-");
} else {
word = parts.join("-" + zeroWidthSpace);
let joiner = "-";
const parts = word.split(joiner).map((p) => {
if (H.c.compound !== "hyphen" &&
p.length >= H.c.minWordLength) {
return createWordHyphenator(lo, lang)(p);
}
} else {
word = word.replace("-", "-" + zeroWidthSpace);
return p;
});
if (H.c.compound !== "auto") {
// Add Zero Width Space
joiner += "\u200B";
}
return word;
return parts.join(joiner);
}

/**
Expand Down Expand Up @@ -388,10 +380,10 @@ function createWordHyphenator(lo, lang) {
);
} else if (!H.c.mixedCase && isMixedCase(word)) {
hw = word;
} else if (word.indexOf("-") === -1) {
hw = hyphenateNormal(word);
} else {
} else if (word.includes("-")) {
hw = hyphenateCompound(word);
} else {
hw = hyphenateNormal(word);
}
lo.cache.set(word, hw);
}
Expand Down

0 comments on commit 3af1137

Please sign in to comment.