Skip to content

Instantly share code, notes, and snippets.

@rolandcoops
Last active September 24, 2019 09:04
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 rolandcoops/67aebe901265b5d4eaa9fcee283ae2b8 to your computer and use it in GitHub Desktop.
Save rolandcoops/67aebe901265b5d4eaa9fcee283ae2b8 to your computer and use it in GitHub Desktop.
Convert a string to css hex values suitable for use in css “content” prop
/**
* convert a string to css hex values suitable for use in css “content” prop
* @example
* hexify('foo@bar') // '\0066\006f\006f\0040\0062\0061\0072'
*/
const hexify = (string) =>
[...string]
.map((c) => `\\${Number(c.charCodeAt()).toString(16).padStart(4, '0')}`)
.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment