Encode and decode URI components. See encodeURIComponent on MDN for more information.
This will be useful for fixing strings that have been double-encoded or double-decoded, but in general it's not possible to determine if a string is in this state or not.