Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Created June 5, 2023 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marek-saji/facb17d5f011c5b309703093a135591c to your computer and use it in GitHub Desktop.
Save marek-saji/facb17d5f011c5b309703093a135591c to your computer and use it in GitHub Desktop.
Example for hyphenopoly <https://www.npmjs.com/package/hyphenopoly>
#!/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.'),
]))
{
"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