Created
June 25, 2017 23:28
-
-
Save dunstontc/1523e3c44d7f64a2714ddaa1d49f034d to your computer and use it in GitHub Desktop.
wrap some text
This file contains 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
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