Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.24 KB | None | 0 0
  1. function exchange(str, a, b) {
  2. return str.split(a).map(function(item){return item.replace(new RegExp(b, 'g'), a)}).join(b);
  3. }
  4. function safeSingleQuote(str) {
  5. str = exchange(str, "'", '"');
  6. return exchange(JSON.stringify(str), "'", '"');
  7. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement