Last active
January 30, 2024 16:13
-
-
Save benjaminsehl/a1985caea3e91f15a0a1e05a924b5e3e to your computer and use it in GitHub Desktop.
Typography Formatting Function
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
const formatters = [ | |
{ pattern: /'/g, replacement: '’' }, // Replace straight quotes with smart quotes | |
{ pattern: /\s([^\s<]+)\s*$/g, replacement: '\u00A0$1' }, // Add non breaking spaces before the last word | |
] | |
const formatted = (a) => | |
formatters.reduce( | |
(a, f) => a?.toString().replace(f.pattern, f.replacement), | |
a, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment