Skip to content

Compiler/0.12 #10

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

Merged
merged 4 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ language: node_js
dist: trusty
sudo: required
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install
script:
- bower install --production
- npm run -s build
after_success:
- >-
Expand Down
12 changes: 6 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"package.json"
],
"dependencies": {
"purescript-prelude": "^3.0.0",
"purescript-globals": "^3.0.0",
"purescript-generics": "^4.0.0",
"purescript-maybe": "^3.0.0",
"purescript-strings": "^3.0.0",
"purescript-tuples": "^4.0.0"
"purescript-globals": "^4.0.0",
"purescript-maybe": "^4.0.0",
"purescript-newtype": "^3.0.0",
"purescript-prelude": "^4.0.0",
"purescript-strings": "^4.0.0",
"purescript-tuples": "^5.0.0"
}
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"build": "pulp build -- --censor-lib --strict"
},
"devDependencies": {
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.6.1"
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
32 changes: 12 additions & 20 deletions src/Data/FormURLEncoded.purs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
module Data.FormURLEncoded
( FormURLEncoded(FormURLEncoded)
, fromArray
, toArray
, encode
) where
module Data.FormURLEncoded where

import Prelude

import Data.Newtype (class Newtype)
import Data.Generic (class Generic)
import Data.Maybe (Maybe(..))
import Data.Monoid (class Monoid)
import Data.Semigroup (class Semigroup)
import Data.Newtype (class Newtype)
import Data.String (joinWith) as String
import Data.Tuple (Tuple(..))
import Global (encodeURIComponent)
import Prelude (class Show, class Ord, class Eq, map, (<<<), (<>))
import Global.Unsafe (unsafeEncodeURIComponent)

-- | `FormURLEncoded` is an ordered list of key-value pairs with possible duplicates.
newtype FormURLEncoded
= FormURLEncoded
(Array (Tuple String (Maybe String)))
newtype FormURLEncoded = FormURLEncoded (Array (Tuple String (Maybe String)))

-- | Construct `FormURLEncoded` from an `Array` of key-value pairs.
fromArray :: Array (Tuple String (Maybe String)) -> FormURLEncoded
Expand All @@ -28,18 +19,19 @@ fromArray = FormURLEncoded
toArray :: FormURLEncoded -> Array (Tuple String (Maybe String))
toArray (FormURLEncoded a) = a

derive instance genericFormUrlEncoded :: Generic FormURLEncoded
derive instance newtypeFormUrlEncoded :: Newtype FormURLEncoded _
derive newtype instance eqFormUrlEncoded :: Eq FormURLEncoded
derive newtype instance ordFormUrlEncoded :: Ord FormURLEncoded
derive newtype instance showFormUrlEncoded :: Show FormURLEncoded
derive newtype instance semigroupFormUrlEncoded :: Semigroup FormURLEncoded
derive newtype instance monoidFormUrlEncoded :: Monoid FormURLEncoded

instance showFormUrlEncoded :: Show FormURLEncoded where
show (FormURLEncoded kvs) = "(FormURLEncoded " <> show kvs <> ")"

-- | Encode `FormURLEncoded` as `application/x-www-form-urlencoded`.
encode :: FormURLEncoded -> String
encode = String.joinWith "&" <<< map encodePart <<< toArray
where
encodePart (Tuple k Nothing) = encodeURIComponent k
encodePart (Tuple k (Just v)) =
encodeURIComponent k <> "=" <> encodeURIComponent v
encodePart = case _ of
Tuple k Nothing -> unsafeEncodeURIComponent k
Tuple k (Just v) -> unsafeEncodeURIComponent k <> "=" <> unsafeEncodeURIComponent v