Skip to content

Commit 082af9c

Browse files
authored
Merge pull request #14 from garyb/updates
Updates
2 parents ae15716 + 1d25825 commit 082af9c

File tree

10 files changed

+405
-126
lines changed

10 files changed

+405
-126
lines changed

.eslintrc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true
8+
},
9+
"rules": {
10+
"strict": [2, "global"],
11+
"block-scoped-var": 2,
12+
"consistent-return": 2,
13+
"eqeqeq": [2, "smart"],
14+
"guard-for-in": 2,
15+
"no-caller": 2,
16+
"no-extend-native": 2,
17+
"no-loop-func": 2,
18+
"no-new": 2,
19+
"no-param-reassign": 2,
20+
"no-return-assign": 2,
21+
"no-unused-expressions": 2,
22+
"no-use-before-define": 2,
23+
"radix": [2, "always"],
24+
"indent": [2, 2],
25+
"quotes": [2, "double"],
26+
"semi": [2, "always"]
27+
}
28+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.*
22
!/.gitignore
3+
!/.eslintrc.json
34
!/.travis.yml
45
/bower_components/
56
/node_modules/

.travis.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
language: node_js
2-
sudo: required
3-
node_js: 6
4-
install:
5-
- npm install
6-
- npm install -g bower
7-
- bower install --production
8-
script:
9-
- npm run -s build
10-
- bower install
11-
- npm -s test
12-
after_success:
13-
- >-
14-
test $TRAVIS_TAG &&
15-
echo $GITHUB_AUTH_TOKEN | pulp login &&
16-
echo y | pulp publish --no-push
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: 6
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
script:
9+
- bower install --production
10+
- npm run -s build
11+
- bower install
12+
- npm -s test
13+
after_success:
14+
- >-
15+
test $TRAVIS_TAG &&
16+
echo $GITHUB_TOKEN | pulp login &&
17+
echo y | pulp publish --no-push

bower.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-globals": "^1.0.0",
21-
"purescript-integers": "^1.0.0",
22-
"purescript-maps": "^1.1.0",
23-
"purescript-pathy": "^2.0.0",
24-
"purescript-string-parsers": "^1.0.1",
25-
"purescript-unfoldable": "^1.0.0"
20+
"purescript-globals": "^2.0.0",
21+
"purescript-integers": "^2.0.0",
22+
"purescript-maps": "^2.0.0",
23+
"purescript-pathy": "^3.0.0",
24+
"purescript-string-parsers": "^2.0.0",
25+
"purescript-unfoldable": "^2.0.0"
26+
},
27+
"devDependencies": {
28+
"purescript-test-unit": "10.0.1"
2629
}
2730
}

package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
{
2-
"private": true,
3-
"scripts": {
4-
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build",
6-
"test": "pulp test"
7-
},
8-
"devDependencies": {
9-
"pulp": "^9.0.1",
10-
"rimraf": "^2.5.2",
11-
"purescript": "0.9.1"
12-
}
13-
}
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build --censor-lib --strict",
6+
"test": "pulp test"
7+
},
8+
"devDependencies": {
9+
"eslint": "^3.8.1",
10+
"pulp": "^9.0.1",
11+
"purescript": "^0.10.1",
12+
"purescript-psa": "^0.3.9",
13+
"rimraf": "^2.5.4"
14+
}
15+
}

src/Data/URI/Common.purs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import Data.Either (Either(..), fromRight)
99
import Data.List (List)
1010
import Data.Maybe (Maybe(..))
1111
import Data.String as S
12-
import Data.String.Regex as Rx
12+
import Data.String.Regex (Regex, regex)
13+
import Data.String.Regex.Flags as RXF
1314
import Data.Unfoldable (replicateA)
1415
import Partial.Unsafe (unsafePartial)
1516

16-
import Text.Parsing.StringParser (ParseError(ParseError), Parser(Parser), unParser)
17+
import Text.Parsing.StringParser (ParseError(..), Parser(..), unParser)
1718
import Text.Parsing.StringParser.String (string)
1819

1920
joinWith String List String String
@@ -24,7 +25,7 @@ rep n p = S.joinWith "" <$> replicateA n p
2425

2526
rxPat String Parser String
2627
rxPat rx =
27-
unsafePartial $ fromRight $ anyMatch <$> Rx.regex rx (Rx.noFlags { ignoreCase = true })
28+
unsafePartial $ fromRight $ anyMatch <$> regex rx RXF.ignoreCase
2829

2930
wrapParser a. Parser a Parser String Parser a
3031
wrapParser outer inner = Parser \ps → do
@@ -49,18 +50,18 @@ parsePCTEncoded = rxPat "%[0-9a-f]{2}"
4950
parseSubDelims Parser String
5051
parseSubDelims = rxPat "[!$&'()*+;=]"
5152

52-
anyMatch Rx.Regex Parser String
53+
anyMatch Regex Parser String
5354
anyMatch rx = Parser \{ str: str, pos: i } → case match1From rx i str of
5455
Just m → pure { result : m, suffix: { str: str, pos: i + (S.length m) }}
5556
NothingLeft { error: (ParseError $ "Expected " <> show rx), pos: i }
5657

57-
match1From Rx.Regex Int String Maybe String
58+
match1From Regex Int String Maybe String
5859
match1From = match1FromImpl Just Nothing
5960

6061
foreign import match1FromImpl
6162
( a. a Maybe a)
6263
( a. Maybe a)
63-
Rx.Regex
64+
Regex
6465
Int
6566
String
6667
(Maybe String)

src/Data/URI/Path.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ printPath = either printPath' printPath'
9494
printPath' a' b s'. Path a' b s' String
9595
printPath' path =
9696
let printed = unsafePrintPath path
97-
in fromMaybe printed $ Str.stripPrefix "./" printed
97+
in fromMaybe printed $ Str.stripPrefix (Str.Pattern "./") printed

src/Data/URI/Query.purs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Control.Alt ((<|>))
1111
import Data.Either (fromRight)
1212
import Data.List (List(..))
1313
import Data.Maybe (Maybe(..))
14-
import Data.String.Regex as Rgx
15-
import Data.StrMap (StrMap, fromList, toList)
14+
import Data.String.Regex as RX
15+
import Data.String.Regex.Flags as RXF
1616
import Data.Tuple (Tuple(..))
1717
import Data.URI.Common (joinWith, rxPat, parsePChar, wrapParser)
1818
import Data.URI.Types (Query(..))
@@ -29,18 +29,18 @@ parseQuery ∷ Parser Query
2929
parseQuery = Query <$> (wrapParser parseParts $
3030
try (joinWith "" <$> many (parsePChar <|> string "/" <|> string "?")))
3131

32-
parseParts Parser (StrMap (Maybe String))
33-
parseParts = fromList <$> sepBy parsePart (string ";" <|> string "&")
32+
parseParts Parser (List (Tuple String (Maybe String)))
33+
parseParts = sepBy parsePart (string ";" <|> string "&")
3434

3535
parsePart Parser (Tuple String (Maybe String))
3636
parsePart = do
37-
key ← rxPat "[^=]+"
37+
key ← rxPat "[^=;&]+"
3838
value ← optionMaybe $ string "=" *> rxPat "[^;&]*"
3939
pure $ Tuple (prettyDecodeURI key) (prettyDecodeURI <$> value)
4040

4141
printQuery Query String
4242
printQuery (Query m) =
43-
case toList m of
43+
case m of
4444
Nil""
4545
items → "?" <> joinWith "&" (printPart <$> items)
4646
where
@@ -49,13 +49,13 @@ printQuery (Query m) =
4949
printPart (Tuple k (Just v)) = prettyEncodeURI k <> "=" <> prettyEncodeURI v
5050

5151
prettyEncodeURI String String
52-
prettyEncodeURI = Rgx.replace rgxSpace "+" <<< encodeURIComponent
52+
prettyEncodeURI = RX.replace rgxSpace "+" <<< encodeURIComponent
5353

5454
prettyDecodeURI String String
55-
prettyDecodeURI = decodeURIComponent <<< Rgx.replace rgxPlus " "
55+
prettyDecodeURI = decodeURIComponent <<< RX.replace rgxPlus " "
5656

57-
rgxSpace Rgx.Regex
58-
rgxSpace = unsafePartial $ fromRight $ Rgx.regex "%20" (Rgx.noFlags { global = true })
57+
rgxSpace RX.Regex
58+
rgxSpace = unsafePartial $ fromRight $ RX.regex "%20" RXF.global
5959

60-
rgxPlus Rgx.Regex
61-
rgxPlus = unsafePartial $ fromRight $ Rgx.regex "\\+" (Rgx.noFlags { global = true })
60+
rgxPlus RX.Regex
61+
rgxPlus = unsafePartial $ fromRight $ RX.regex "\\+" RXF.global

src/Data/URI/Types.purs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module Data.URI.Types where
22

33
import Prelude
4-
54
import Data.Either (Either)
65
import Data.Generic (class Generic)
6+
import Data.List (List)
77
import Data.Maybe (Maybe)
88
import Data.Path.Pathy (Path, File, Dir, Abs, Rel, Sandboxed, Unsandboxed)
9-
import Data.StrMap (StrMap)
109
import Data.Tuple (Tuple)
1110

1211
-- | A generic URI
@@ -57,60 +56,60 @@ data Host
5756
type Port = Int
5857

5958
-- | The query component of a URI.
60-
newtype Query = Query (StrMap (Maybe String))
59+
newtype Query = Query (List (Tuple String (Maybe String)))
6160

6261
-- | The hash fragment of a URI.
6362
type Fragment = String
6463

6564
derive instance eqURIEq URI
6665

6766
instance showURIShow URI where
68-
show (URI s h q f) = "URI (" <> show s <> ") (" <> show h <> ") (" <> show q <> ") (" <> show f <> ")"
67+
show (URI s h q f) = "(URI " <> show s <> " " <> show h <> " " <> show q <> " " <> show f <> ")"
6968

7069
derive instance eqAbsoluteURIEq AbsoluteURI
7170

7271
instance showAbsoluteURIShow AbsoluteURI where
73-
show (AbsoluteURI s h q) = "AbsoluteURI (" <> show s <> ") (" <> show h <> ") (" <> show q <> ")"
72+
show (AbsoluteURI s h q) = "(AbsoluteURI " <> show s <> " " <> show h <> " " <> show q <> ")"
7473

7574
derive instance eqRelativeRefEq RelativeRef
7675

7776
instance showRelativeRefShow RelativeRef where
78-
show (RelativeRef r q f) = "RelativeRef (" <> show r <> ") (" <> show q <> ") (" <> show f <> ")"
77+
show (RelativeRef r q f) = "(RelativeRef " <> show r <> " " <> show q <> " " <> show f <> ")"
7978

8079
derive instance eqURISchemeEq URIScheme
8180
derive instance ordURISchemeOrd URIScheme
8281
derive instance genericURISchemeGeneric URIScheme
8382

8483
instance showURISchemeShow URIScheme where
85-
show (URIScheme s) = "URIScheme " <> show s
84+
show (URIScheme s) = "(URIScheme " <> show s <> ")"
8685

8786
derive instance eqHierarchicalPartEq HierarchicalPart
8887

8988
instance showHierarchicalPartShow HierarchicalPart where
90-
show (HierarchicalPart authority path) = "HierarchicalPart (" <> show authority <> ") (" <> show path <> ")"
89+
show (HierarchicalPart authority path) = "(HierarchicalPart " <> show authority <> " " <> show path <> ")"
9190

9291
derive instance eqRelativePartEq RelativePart
9392

9493
instance showRelativePartShow RelativePart where
95-
show (RelativePart authority path) = "RelativePart (" <> show authority <> ") (" <> show path <> ")"
94+
show (RelativePart authority path) = "(RelativePart " <> show authority <> " " <> show path <> ")"
9695

9796
derive instance eqAuthorityEq Authority
9897
derive instance ordAuthorityOrd Authority
9998
derive instance genericAuthorityGeneric Authority
10099

101100
instance showAuthorityShow Authority where
102-
show (Authority userinfo hosts) = "Authority (" <> show userinfo <> ") " <> show hosts
101+
show (Authority userinfo hosts) = "(Authority " <> show userinfo <> " " <> show hosts <> ")"
103102

104103
derive instance eqHostEq Host
105104
derive instance ordHostOrd Host
106105
derive instance genericQueryGeneric Host
107106

108107
instance showHostShow Host where
109-
show (IPv6Address ip) = "IPv6Address " <> show ip
110-
show (IPv4Address ip) = "IPv4Address " <> show ip
111-
show (NameAddress name) = "NameAddress " <> show name
108+
show (IPv6Address ip) = "(IPv6Address " <> show ip <> ")"
109+
show (IPv4Address ip) = "(IPv4Address " <> show ip <> ")"
110+
show (NameAddress name) = "(NameAddress " <> show name <> ")"
112111

113112
derive instance eqQueryEq Query
114113

115114
instance showQueryShow Query where
116-
show (Query m) = "Query (" <> show m <> ")"
115+
show (Query m) = "(Query (" <> show m <> "))"

0 commit comments

Comments
 (0)