Module

JSURI

Package
js-uri
Repository
purerl/purescript-js-uri

#encodeURIComponent Source

encodeURIComponent :: String -> Maybe String

URI-encode a string according to RFC3896. Implemented using JavaScript's encodeURIComponent.

> encodeURIComponent "https://purescript.org"
Just "https%3A%2F%2Fpurescript.org"

Encoding a URI can fail with a URIError if the string contains malformed characters. If you are confident you are encoding a well-formed string then you can run this function unsafely:

import Partial.Unsafe (unsafePartial)
import Data.Maybe (fromJust)

unsafeEncode :: String -> String
unsafeEncode str = unsafePartial $ fromJust $ encodeURIComponent str

#encodeFormURLComponent Source

encodeFormURLComponent :: String -> Maybe String

URI-encode a string according to RFC3896, except with spaces encoded using '+' instead of '%20' to comply with application/x-www-form-urlencoded.

> encodeURIComponent "abc ABC"
Just "abc%20ABC"

> encodeFormURLComponent "abc ABC"
Just "abc+ABC"

#decodeURIComponent Source

decodeURIComponent :: String -> Maybe String

Decode a URI string according to RFC3896. Implemented using JavaScript's decodeURIComponent.

> decodeURIComponent "https%3A%2F%2Fpurescript.org"
Just "https://purescript.org"

Decoding a URI can fail with a URIError if the string contains malformed characters. If you are confident you are encoding a well-formed string then you can run this function unsafely:

import Partial.Unsafe (unsafePartial)
import Data.Maybe (fromJust)

unsafeDecode :: String -> String
unsafeDecode str = unsafePartial $ fromJust $ decodeURIComponent str

#decodeFormURLComponent Source

decodeFormURLComponent :: String -> Maybe String

Decode a URI according to application/x-www-form-urlencoded (for example, a string containing '+' for spaces or query parameters).

> decodeURIComponent "https%3A%2F%2Fpurescript.org?search+query"
Just "https://purescript.org?search+query"

> decodeFormURLComponent "https%3A%2F%2Fpurescript.org?search+query"
Just "https://purescript.org?search query"
Modules
JSURI