Created
February 27, 2017 15:42
-
-
Save xcodebuild/5881010e6bd67de8e15396b96faa6113 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
function exchange(str, a, b) { | |
return str.split(a).map(function(item){return item.replace(new RegExp(b, 'g'), a)}).join(b); | |
} | |
function safeSingleQuote(str) { | |
str = exchange(str, "'", '"'); | |
return exchange(JSON.stringify(str), "'", '"'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment