Skip to content

Commit 007ffec

Browse files
committed
Initial commit
0 parents  commit 007ffec

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/bower_components/
2+
/node_modules/
3+
/output/
4+
/.psci*
5+
/src/.webpack.js

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 DICOM Grid, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bower.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "purescript-node-url",
3+
"version": "1.0.0",
4+
"moduleType": [
5+
"node"
6+
],
7+
"ignore": [
8+
"**/.*",
9+
"node_modules",
10+
"bower_components",
11+
"output"
12+
],
13+
"devDependencies": {
14+
"purescript-console": "^0.1.0"
15+
},
16+
"dependencies": {
17+
"purescript-nullable": "~0.2.1"
18+
}
19+
}

docs/Node/URL.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Module Node.URL
2+
3+
This module defines bindings to the Node URL and Query String APIs.
4+
5+
#### `Query`
6+
7+
``` purescript
8+
data Query
9+
```
10+
11+
A query object is a JavaScript object whose values are strings or arrays of strings.
12+
13+
It is intended that the user coerce values of this type to/from some trusted representation via
14+
e.g. `Data.Foreign` or `Unsafe.Coerce`..
15+
16+
#### `URL`
17+
18+
``` purescript
19+
type URL = { protocol :: Nullable String, slashes :: Nullable Boolean, host :: Nullable String, auth :: Nullable String, hostname :: Nullable String, port :: Nullable String, pathname :: Nullable String, search :: Nullable String, path :: Nullable String, query :: Nullable String, hash :: Nullable String }
20+
```
21+
22+
A URL object.
23+
24+
All fields are nullable, and will be missing if the URL string passed to
25+
`parse` did not contain the appropriate URL part.
26+
27+
#### `parse`
28+
29+
``` purescript
30+
parse :: String -> URL
31+
```
32+
33+
Parse a URL string into a URL object.
34+
35+
#### `format`
36+
37+
``` purescript
38+
format :: URL -> String
39+
```
40+
41+
Format a URL object as a URL string.
42+
43+
#### `resolve`
44+
45+
``` purescript
46+
resolve :: String -> String -> String
47+
```
48+
49+
Resolve a URL relative to some base URL.
50+
51+
#### `parseQueryString`
52+
53+
``` purescript
54+
parseQueryString :: String -> Query
55+
```
56+
57+
Convert a query string to an object.
58+
59+
#### `toQueryString`
60+
61+
``` purescript
62+
toQueryString :: Query -> String
63+
```
64+
65+
Convert a query string to an object.
66+
67+

src/Node/URL.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
// module Node.URL
4+
5+
var url = require('url');
6+
var queryString = require('querystring');
7+
8+
exports.parse = url.parse;
9+
10+
exports.format = url.format;
11+
12+
exports.resolve = function(from) {
13+
return function(to) {
14+
return url.resolve(from, to);
15+
}
16+
};
17+
18+
exports.parseQueryString = queryString.parse;
19+
20+
exports.toQueryString = queryString.stringify;

src/Node/URL.purs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- | This module defines bindings to the Node URL and Query String APIs.
2+
3+
module Node.URL where
4+
5+
import Data.Nullable
6+
7+
-- | A query object is a JavaScript object whose values are strings or arrays of strings.
8+
-- |
9+
-- | It is intended that the user coerce values of this type to/from some trusted representation via
10+
-- | e.g. `Data.Foreign` or `Unsafe.Coerce`..
11+
data Query
12+
13+
-- | A URL object.
14+
-- |
15+
-- | All fields are nullable, and will be missing if the URL string passed to
16+
-- | `parse` did not contain the appropriate URL part.
17+
type URL =
18+
{ protocol :: Nullable String
19+
, slashes :: Nullable Boolean
20+
, host :: Nullable String
21+
, auth :: Nullable String
22+
, hostname :: Nullable String
23+
, port :: Nullable String
24+
, pathname :: Nullable String
25+
, search :: Nullable String
26+
, path :: Nullable String
27+
, query :: Nullable String
28+
, hash :: Nullable String
29+
}
30+
31+
-- | Parse a URL string into a URL object.
32+
foreign import parse :: String -> URL
33+
34+
-- | Format a URL object as a URL string.
35+
foreign import format :: URL -> String
36+
37+
-- | Resolve a URL relative to some base URL.
38+
foreign import resolve :: String -> String -> String
39+
40+
-- | Convert a query string to an object.
41+
foreign import parseQueryString :: String -> Query
42+
43+
-- | Convert a query string to an object.
44+
foreign import toQueryString :: Query -> String

test/Main.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Test.Main where
2+
3+
import Control.Monad.Eff.Console
4+
5+
main = do
6+
log "You should add some tests."

0 commit comments

Comments
 (0)