Last active
May 15, 2016 23:11
-
-
Save englishextra/3053a4dc18c2de3c80ce7d26207681e0 to your computer and use it in GitHub Desktop.
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
/*! | |
* Escape strings for use as JavaScript string literals | |
* gist.github.com/englishextra/3053a4dc18c2de3c80ce7d26207681e0 | |
* modified github.com/joliss/js-string-escape | |
*/ | |
jsStringEscape = function (b) { | |
return ("" + b).replace(/["'\\\n\r\u2028\u2029]/g, function (a) { | |
switch (a) { | |
case '"': | |
case "'": | |
case "\\": | |
return "\\" + a; | |
case "\n": | |
return "\\n"; | |
case "\r": | |
return "\\r"; | |
case "\u2028": | |
return "\\u2028"; | |
case "\u2029": | |
return "\\u2029" | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment