Just a string. Add \\\' to it every time there is a single quote.
if (!String.prototype.hasOwnProperty('addSlashes')) {
String.prototype.addSlashes = function() {
return this.replace(/&/g, '&') /* This MUST be the 1st replacement. */
.replace(/'/g, ''') /* The 4 other predefined entities, required. */
.replace(/"/g, '"')
.replace(/\\/g, '\\\\')
.replace(//g, '>').replace(/\u0000/g, '\\0');
}
}
Usage: alert(str.addSlashes());
ref: https://stackoverflow.com/a/9756789/3584667