Skip to content

Commit 1fd91c8

Browse files
authored
Merge pull request #1 from purescript-node/joneshf/initial-work
Put together a `net` module
2 parents a78379f + 08cec42 commit 1fd91c8

File tree

14 files changed

+1094
-0
lines changed

14 files changed

+1094
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.*
2+
!/.gitignore
3+
!/.jscsrc
4+
!/.jshintrc
5+
!/.travis.yml
6+
/bower_components/
7+
/node_modules/
8+
/output/
9+
package-lock.json

.jscsrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"preset": "grunt",
3+
"disallowSpacesInFunctionExpression": null,
4+
"requireSpacesInFunctionExpression": {
5+
"beforeOpeningRoundBrace": true,
6+
"beforeOpeningCurlyBrace": true
7+
},
8+
"disallowSpacesInAnonymousFunctionExpression": null,
9+
"requireSpacesInAnonymousFunctionExpression": {
10+
"beforeOpeningRoundBrace": true,
11+
"beforeOpeningCurlyBrace": true
12+
},
13+
"disallowSpacesInsideObjectBrackets": null,
14+
"requireSpacesInsideObjectBrackets": "all",
15+
"validateQuoteMarks": "\"",
16+
"requireCurlyBraces": null
17+
}

.jshintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"bitwise": true,
3+
"eqeqeq": true,
4+
"forin": true,
5+
"freeze": true,
6+
"funcscope": true,
7+
"futurehostile": true,
8+
"strict": "global",
9+
"latedef": true,
10+
"noarg": true,
11+
"nocomma": true,
12+
"nonew": true,
13+
"notypeof": true,
14+
"singleGroups": true,
15+
"undef": true,
16+
"unused": true,
17+
"eqnull": true,
18+
"node": true
19+
}

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: 8
5+
env:
6+
- PATH=$HOME/purescript:$PATH
7+
install:
8+
- 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')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
12+
- npm install -g bower
13+
- npm install
14+
- bower install --production
15+
script:
16+
- npm run -s build
17+
after_success:
18+
- >-
19+
test $TRAVIS_TAG &&
20+
echo $GITHUB_TOKEN | pulp login &&
21+
echo y | pulp publish --no-push

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# purescript-node-net
2+
3+
[![Latest release](http://img.shields.io/github/release/purescript-node/purescript-node-net.svg)](https://github.com/purescript-node/purescript-node-net/releases)
4+
[![Build Status](https://travis-ci.org/purescript-node/purescript-node-net.svg?branch=master)](https://travis-ci.org/purescript-node/purescript-node-net)
5+
6+
A wrapper for Node's net API.
7+
8+
## Installation
9+
10+
```
11+
bower install purescript-node-net
12+
```
13+
14+
## Documentation
15+
16+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-node-net).

bower.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "purescript-node-net",
3+
"repository": {
4+
"type": "git",
5+
"url": "git://github.com/purescript-node/purescript-node-net"
6+
},
7+
"license": "MIT",
8+
"ignore": [
9+
"**/.*",
10+
"node_modules",
11+
"bower_components",
12+
"output"
13+
],
14+
"dependencies": {
15+
"purescript-effect": ">= 1.0.0 < 3",
16+
"purescript-either": ">= 1.0.0 < 5",
17+
"purescript-exceptions": ">= 4.0.0 < 5",
18+
"purescript-foreign": ">= 5.0.0 < 6",
19+
"purescript-maybe": ">= 1.0.0 < 5",
20+
"purescript-node-buffer": ">= 5.0.0 < 6",
21+
"purescript-node-fs": ">= 5.0.0 < 6",
22+
"purescript-nullable": ">= 3.0.0 < 5",
23+
"purescript-options": ">= 1.0.0 < 6",
24+
"purescript-prelude": ">= 4.0.0 < 5",
25+
"purescript-transformers": ">= 1.0.0 < 5"
26+
},
27+
"devDependencies": {
28+
"purescript-console": ">= 4.0.0 < 5"
29+
}
30+
}

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "jshint src && jscs src && pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
7+
},
8+
"devDependencies": {
9+
"jscs": "^3.0.7",
10+
"jshint": "^2.9.5",
11+
"pulp": "^12.2.0",
12+
"purescript-psa": "^0.6.0",
13+
"rimraf": "^2.6.2"
14+
}
15+
}

src/Node/Net.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
var net = require("net");
4+
5+
exports.isIP = net.isIP;
6+
7+
exports.isIPv4 = net.isIPv4;
8+
9+
exports.isIPv6 = net.isIPv6;

src/Node/Net.purs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Node.Net
2+
( isIP
3+
, isIPv4
4+
, isIPv6
5+
) where
6+
7+
-- | Returns `4` if the `String` is a valid IPv4 address, `6` if the `String`
8+
-- | is a valid IPv6 address, and `0` otherwise.
9+
foreign import isIP :: String -> Int
10+
11+
-- | Returns `true` if the `String` is a valid IPv4 address,
12+
-- | and `false` otherwise.
13+
foreign import isIPv4 :: String -> Boolean
14+
15+
-- | Returns `true` if the `String` is a valid IPv4 address,
16+
-- | and `false` otherwise.
17+
foreign import isIPv6 :: String -> Boolean

src/Node/Net/Server.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
var net = require("net");
4+
5+
exports.addressImpl = function (server) {
6+
return server.address();
7+
};
8+
9+
exports.closeImpl = function (server, callback) {
10+
server.close(callback);
11+
};
12+
13+
exports.createServerImpl = net.createServer;
14+
15+
exports.getConnectionsImpl = function (server, callback) {
16+
server.getConnections(callback);
17+
};
18+
19+
exports.listenImpl = function (server, options, callback) {
20+
server.listen(options, callback);
21+
};
22+
23+
exports.listeningImpl = function (socket) {
24+
return socket.listening;
25+
};
26+
27+
exports.onImpl = function (event, server, callback) {
28+
server.on(event, callback);
29+
};

0 commit comments

Comments
 (0)