Skip to content

Instantly share code, notes, and snippets.

@benjaminsehl
Last active January 30, 2024 16:13
Show Gist options
  • Save benjaminsehl/a1985caea3e91f15a0a1e05a924b5e3e to your computer and use it in GitHub Desktop.
Save benjaminsehl/a1985caea3e91f15a0a1e05a924b5e3e to your computer and use it in GitHub Desktop.
Typography Formatting Function
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