Skip to content

Instantly share code, notes, and snippets.

@axe312ger
Last active September 9, 2016 11:48

Revisions

  1. axe312ger renamed this gist Sep 9, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. axe312ger created this gist Sep 9, 2016.
    11 changes: 11 additions & 0 deletions utf8EncodeURIComponent
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    const reserved = [
    ':', '/', '?', '#', '[', ']', '@', // RFC 3986 gen-delims
    '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=', // RFC 3986 sub-delims
    '%' // % needs to be encoded to ensure proper decoding
    ]

    function utf8EncodeURIComponent (uri) {
    return Array.from(uri)
    .map((char) => reserved.includes(char) ? encodeURIComponent(char) : char)
    .join('')
    }