Comparing version 2.0.0 to 2.0.2
@@ -5,20 +5,8 @@ 'use strict' | ||
const { Buffer } = require('buffer') | ||
const { getGlobalThis } = require('@offirmo/globalthis-ponyfill') | ||
// From https://mathiasbynens.be/notes/globalthis | ||
;/* istanbul ignore next: this is only for node 10 */ | ||
(function() { | ||
if (typeof globalThis === 'object') return | ||
Object.defineProperty(Object.prototype, '__magic__', { | ||
get: function() { | ||
return this | ||
}, | ||
configurable: true | ||
}) | ||
// eslint-disable-next-line no-undef | ||
__magic__.globalThis = __magic__ | ||
delete Object.prototype.__magic__ | ||
}()) | ||
let util = null | ||
let customInspect = Symbol.for('nodejs.util.inspect.custom') | ||
const gt = getGlobalThis() | ||
let TD = gt.TextDecoder | ||
try { | ||
@@ -28,10 +16,22 @@ util = require('util') | ||
/* istanbul ignore next */ | ||
if (typeof TextDecoder !== 'function') { | ||
if (typeof TD !== 'function') { | ||
// node 10 | ||
// eslint-disable-next-line no-undef | ||
globalThis.TextDecoder = util.TextDecoder | ||
TD = util.TextDecoder | ||
} | ||
} catch (ignored) { | ||
// Do without | ||
if (typeof TD !== 'function') { | ||
class TextDecoder { | ||
constructor(utfLabel, options) { | ||
this.utfLabel = utfLabel | ||
} | ||
decode(buf) { | ||
return buf.toString(this.utfLabel) | ||
} | ||
} | ||
TD = TextDecoder | ||
} | ||
} | ||
const td = new TextDecoder('utf8', {fatal: true, ignoreBOM: true}) | ||
const td = new TD('utf8', {fatal: true, ignoreBOM: true}) | ||
@@ -87,4 +87,4 @@ /** | ||
} | ||
let inp | ||
let inpE | ||
let inp = null | ||
let inpE = null | ||
switch (typeof(input)) { | ||
@@ -135,7 +135,8 @@ case 'object': | ||
throw new Error( | ||
'Do not switch objectMode in the middle of the stream') | ||
'Do not switch objectMode in the middle of the stream' | ||
) | ||
} | ||
this._readableState.objectMode = om | ||
return this._writableState.objectMode = om | ||
this._writableState.objectMode = om | ||
}) | ||
@@ -176,5 +177,4 @@ } | ||
return 0 | ||
} else { | ||
return nf1.compare(nf2) | ||
} | ||
return nf1.compare(nf2) | ||
} | ||
@@ -322,3 +322,3 @@ | ||
}) | ||
this.on('error', (er) => { | ||
this.on('error', er => { | ||
if ((cb != null) && !done) { | ||
@@ -346,11 +346,11 @@ done = true | ||
return 0 | ||
} else { | ||
const buf1 = this.slice() | ||
const buf2 = other.slice() | ||
// these will both be buffers because of the check above. | ||
if (Buffer.isBuffer(buf1) && Buffer.isBuffer(buf2)) { | ||
return buf1.compare(buf2) | ||
} | ||
throw new Error('Cannot compare streams in object mode') | ||
} | ||
const buf1 = this.slice() | ||
const buf2 = other.slice() | ||
// these will both be buffers because of the check above. | ||
if (Buffer.isBuffer(buf1) && Buffer.isBuffer(buf2)) { | ||
return buf1.compare(buf2) | ||
} | ||
throw new Error('Cannot compare streams in object mode') | ||
} | ||
@@ -388,3 +388,3 @@ | ||
case 1: return bufs[0].slice(start, end) | ||
default: | ||
default: { | ||
const b = Buffer.concat(bufs) | ||
@@ -394,2 +394,3 @@ // TODO: store the concatented bufs back | ||
return b.slice(start, end) | ||
} | ||
} | ||
@@ -422,5 +423,4 @@ } | ||
return b.toJSON() | ||
} else { | ||
return b | ||
} | ||
return b | ||
} | ||
@@ -463,15 +463,13 @@ | ||
const bufs = this._bufArray() | ||
const hex = bufs.map((b) => { | ||
const hex = bufs.map(b => { | ||
if (Buffer.isBuffer(b)) { | ||
if ((options != null ? options.stylize : undefined)) { | ||
return options.stylize(b.toString('hex'), 'string') | ||
} else { | ||
return b.toString('hex') | ||
} | ||
} else { | ||
if (util) { | ||
return util.inspect(b, options) | ||
} | ||
return b.toString() | ||
return b.toString('hex') | ||
} | ||
if (util) { | ||
return util.inspect(b, options) | ||
} | ||
return b.toString() | ||
}).join(', ') | ||
@@ -559,3 +557,5 @@ return `${this.constructor.name} [${hex}]` | ||
function _read_gen(meth, len) { | ||
// eslint-disable-next-line func-names | ||
return function(val) { | ||
// eslint-disable-next-line no-invalid-this | ||
const b = this.read(len) | ||
@@ -575,5 +575,7 @@ if (!Buffer.isBuffer(b)) { | ||
function _write_gen(meth, len) { | ||
// eslint-disable-next-line func-names | ||
return function(val) { | ||
const b = Buffer.alloc(len) | ||
b[meth].call(b, val, 0, true) | ||
// eslint-disable-next-line no-invalid-this | ||
return this.push(b) | ||
@@ -580,0 +582,0 @@ } |
{ | ||
"name": "nofilter", | ||
"version": "2.0.0", | ||
"version": "2.0.2", | ||
"description": "Read and write a growable buffer as a stream", | ||
@@ -38,6 +38,9 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@cto.af/eslint-config": "*", | ||
"@types/node": "^14.14.25", | ||
"chai": "^4.3", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.20.0", | ||
"eslint-plugin-chai-friendly": "^0.6.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"jsdoc": "^3.6.6", | ||
@@ -50,3 +53,6 @@ "minami": "^1.2.3", | ||
"node": ">=10.18" | ||
}, | ||
"dependencies": { | ||
"@offirmo/globalthis-ponyfill": "^3.0.1" | ||
} | ||
} |
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
26954
825
1
11
+ Added@offirmo/globalthis-ponyfill@3.0.2(transitive)