Created
June 5, 2023 12:36
-
-
Save marek-saji/facb17d5f011c5b309703093a135591c to your computer and use it in GitHub Desktop.
Example for hyphenopoly <https://www.npmjs.com/package/hyphenopoly>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S node --experimental-import-meta-resolve | |
import { fileURLToPath } from 'node:url'; | |
import { readFile } from 'node:fs/promises'; | |
import hyphenopoly from 'hyphenopoly'; | |
const hyphenator = hyphenopoly.config({ | |
exceptions: { | |
'en-us': 'en-han-ces', | |
}, | |
hyphen: '•', | |
loader: async (file) => { | |
const filePath = fileURLToPath( | |
await import.meta.resolve(`hyphenopoly/patterns/${file}`) | |
); | |
return readFile(filePath); | |
}, | |
require: ['de', 'en-us'], | |
}); | |
async function hyphenateEn(text) { | |
return (await hyphenator.get('en-us'))(text) | |
} | |
async function hyphenateDe(text) { | |
return (await hyphenator.get('de'))(text) | |
} | |
console.log(await Promise.all([ | |
hyphenateEn('hyphenation enhances justification.'), | |
hyphenateDe('Silbentrennung verbessert den Blocksatz.'), | |
])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "module", | |
"dependencies": { | |
"hyphenopoly": "^5.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment