Skip to content

Commit d9399d2

Browse files
updating docs
1 parent 020d619 commit d9399d2

15 files changed

+192
-24
lines changed

.README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,91 @@ ${badge('devDependencies')}
1313

1414
`npm install --save ${pkg.name}`
1515

16-
## Usage & Examples
16+
## Documentation
1717

1818
Head on over to the [documentation](https://oaklabsinc.github.io/oak-tools/) page!
1919

20+
## Usage
21+
22+
`oak-tools` consists of a few helpful utility methods. Everything exposed from the module is a `Class` and needs to be constructed using `new`
23+
24+
**logger()**
25+
26+
The logger is based off [pino](https://github.com/pinojs/pino) and has nearly the same same option parameters. The following example are the default options.
27+
28+
```javascript
29+
const Logger = require('oak-tools').logger
30+
let log = new Logger({
31+
level: 'info',
32+
stream: process.stdout,
33+
pretty: true
34+
})
35+
36+
```
37+
38+
39+
40+
**server(_type_)**
41+
42+
The server is extended from a plain 'ol [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter). Head [here](https://oaklabsinc.github.io/oak-tools/WebSocketServer.html) for full documentation on the `server` class
43+
44+
```javascript
45+
const msgpack = require('msgpack5')()
46+
const Server = require('oak-tools').server('websocket')
47+
48+
// all these options are, well... optional
49+
let server = new Server({
50+
port: 9500,
51+
host: 'localhost',
52+
serializer: { encode, decode } = msgpack
53+
})
54+
55+
server
56+
.on('error', function (err) {
57+
console.error('* client error', err)
58+
})
59+
.on('connection', function (ID) {
60+
console.log('* client connection: ', ID)
61+
})
62+
.on('reconnect', function (ID) {
63+
console.log('* client reconnect: ', ID)
64+
})
65+
.on('close', function (ID) {
66+
console.log('* client closed', ID)
67+
})
68+
.on('who.is.the.man.now', function () {
69+
server.pub('heres.who', {
70+
answer: 'you are. http://www.yourethemannowdog.com/'
71+
})
72+
})
73+
```
74+
75+
**client(_type_)**
76+
77+
The `client` API is similar to `server`, but it has both a `sub` and a `pub` method.
78+
79+
```javascript
80+
const { join } = require('path')
81+
82+
let Client = require(join(__dirname, '..')).client('websocket')
83+
84+
let client = new Client({
85+
id: 'sean connery'
86+
})
87+
88+
client.on('open', function () {
89+
console.log('* client is connected')
90+
client
91+
.sub('heres.who')
92+
.on('heres.who', function ({ answer }) {
93+
console.log(answer)
94+
})
95+
.pub('who.is.the.man.now')
96+
})
97+
```
98+
99+
100+
20101
## Scripts
21102

22103
${scripts()}
@@ -31,8 +112,8 @@ Contributions welcome; Please submit all pull requests against the master branch
31112

32113
## Authors
33114

34-
- [Flynn Joffray](http://github.com/nucleardreamer) - <nucleardreamer@gmail.com>
35-
- [Nir Ziv](http://github.com/nirziv) - <nir@oaklabs.is>
115+
- [Flynn Joffray](http://github.com/nucleardreamer) - <nucleardreamer@gmail.com>
116+
- [Nir Ziv](http://github.com/nirziv) - <nir@oaklabs.is>
36117

37118
## License
38119

README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,91 @@ Helpful utilities for developing oak applications
1313

1414
`npm install --save oak-tools`
1515

16-
## Usage & Examples
16+
## Documentation
1717

1818
Head on over to the [documentation](https://oaklabsinc.github.io/oak-tools/) page!
1919

20+
## Usage
21+
22+
`oak-tools` consists of a few helpful utility methods. Everything exposed from the module is a `Class` and needs to be constructed using `new`
23+
24+
**logger()**
25+
26+
The logger is based off [pino](https://github.com/pinojs/pino) and has nearly the same same option parameters. The following example are the default options.
27+
28+
```javascript
29+
const Logger = require('oak-tools').logger
30+
let log = new Logger({
31+
level: 'info',
32+
stream: process.stdout,
33+
pretty: true
34+
})
35+
36+
```
37+
38+
39+
40+
**server(_type_)**
41+
42+
The server is extended from a plain 'ol [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter). Head [here](https://oaklabsinc.github.io/oak-tools/WebSocketServer.html) for full documentation on the `server` class
43+
44+
```javascript
45+
const msgpack = require('msgpack5')()
46+
const Server = require('oak-tools').server('websocket')
47+
48+
// all these options are, well... optional
49+
let server = new Server({
50+
port: 9500,
51+
host: 'localhost',
52+
serializer: { encode, decode } = msgpack
53+
})
54+
55+
server
56+
.on('error', function (err) {
57+
console.error('* client error', err)
58+
})
59+
.on('connection', function (ID) {
60+
console.log('* client connection: ', ID)
61+
})
62+
.on('reconnect', function (ID) {
63+
console.log('* client reconnect: ', ID)
64+
})
65+
.on('close', function (ID) {
66+
console.log('* client closed', ID)
67+
})
68+
.on('who.is.the.man.now', function () {
69+
server.pub('heres.who', {
70+
answer: 'you are. http://www.yourethemannowdog.com/'
71+
})
72+
})
73+
```
74+
75+
**client(_type_)**
76+
77+
The `client` API is similar to `server`, but it has both a `sub` and a `pub` method.
78+
79+
```javascript
80+
const { join } = require('path')
81+
82+
let Client = require(join(__dirname, '..')).client('websocket')
83+
84+
let client = new Client({
85+
id: 'sean connery'
86+
})
87+
88+
client.on('open', function () {
89+
console.log('* client is connected')
90+
client
91+
.sub('heres.who')
92+
.on('heres.who', function ({ answer }) {
93+
console.log(answer)
94+
})
95+
.pub('who.is.the.man.now')
96+
})
97+
```
98+
99+
100+
20101
## Scripts
21102

22103
- **npm run coverage** : `node node_modules/.bin/istanbul cover node_modules/.bin/tape test/*.js || true`
@@ -47,8 +128,8 @@ Contributions welcome; Please submit all pull requests against the master branch
47128

48129
## Authors
49130

50-
- [Flynn Joffray](http://github.com/nucleardreamer) - <nucleardreamer@gmail.com>
51-
- [Nir Ziv](http://github.com/nirziv) - <nir@oaklabs.is>
131+
- [Flynn Joffray](http://github.com/nucleardreamer) - <nucleardreamer@gmail.com>
132+
- [Nir Ziv](http://github.com/nirziv) - <nir@oaklabs.is>
52133

53134
## License
54135

docs/Logger.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ <h5>Returns:</h5>
378378
<br class="clear">
379379

380380
<footer>
381-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
381+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
382382
</footer>
383383

384384
<script>prettyPrint();</script>

docs/Message.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ <h5>Returns:</h5>
13091309
<br class="clear">
13101310

13111311
<footer>
1312-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1312+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
13131313
</footer>
13141314

13151315
<script>prettyPrint();</script>

docs/WebSocketClient.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ <h4 class="name" id="close"><span class="type-signature"></span>close<span class
979979

980980
<dt class="tag-source">Source:</dt>
981981
<dd class="tag-source"><ul class="dummy"><li>
982-
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line112">line 112</a>
982+
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line115">line 115</a>
983983
</li></ul></dd>
984984

985985

@@ -1219,7 +1219,7 @@ <h4 class="name" id="sub"><span class="type-signature"></span>sub<span class="si
12191219

12201220
<dt class="tag-source">Source:</dt>
12211221
<dd class="tag-source"><ul class="dummy"><li>
1222-
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line79">line 79</a>
1222+
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line80">line 80</a>
12231223
</li></ul></dd>
12241224

12251225

@@ -1355,7 +1355,7 @@ <h4 class="name" id="unsub"><span class="type-signature"></span>unsub<span class
13551355

13561356
<dt class="tag-source">Source:</dt>
13571357
<dd class="tag-source"><ul class="dummy"><li>
1358-
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line95">line 95</a>
1358+
<a href="lib_websocket_client.js.html">lib/websocket/client.js</a>, <a href="lib_websocket_client.js.html#line97">line 97</a>
13591359
</li></ul></dd>
13601360

13611361

@@ -1492,7 +1492,7 @@ <h5>Parameters:</h5>
14921492
<br class="clear">
14931493

14941494
<footer>
1495-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1495+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
14961496
</footer>
14971497

14981498
<script>prettyPrint();</script>

docs/WebSocketServer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ <h4 class="name" id="close"><span class="type-signature"></span>close<span class
542542

543543
<dt class="tag-source">Source:</dt>
544544
<dd class="tag-source"><ul class="dummy"><li>
545-
<a href="lib_websocket_server.js.html">lib/websocket/server.js</a>, <a href="lib_websocket_server.js.html#line171">line 171</a>
545+
<a href="lib_websocket_server.js.html">lib/websocket/server.js</a>, <a href="lib_websocket_server.js.html#line172">line 172</a>
546546
</li></ul></dd>
547547

548548

@@ -1212,7 +1212,7 @@ <h5>Type:</h5>
12121212
<br class="clear">
12131213

12141214
<footer>
1215-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1215+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
12161216
</footer>
12171217

12181218
<script>prettyPrint();</script>

docs/global.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ <h5>Type:</h5>
512512
<br class="clear">
513513

514514
<footer>
515-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
515+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
516516
</footer>
517517

518518
<script>prettyPrint();</script>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Logger.ht
5555
<br class="clear">
5656

5757
<footer>
58-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
58+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
5959
</footer>
6060

6161
<script>prettyPrint();</script>

docs/index.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ <h1 class="page-title">index.js</h1>
9494
<br class="clear">
9595

9696
<footer>
97-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
97+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
9898
</footer>
9999

100100
<script>prettyPrint();</script>

docs/lib_logger.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h1 class="page-title">lib/logger.js</h1>
8585
<br class="clear">
8686

8787
<footer>
88-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 21:46:11 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
88+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Thu Jan 19 2017 22:32:08 GMT-0800 (PST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
8989
</footer>
9090

9191
<script>prettyPrint();</script>

0 commit comments

Comments
 (0)