Skip to content

Instantly share code, notes, and snippets.

@mokargas
Last active February 16, 2017 01:08
Show Gist options
  • Save mokargas/2bebfc6960d8e9d04ab72b6592dd42a4 to your computer and use it in GitHub Desktop.
Save mokargas/2bebfc6960d8e9d04ab72b6592dd42a4 to your computer and use it in GitHub Desktop.
Wrap text with spans
/**
* Wraps a span tag around each character/letter
*
* @param {string} str The string to transform
* @returns {string} Input as split by chars/letters
*/
wrapChars(str) {
return str.replace(/./g, "<span>$&</span>").replace(/\s/g, "<span>&nbsp;</span>");
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment