Created
July 24, 2015 21:02
-
-
Save MadLittleMods/e9d58b1c363bdc816267 to your computer and use it in GitHub Desktop.
Wrap some content with a tag without having to deal with the concat hell :P
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
// tag: '<a href="foo.html">' | |
// | |
// ex. usage: `wrapWithHtmlIf('<a href="foo.html">', 'Hello World', function() { return true });` | |
// output: '<a href="foo.html">Hello World</a>' | |
var wrapWithHtmlIf = function(tag, content, testCb) { | |
if(testCb()) { | |
return tag + content + '</' + tag.match(/<(\w*?)(?:\s|\>)/)[1] + '>'; | |
} | |
return content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment