function encode(val) {
  return encodeURIComponent(val).
    replace(/%3A/gi, ':').
    replace(/%24/g, '$').
    replace(/%2C/gi, ',').
    replace(/%20/g, '+').
    replace(/%5B/gi, '[').
    replace(/%5D/gi, ']');
}
It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
URI encoded counterparts

@param {string} val The value to be encoded.

@returns {string} The encoded value.