Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Value for QueryParameter: none #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Url/Builder.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Url.Builder exposing
( absolute, relative, crossOrigin, custom, Root(..)
, QueryParameter, string, int, toQuery
, QueryParameter, string, int, none, toQuery
)


Expand All @@ -21,7 +21,7 @@ This module helps you create these!
@docs absolute, relative, crossOrigin, custom, Root

# Queries
@docs QueryParameter, string, int, toQuery
@docs QueryParameter, string, int, none, toQuery

-}

Expand Down Expand Up @@ -193,6 +193,16 @@ int : String -> Int -> QueryParameter
int key value =
QueryParameter (Url.percentEncode key) (String.fromInt value)

{-| Equivalent to Html.none, this does nothing.
Adds nothing to a query.
This is useful for the generation of dynamic urls.

absolute ["products"] [ string "search" "hat", none]
== absolute ["products"] [ string "search" "hat"]

-}
none : QueryParameter
none = QueryParameter "" ""

{-| Convert a list of query parameters to a percent-encoded query. This
function is used by `absolute`, `relative`, etc.
Expand Down Expand Up @@ -221,4 +231,6 @@ toQuery parameters =

toQueryPair : QueryParameter -> String
toQueryPair (QueryParameter key value) =
key ++ "=" ++ value
if QueryParameter key value == none
then ""
else key ++ "=" ++ value