// 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
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);
-```
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');
+
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
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).
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');
+
serialport-list will list all available
diff --git a/docs/index.js.html b/docs/index.js.html
index 02b58dc00..8660eaa41 100644
--- a/docs/index.js.html
+++ b/docs/index.js.html
@@ -65,7 +65,7 @@
* @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 @@
* 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 @@
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 @@
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 @@
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 @@
diff --git a/lib/parsers/byte-length.js b/lib/parsers/byte-length.js
index cd7cb5017..91271bec4 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 e895f8687..de03a6c96 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 f9b74757a..5653e7e20 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 348437199..c463f4b64 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 c953ba7b5..e3495545d 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 fa4031b64..977d04b78 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) {