Add Robot_JoyIt driver
This commit is contained in:
44
node_modules/stream-json/streamers/StreamArray.js
generated
vendored
Normal file
44
node_modules/stream-json/streamers/StreamArray.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const StreamBase = require('./StreamBase');
|
||||
const withParser = require('../utils/withParser');
|
||||
|
||||
class StreamArray extends StreamBase {
|
||||
static make(options) {
|
||||
return new StreamArray(options);
|
||||
}
|
||||
|
||||
static withParser(options) {
|
||||
return withParser(StreamArray.make, options);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._level = 1;
|
||||
this._counter = 0;
|
||||
}
|
||||
|
||||
_wait(chunk, _, callback) {
|
||||
// first chunk should open an array
|
||||
if (chunk.name !== 'startArray') {
|
||||
return callback(new Error('Top-level object should be an array.'));
|
||||
}
|
||||
this._transform = this._filter;
|
||||
return this._transform(chunk, _, callback);
|
||||
}
|
||||
|
||||
_push(discard) {
|
||||
if (this._assembler.current.length) {
|
||||
if (discard) {
|
||||
++this._counter;
|
||||
this._assembler.current.pop();
|
||||
} else {
|
||||
this.push({key: this._counter++, value: this._assembler.current.pop()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StreamArray.streamArray = StreamArray.make;
|
||||
StreamArray.make.Constructor = StreamArray;
|
||||
|
||||
module.exports = StreamArray;
|
||||
101
node_modules/stream-json/streamers/StreamBase.js
generated
vendored
Normal file
101
node_modules/stream-json/streamers/StreamBase.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
const {Transform} = require('stream');
|
||||
const Assembler = require('../Assembler');
|
||||
|
||||
class Counter {
|
||||
constructor(initialDepth) {
|
||||
this.depth = initialDepth;
|
||||
}
|
||||
startObject() {
|
||||
++this.depth;
|
||||
}
|
||||
endObject() {
|
||||
--this.depth;
|
||||
}
|
||||
startArray() {
|
||||
++this.depth;
|
||||
}
|
||||
endArray() {
|
||||
--this.depth;
|
||||
}
|
||||
}
|
||||
|
||||
class StreamBase extends Transform {
|
||||
constructor(options) {
|
||||
super(Object.assign({}, options, {writableObjectMode: true, readableObjectMode: true}));
|
||||
if (options) {
|
||||
this.objectFilter = options.objectFilter;
|
||||
this.includeUndecided = options.includeUndecided;
|
||||
}
|
||||
if (typeof this.objectFilter != 'function') {
|
||||
this._filter = this._transform;
|
||||
}
|
||||
this._transform = this._wait || this._filter;
|
||||
this._assembler = new Assembler(options);
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
if (this._assembler[chunk.name]) {
|
||||
this._assembler[chunk.name](chunk.value);
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._push();
|
||||
}
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
|
||||
_filter(chunk, encoding, callback) {
|
||||
if (this._assembler[chunk.name]) {
|
||||
this._assembler[chunk.name](chunk.value);
|
||||
const result = this.objectFilter(this._assembler);
|
||||
if (result) {
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._push();
|
||||
this._transform = this._filter;
|
||||
}
|
||||
this._transform = this._accept;
|
||||
return callback(null);
|
||||
}
|
||||
if (result === false) {
|
||||
this._saved_assembler = this._assembler;
|
||||
this._assembler = new Counter(this._saved_assembler.depth);
|
||||
this._saved_assembler.dropToLevel(this._level);
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._assembler = this._saved_assembler;
|
||||
this._transform = this._filter;
|
||||
}
|
||||
this._transform = this._reject;
|
||||
return callback(null);
|
||||
}
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._push(!this.includeUndecided);
|
||||
}
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
|
||||
_accept(chunk, encoding, callback) {
|
||||
if (this._assembler[chunk.name]) {
|
||||
this._assembler[chunk.name](chunk.value);
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._push();
|
||||
this._transform = this._filter;
|
||||
}
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
|
||||
_reject(chunk, encoding, callback) {
|
||||
if (this._assembler[chunk.name]) {
|
||||
this._assembler[chunk.name](chunk.value);
|
||||
if (this._assembler.depth === this._level) {
|
||||
this._assembler = this._saved_assembler;
|
||||
this._transform = this._filter;
|
||||
}
|
||||
}
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StreamBase;
|
||||
43
node_modules/stream-json/streamers/StreamObject.js
generated
vendored
Normal file
43
node_modules/stream-json/streamers/StreamObject.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const StreamBase = require('./StreamBase');
|
||||
const withParser = require('../utils/withParser');
|
||||
|
||||
class StreamObject extends StreamBase {
|
||||
static make(options) {
|
||||
return new StreamObject(options);
|
||||
}
|
||||
|
||||
static withParser(options) {
|
||||
return withParser(StreamObject.make, options);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._level = 1;
|
||||
this._lastKey = null;
|
||||
}
|
||||
|
||||
_wait(chunk, _, callback) {
|
||||
// first chunk should open an array
|
||||
if (chunk.name !== 'startObject') {
|
||||
return callback(new Error('Top-level object should be an object.'));
|
||||
}
|
||||
this._transform = this._filter;
|
||||
return this._transform(chunk, _, callback);
|
||||
}
|
||||
|
||||
_push(discard) {
|
||||
if (this._lastKey === null) {
|
||||
this._lastKey = this._assembler.key;
|
||||
} else {
|
||||
!discard && this.push({key: this._lastKey, value: this._assembler.current[this._lastKey]});
|
||||
this._assembler.current = {};
|
||||
this._lastKey = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
StreamObject.streamObject = StreamObject.make;
|
||||
StreamObject.make.Constructor = StreamObject;
|
||||
|
||||
module.exports = StreamObject;
|
||||
33
node_modules/stream-json/streamers/StreamValues.js
generated
vendored
Normal file
33
node_modules/stream-json/streamers/StreamValues.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const StreamBase = require('./StreamBase');
|
||||
const withParser = require('../utils/withParser');
|
||||
|
||||
class StreamValues extends StreamBase {
|
||||
static make(options) {
|
||||
return new StreamValues(options);
|
||||
}
|
||||
|
||||
static withParser(options) {
|
||||
return withParser(StreamValues.make, Object.assign({}, options, {jsonStreaming: true}));
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._counter = 0;
|
||||
this._level = 0;
|
||||
}
|
||||
|
||||
_push(discard) {
|
||||
if (discard) {
|
||||
++this._counter;
|
||||
} else {
|
||||
this.push({key: this._counter++, value: this._assembler.current});
|
||||
}
|
||||
this._assembler.current = this._assembler.key = null;
|
||||
}
|
||||
}
|
||||
StreamValues.streamValues = StreamValues.make;
|
||||
StreamValues.make.Constructor = StreamValues;
|
||||
|
||||
module.exports = StreamValues;
|
||||
Reference in New Issue
Block a user