Skip to content

Instantly share code, notes, and snippets.

@dunstontc
Created June 25, 2017 23:28
Show Gist options
  • Save dunstontc/1523e3c44d7f64a2714ddaa1d49f034d to your computer and use it in GitHub Desktop.
Save dunstontc/1523e3c44d7f64a2714ddaa1d49f034d to your computer and use it in GitHub Desktop.
wrap some text
function wrapText (text, token) {
const length = token.length
if ((text.substr(0, length) === token) && (text.substr(-length) === token)) {
return text.substr(length, text.length - length * 2)
} else {
return token + text + token
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment