File tree Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 77
88A ` FormURLEncoded ` datatype represents an ordered list of key-value pairs
99with possible duplicates. ` encode ` function allows to transform ` FormURLEncoded `
10- into a string according to ` application/x-www-form-urlencoded ` .
10+ into a ` Maybe String ` according to ` application/x-www-form-urlencoded ` .
1111
1212Documentation is available on [ Pursuit] [ Pursuit ] .
1313
@@ -23,7 +23,7 @@ Example:
2323> encode (fromArray [ Tuple " hey" Nothing
2424> , Tuple " Oh" (Just " Let's go!" )
2525> ])
26- " hey&Oh=Let's%20go!"
26+ Just " hey&Oh=Let's%20go!"
2727```
2828
2929## Contributing
Original file line number Diff line number Diff line change 1414 " package.json"
1515 ],
1616 "dependencies" : {
17- "purescript-globals" : " ^4.0 .0" ,
17+ "purescript-globals" : " ^4.1 .0" ,
1818 "purescript-maybe" : " ^4.0.0" ,
1919 "purescript-newtype" : " ^3.0.0" ,
2020 "purescript-prelude" : " ^4.0.0" ,
2121 "purescript-strings" : " ^4.0.0" ,
22- "purescript-tuples" : " ^5.0.0"
22+ "purescript-tuples" : " ^5.0.0" ,
23+ "purescript-foldable-traversable" : " ^4.1.1"
2324 }
2425}
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ import Prelude
55import Data.Maybe (Maybe (..))
66import Data.Newtype (class Newtype )
77import Data.String (joinWith ) as String
8+ import Data.Traversable (traverse )
89import Data.Tuple (Tuple (..))
9- import Global.Unsafe ( unsafeEncodeURIComponent )
10+ import Global ( encodeURIComponent )
1011
1112-- | `FormURLEncoded` is an ordered list of key-value pairs with possible duplicates.
1213newtype FormURLEncoded = FormURLEncoded (Array (Tuple String (Maybe String )))
@@ -29,9 +30,9 @@ instance showFormUrlEncoded :: Show FormURLEncoded where
2930 show (FormURLEncoded kvs) = " (FormURLEncoded " <> show kvs <> " )"
3031
3132-- | Encode `FormURLEncoded` as `application/x-www-form-urlencoded`.
32- encode :: FormURLEncoded -> String
33- encode = String .joinWith " &" <<< map encodePart <<< toArray
33+ encode :: FormURLEncoded -> Maybe String
34+ encode = map ( String .joinWith " &" ) <<< traverse encodePart <<< toArray
3435 where
3536 encodePart = case _ of
36- Tuple k Nothing -> unsafeEncodeURIComponent k
37- Tuple k (Just v) -> unsafeEncodeURIComponent k <> " =" <> unsafeEncodeURIComponent v
37+ Tuple k Nothing -> encodeURIComponent k
38+ Tuple k (Just v) -> (\key val -> key <> " =" <> val) <$> encodeURIComponent k <*> encodeURIComponent v
You can’t perform that action at this time.
0 commit comments