Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created January 1, 2016 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavaScript-Packer/9d7444b87260d7c626c4 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/9d7444b87260d7c626c4 to your computer and use it in GitHub Desktop.
Simple and effective escaper function for JavaScript new lines, quotes, etc
function kleen(e, r) {
r = "replace";
return e[r](/\\/g, "\\\\")[r](/\r/gm, "\n")[r](/\n{2,}/gm, "\n")[r](/\n/g, "\\n")[r](/\'/g, "\\'"[r](/\"/g, '\\"'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment