ensureEncoded (string) {
        // Takes care of the case where the string is already encoded.
        try {
            string = decodeURIComponent(string);
        }
        catch (e) {} // eslint-disable-line no-empty

        try {
            return encodeURIComponent(string);
        }
        // handle malformed URI sequence
        // refer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI
        catch (error) {
            return string;
        }
    }
Makes sure the given string is encoded only once.

@param {String} string -
@returns {String}