parser-delimiter
Advanced tools
Comparing version 0.0.2 to 1.0.0
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
const Buffer = require('safe-buffer').Buffer; | ||
const Transform = require('stream').Transform; | ||
'use strict' | ||
const Buffer = require('safe-buffer').Buffer | ||
const Transform = require('stream').Transform | ||
/** | ||
@@ -16,37 +16,37 @@ * A transform stream that emits data each time a byte sequence is received. | ||
class DelimiterParser extends Transform { | ||
constructor(options) { | ||
options = options || {}; | ||
super(options); | ||
constructor (options) { | ||
options = options || {} | ||
super(options) | ||
if (options.delimiter === undefined) { | ||
throw new TypeError('"delimiter" is not a bufferable object'); | ||
throw new TypeError('"delimiter" is not a bufferable object') | ||
} | ||
if (options.delimiter.length === 0) { | ||
throw new TypeError('"delimiter" has a 0 or undefined length'); | ||
throw new TypeError('"delimiter" has a 0 or undefined length') | ||
} | ||
this.includeDelimiter = options.includeDelimiter !== undefined ? options.includeDelimiter : false; | ||
this.delimiter = Buffer.from(options.delimiter); | ||
this.buffer = Buffer.alloc(0); | ||
this.includeDelimiter = options.includeDelimiter !== undefined ? options.includeDelimiter : false | ||
this.delimiter = Buffer.from(options.delimiter) | ||
this.buffer = Buffer.alloc(0) | ||
} | ||
_transform(chunk, encoding, cb) { | ||
let data = Buffer.concat([this.buffer, chunk]); | ||
let position; | ||
_transform (chunk, encoding, cb) { | ||
let data = Buffer.concat([this.buffer, chunk]) | ||
let position | ||
while ((position = data.indexOf(this.delimiter)) !== -1) { | ||
this.push(data.slice(0, position + (this.includeDelimiter ? this.delimiter.length : 0))); | ||
data = data.slice(position + this.delimiter.length); | ||
this.push(data.slice(0, position + (this.includeDelimiter ? this.delimiter.length : 0))) | ||
data = data.slice(position + this.delimiter.length) | ||
} | ||
this.buffer = data; | ||
cb(); | ||
this.buffer = data | ||
cb() | ||
} | ||
_flush(cb) { | ||
this.push(this.buffer); | ||
this.buffer = Buffer.alloc(0); | ||
cb(); | ||
_flush (cb) { | ||
this.push(this.buffer) | ||
this.buffer = Buffer.alloc(0) | ||
cb() | ||
} | ||
}; | ||
module.exports = DelimiterParser; | ||
module.exports = DelimiterParser |
{ | ||
"name": "parser-delimiter", | ||
"main": "regex.js", | ||
"version": "0.0.2", | ||
"main": "delimiter.js", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"safe-buffer": "^5.1.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"docdash": "^0.4.0", | ||
"jsdoc": "^3.5.5" | ||
}, | ||
"license": "MIT", | ||
@@ -14,0 +9,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
1
1843