Last active
September 24, 2019 09:04
-
-
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
This file contains hidden or 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
/** | |
* 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