I have a series of regex replace calls that do what you seem to be looking for, or at least the issues you mentioned. I put together a test string with several items you mentioned.
var testString = ' I start with \"unwanted items and" end with a space". Also I have Quotes ';
var cleanedString = testString.replace(/\s\s+/g, ' ').replace(/^\s|\s$/g, '').replace(/([^\\])(['"])/g, "$1\\$2");
console.log(cleanedString);
This will escape quotes (single or double) that have not yet been escaped, though you would have to worry about the case where the item is preceded by an escaped escape symbol. For example \\' would not be turned into \\\' as it should be. If you want to escape more characters you just need to add them to the final .replace regex. Let me know if there are specific examples you are looking for.