From 41f1d2d2d62f869aa5674cc03072c14a423201bf Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Tue, 27 Feb 2018 23:07:07 -0500 Subject: [PATCH] docs(parsers): improve the parser examples --- docs/BaseBinding.html | 2 +- docs/ByteLengthParser.html | 10 ++++------ docs/CCTalkParser.html | 10 ++++------ docs/DelimiterParser.html | 12 +++++------- docs/Poller.html | 2 +- docs/ReadLineParser.html | 14 ++++++-------- docs/ReadyParser.html | 14 ++++++-------- docs/RegexParser.html | 14 ++++++-------- docs/SerialPort.html | 2 +- docs/bindings_base.js.html | 2 +- docs/bindings_poller.js.html | 2 +- docs/global.html | 2 +- docs/index.html | 2 +- docs/index.js.html | 2 +- docs/parsers_byte-length.js.html | 6 ++---- docs/parsers_cctalk.js.html | 6 ++---- docs/parsers_delimiter.js.html | 8 +++----- docs/parsers_index.js.html | 2 +- docs/parsers_readline.js.html | 7 +++---- docs/parsers_ready.js.html | 7 +++---- docs/parsers_regex.js.html | 8 +++----- docs/serialport.js.html | 2 +- lib/parsers/byte-length.js | 4 +--- lib/parsers/cctalk.js | 4 +--- lib/parsers/delimiter.js | 6 ++---- lib/parsers/readline.js | 5 ++--- lib/parsers/ready.js | 5 ++--- lib/parsers/regex.js | 6 ++---- 28 files changed, 67 insertions(+), 99 deletions(-) diff --git a/docs/BaseBinding.html b/docs/BaseBinding.html index 368b509..ad812b7 100644 --- a/docs/BaseBinding.html +++ b/docs/BaseBinding.html @@ -2383,7 +2383,7 @@
diff --git a/docs/ByteLengthParser.html b/docs/ByteLengthParser.html index 1937ac6..c70c3e4 100644 --- a/docs/ByteLengthParser.html +++ b/docs/ByteLengthParser.html @@ -69,7 +69,7 @@
Source:
@@ -118,14 +118,12 @@
Example
-
To use the `ByteLength` parser:
-```js
+    
// To use the `ByteLength` parser:
 const SerialPort = require('serialport');
 const ByteLength = SerialPort.parsers.ByteLength
 const port = new SerialPort('/dev/tty-usbserial1');
 const parser = port.pipe(new ByteLength({length: 8}));
-parser.on('data', console.log); // will have 8 bytes per data event
-```
+parser.on('data', console.log); // will have 8 bytes per data event
@@ -285,7 +283,7 @@ parser.on('data', console.log); // will have 8 bytes per data event
diff --git a/docs/CCTalkParser.html b/docs/CCTalkParser.html index 4dc30ec..146abc5 100644 --- a/docs/CCTalkParser.html +++ b/docs/CCTalkParser.html @@ -69,7 +69,7 @@
Source:
@@ -118,14 +118,12 @@
Example
-
CCTalk Messages are emitted as buffers.
-```js
+    
// CCTalk Messages are emitted as buffers.
 const SerialPort = require('serialport');
 const CCTalk = SerialPort.parsers.CCTalk;
 const port = new SerialPort('/dev/ttyUSB0');
 const parser = port.pipe(new CCtalk());
-parser.on('data', console.log);
-```
+parser.on('data', console.log);
@@ -187,7 +185,7 @@ parser.on('data', console.log);
diff --git a/docs/DelimiterParser.html b/docs/DelimiterParser.html index e7612ca..1dfdc13 100644 --- a/docs/DelimiterParser.html +++ b/docs/DelimiterParser.html @@ -69,7 +69,7 @@
Source:
@@ -118,14 +118,12 @@
Example
-
To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
-```js
+    
// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes:
 const SerialPort = require('serialport');
 const Delimiter = SerialPort.parsers.Delimiter;
 const port = new SerialPort('/dev/tty-usbserial1');
-const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') }));
-parser.on('data', console.log);
-```
+const parser = port.pipe(new Delimiter({ delimiter: '\n' })); +parser.on('data', console.log);
@@ -187,7 +185,7 @@ parser.on('data', console.log);
diff --git a/docs/Poller.html b/docs/Poller.html index a71de81..bd941d8 100644 --- a/docs/Poller.html +++ b/docs/Poller.html @@ -576,7 +576,7 @@
diff --git a/docs/ReadLineParser.html b/docs/ReadLineParser.html index df3b16a..421502e 100644 --- a/docs/ReadLineParser.html +++ b/docs/ReadLineParser.html @@ -43,7 +43,8 @@ ReadLineParser -

A transform stream that emits data after a newline delimiter is received.

+

A transform stream that emits data after a newline delimiter is received.

+

To use the Readline parser, provide a delimiter (defaults to \n). Data is emitted as string controllable by the encoding option (defaults to utf8).

@@ -69,7 +70,7 @@
Source:
@@ -118,14 +119,11 @@
Example
-
To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
-```js
-const SerialPort = require('serialport');
+    
const SerialPort = require('serialport');
 const Readline = SerialPort.parsers.Readline;
 const port = new SerialPort('/dev/tty-usbserial1');
 const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
-parser.on('data', console.log);
-```
+parser.on('data', console.log);
@@ -187,7 +185,7 @@ parser.on('data', console.log);
diff --git a/docs/ReadyParser.html b/docs/ReadyParser.html index 6a7a049..4045eca 100644 --- a/docs/ReadyParser.html +++ b/docs/ReadyParser.html @@ -43,7 +43,8 @@ ReadyParser -

A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events

+

A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events

+

To use the Ready parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through.

@@ -69,7 +70,7 @@
Source:
@@ -118,15 +119,12 @@
Example
-
To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through.
-```js
-const SerialPort = require('serialport');
+    
const SerialPort = require('serialport');
 const Ready = SerialPort.parsers.Ready;
 const port = new SerialPort('/dev/tty-usbserial1');
 const parser = port.pipe(new Ready({ delimiter: 'READY' }));
 parser.on('ready', () => console.log('the ready byte sequence has been received'))
-parser.on('data', console.log); // all data after READY is received
-```
+parser.on('data', console.log); // all data after READY is received
@@ -292,7 +290,7 @@ parser.on('data', console.log); // all data after READY is received
diff --git a/docs/RegexParser.html b/docs/RegexParser.html index 05344f3..56e1d0e 100644 --- a/docs/RegexParser.html +++ b/docs/RegexParser.html @@ -43,7 +43,8 @@ RegexParser -

A transform stream that uses a regular expression to split the incoming text upon.

+

A transform stream that uses a regular expression to split the incoming text upon.

+

To use the Regex parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the encoding option (defaults to utf8).

@@ -69,7 +70,7 @@
Source:
@@ -118,14 +119,11 @@
Example
-
To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
-```js
-const SerialPort = require('serialport');
+    
const SerialPort = require('serialport');
 const Regex = SerialPort.parsers.Regex;
 const port = new SerialPort('/dev/tty-usbserial1');
 const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }));
-parser.on('data', console.log);
-```
+parser.on('data', console.log);
@@ -187,7 +185,7 @@ parser.on('data', console.log);
diff --git a/docs/SerialPort.html b/docs/SerialPort.html index fa2868c..b9e1a90 100644 --- a/docs/SerialPort.html +++ b/docs/SerialPort.html @@ -2981,7 +2981,7 @@ function writeAndDrain (data, callback) {
diff --git a/docs/bindings_base.js.html b/docs/bindings_base.js.html index a59a6e3..94b10cb 100644 --- a/docs/bindings_base.js.html +++ b/docs/bindings_base.js.html @@ -280,7 +280,7 @@ module.exports = BaseBinding;
diff --git a/docs/bindings_poller.js.html b/docs/bindings_poller.js.html index 81a5505..94cbfb8 100644 --- a/docs/bindings_poller.js.html +++ b/docs/bindings_poller.js.html @@ -151,7 +151,7 @@ module.exports = Poller;
diff --git a/docs/global.html b/docs/global.html index a83adcf..8d21030 100644 --- a/docs/global.html +++ b/docs/global.html @@ -2027,7 +2027,7 @@ port.write('ROBOT PLEASE RESPOND\n');
diff --git a/docs/index.html b/docs/index.html index dd26ff1..8aa335a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -465,7 +465,7 @@ null
diff --git a/docs/index.js.html b/docs/index.js.html index 02b58dc..8660eaa 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -65,7 +65,7 @@ module.exports = SerialPort;
diff --git a/docs/parsers_byte-length.js.html b/docs/parsers_byte-length.js.html index 9a680ea..b58164c 100644 --- a/docs/parsers_byte-length.js.html +++ b/docs/parsers_byte-length.js.html @@ -47,14 +47,12 @@ const Transform = require('stream').Transform; * @param {Object} options parser options object * @param {Number} options.length the number of bytes on each data event * @example -To use the `ByteLength` parser: -```js +// To use the `ByteLength` parser: const SerialPort = require('serialport'); const ByteLength = SerialPort.parsers.ByteLength const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new ByteLength({length: 8})); parser.on('data', console.log); // will have 8 bytes per data event -``` */ class ByteLengthParser extends Transform { constructor(options) { @@ -109,7 +107,7 @@ module.exports = ByteLengthParser;
diff --git a/docs/parsers_cctalk.js.html b/docs/parsers_cctalk.js.html index 10fcb1c..82a7a36 100644 --- a/docs/parsers_cctalk.js.html +++ b/docs/parsers_cctalk.js.html @@ -44,14 +44,12 @@ const Buffer = require('safe-buffer').Buffer; * Parses the CCTalk protocol * @extends Transform * @example -CCTalk Messages are emitted as buffers. -```js +// CCTalk Messages are emitted as buffers. const SerialPort = require('serialport'); const CCTalk = SerialPort.parsers.CCTalk; const port = new SerialPort('/dev/ttyUSB0'); const parser = port.pipe(new CCtalk()); parser.on('data', console.log); -``` */ class CCTalkParser extends Transform { constructor() { @@ -94,7 +92,7 @@ module.exports = CCTalkParser;
diff --git a/docs/parsers_delimiter.js.html b/docs/parsers_delimiter.js.html index b2ba812..c889782 100644 --- a/docs/parsers_delimiter.js.html +++ b/docs/parsers_delimiter.js.html @@ -44,14 +44,12 @@ const Transform = require('stream').Transform; * A transform stream that emits data each time a byte sequence is received. * @extends Transform * @example -To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes: -```js +// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes: const SerialPort = require('serialport'); const Delimiter = SerialPort.parsers.Delimiter; const port = new SerialPort('/dev/tty-usbserial1'); -const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') })); +const parser = port.pipe(new Delimiter({ delimiter: '\n' })); parser.on('data', console.log); -``` */ class DelimiterParser extends Transform { constructor(options) { @@ -102,7 +100,7 @@ module.exports = DelimiterParser;
diff --git a/docs/parsers_index.js.html b/docs/parsers_index.js.html index 3bf95e1..7d5d75a 100644 --- a/docs/parsers_index.js.html +++ b/docs/parsers_index.js.html @@ -86,7 +86,7 @@ module.exports = {
diff --git a/docs/parsers_readline.js.html b/docs/parsers_readline.js.html index 6967411..6cbc3db 100644 --- a/docs/parsers_readline.js.html +++ b/docs/parsers_readline.js.html @@ -42,16 +42,15 @@ const Buffer = require('safe-buffer').Buffer; const DelimiterParser = require('./delimiter'); /** * A transform stream that emits data after a newline delimiter is received. + * + * To use the `Readline` parser, provide a delimiter (defaults to `\n`). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). * @extends DelimiterParser * @example -To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). -```js const SerialPort = require('serialport'); const Readline = SerialPort.parsers.Readline; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Readline({ delimiter: '\r\n' })); parser.on('data', console.log); -``` */ class ReadLineParser extends DelimiterParser { constructor(options) { @@ -81,7 +80,7 @@ module.exports = ReadLineParser;
diff --git a/docs/parsers_ready.js.html b/docs/parsers_ready.js.html index 0af3d55..773240f 100644 --- a/docs/parsers_ready.js.html +++ b/docs/parsers_ready.js.html @@ -42,17 +42,16 @@ const Buffer = require('safe-buffer').Buffer; const Transform = require('stream').Transform; /** * A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events + * + * To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through. * @extends Transform * @example -To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through. -```js const SerialPort = require('serialport'); const Ready = SerialPort.parsers.Ready; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Ready({ delimiter: 'READY' })); parser.on('ready', () => console.log('the ready byte sequence has been received')) parser.on('data', console.log); // all data after READY is received -``` */ class ReadyParser extends Transform { /** @@ -116,7 +115,7 @@ module.exports = ReadyParser;
diff --git a/docs/parsers_regex.js.html b/docs/parsers_regex.js.html index a3391f7..f6454ae 100644 --- a/docs/parsers_regex.js.html +++ b/docs/parsers_regex.js.html @@ -41,17 +41,15 @@ const Transform = require('stream').Transform; /** * A transform stream that uses a regular expression to split the incoming text upon. + * + * To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). * @extends Transform * @example -To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). -```js const SerialPort = require('serialport'); const Regex = SerialPort.parsers.Regex; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Regex({ regex: /[\r\n]+/ })); parser.on('data', console.log); -``` - */ class RegexParser extends Transform { constructor(options) { @@ -103,7 +101,7 @@ module.exports = RegexParser;
diff --git a/docs/serialport.js.html b/docs/serialport.js.html index 008d665..32065b7 100644 --- a/docs/serialport.js.html +++ b/docs/serialport.js.html @@ -684,7 +684,7 @@ module.exports = SerialPort;
diff --git a/lib/parsers/byte-length.js b/lib/parsers/byte-length.js index cd7cb50..91271be 100644 --- a/lib/parsers/byte-length.js +++ b/lib/parsers/byte-length.js @@ -8,14 +8,12 @@ const Transform = require('stream').Transform; * @param {Object} options parser options object * @param {Number} options.length the number of bytes on each data event * @example -To use the `ByteLength` parser: -```js +// To use the `ByteLength` parser: const SerialPort = require('serialport'); const ByteLength = SerialPort.parsers.ByteLength const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new ByteLength({length: 8})); parser.on('data', console.log); // will have 8 bytes per data event -``` */ class ByteLengthParser extends Transform { constructor(options) { diff --git a/lib/parsers/cctalk.js b/lib/parsers/cctalk.js index e895f86..de03a6c 100644 --- a/lib/parsers/cctalk.js +++ b/lib/parsers/cctalk.js @@ -5,14 +5,12 @@ const Buffer = require('safe-buffer').Buffer; * Parses the CCTalk protocol * @extends Transform * @example -CCTalk Messages are emitted as buffers. -```js +// CCTalk Messages are emitted as buffers. const SerialPort = require('serialport'); const CCTalk = SerialPort.parsers.CCTalk; const port = new SerialPort('/dev/ttyUSB0'); const parser = port.pipe(new CCtalk()); parser.on('data', console.log); -``` */ class CCTalkParser extends Transform { constructor() { diff --git a/lib/parsers/delimiter.js b/lib/parsers/delimiter.js index f9b7475..5653e7e 100644 --- a/lib/parsers/delimiter.js +++ b/lib/parsers/delimiter.js @@ -5,14 +5,12 @@ const Transform = require('stream').Transform; * A transform stream that emits data each time a byte sequence is received. * @extends Transform * @example -To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes: -```js +// To use the `Delimiter` parser, provide a delimiter as a string, buffer, or array of bytes: const SerialPort = require('serialport'); const Delimiter = SerialPort.parsers.Delimiter; const port = new SerialPort('/dev/tty-usbserial1'); -const parser = port.pipe(new Delimiter({ delimiter: Buffer.from('EOL') })); +const parser = port.pipe(new Delimiter({ delimiter: '\n' })); parser.on('data', console.log); -``` */ class DelimiterParser extends Transform { constructor(options) { diff --git a/lib/parsers/readline.js b/lib/parsers/readline.js index 3484371..c463f4b 100644 --- a/lib/parsers/readline.js +++ b/lib/parsers/readline.js @@ -3,16 +3,15 @@ const Buffer = require('safe-buffer').Buffer; const DelimiterParser = require('./delimiter'); /** * A transform stream that emits data after a newline delimiter is received. + * + * To use the `Readline` parser, provide a delimiter (defaults to `\n`). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). * @extends DelimiterParser * @example -To use the `Readline` parser, provide a delimiter (defaults to '\n'). Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). -```js const SerialPort = require('serialport'); const Readline = SerialPort.parsers.Readline; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Readline({ delimiter: '\r\n' })); parser.on('data', console.log); -``` */ class ReadLineParser extends DelimiterParser { constructor(options) { diff --git a/lib/parsers/ready.js b/lib/parsers/ready.js index c953ba7..e349554 100644 --- a/lib/parsers/ready.js +++ b/lib/parsers/ready.js @@ -3,17 +3,16 @@ const Buffer = require('safe-buffer').Buffer; const Transform = require('stream').Transform; /** * A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events + * + * To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through. * @extends Transform * @example -To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through. -```js const SerialPort = require('serialport'); const Ready = SerialPort.parsers.Ready; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Ready({ delimiter: 'READY' })); parser.on('ready', () => console.log('the ready byte sequence has been received')) parser.on('data', console.log); // all data after READY is received -``` */ class ReadyParser extends Transform { /** diff --git a/lib/parsers/regex.js b/lib/parsers/regex.js index fa4031b..977d04b 100644 --- a/lib/parsers/regex.js +++ b/lib/parsers/regex.js @@ -2,17 +2,15 @@ const Transform = require('stream').Transform; /** * A transform stream that uses a regular expression to split the incoming text upon. + * + * To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). * @extends Transform * @example -To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`). -```js const SerialPort = require('serialport'); const Regex = SerialPort.parsers.Regex; const port = new SerialPort('/dev/tty-usbserial1'); const parser = port.pipe(new Regex({ regex: /[\r\n]+/ })); parser.on('data', console.log); -``` - */ class RegexParser extends Transform { constructor(options) {