UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 4.25 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import r from"./../../utils/define-nonenumerable-read-only-property.js";import t from"./../../vendor/debug.js";import e from"./../../vendor/readable-stream.js";import o from"./../../utils/inherit.js";import n from"./../../utils/copy.js";import i from"./../../assert/is-plain-object.js";import s from"./../../assert/has-own-property.js";import a from"./../../assert/is-function.js";import f from"./../../assert/is-boolean.js";import l from"./../../assert/is-nonnegative-number.js";import m from"./../../assert/is-string.js";import p from"./../../vendor/process.js";var d=!1,u=null,h=!1,c=!0,g={objectMode:d,encoding:u,allowHalfOpen:h,decodeStrings:c},v=i,w=s,y=a,b=f.isPrimitive,j=l.isPrimitive,O=m.isPrimitive;function M(r,t){return v(t)?w(t,"transform")&&(r.transform=t.transform,!y(r.transform))?new TypeError("invalid option. `transform` option must be a function. Option: `"+r.transform+"`."):w(t,"flush")&&(r.flush=t.flush,!y(r.flush))?new TypeError("invalid option. `flush` option must be a function. Option: `"+r.flush+"`."):w(t,"objectMode")&&(r.objectMode=t.objectMode,!b(r.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+r.objectMode+"`."):w(t,"encoding")&&(r.encoding=t.encoding,!O(r.encoding))?new TypeError("invalid option. `encoding` option must be a primitive string. Option: `"+r.encoding+"`."):w(t,"allowHalfOpen")&&(r.allowHalfOpen=t.allowHalfOpen,!b(r.allowHalfOpen))?new TypeError("invalid option. `allowHalfOpen` option must be a primitive boolean. Option: `"+r.allowHalfOpen+"`."):w(t,"highWaterMark")&&(r.highWaterMark=t.highWaterMark,!j(r.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+r.highWaterMark+"`."):w(t,"decodeStrings")&&(r.decodeStrings=t.decodeStrings,!b(r.decodeStrings))?new TypeError("invalid option. `decodeStrings` option must be a primitive boolean. Option: `"+r.decodeStrings+"`."):null:new TypeError("invalid argument. Options must be an object. Value: `"+t+"`.")}var T=t,E=T("transform-stream:destroy");function S(r){var t;return this._destroyed?(E("Attempted to destroy an already destroyed stream."),this):(t=this,this._destroyed=!0,p.nextTick((function(){r&&(E("Stream was destroyed due to an error. Error: %s.",JSON.stringify(r)),t.emit("error",r));E("Closing the stream..."),t.emit("close")})),this)}var k=t,_=k("transform-stream:transform");function H(r,t,e){_("Received a new chunk. Chunk: %s. Encoding: %s.",r.toString(),t),e(null,r)}var W=t,C=e.Transform,J=o,N=n,P=g,V=M,x=S,A=H,R=W("transform-stream:main");function q(r){var t,e;if(!(this instanceof q))return arguments.length?new q(r):new q;if(t=N(P),arguments.length&&(e=V(t,r)))throw e;return R("Creating a transform stream configured with the following options: %s.",JSON.stringify(t)),C.call(this,t),this._destroyed=!1,t.transform?this._transform=t.transform:this._transform=A,t.flush&&(this._flush=t.flush),this}J(q,C),q.prototype.destroy=x;var z=i,B=n,D=q;function F(r){var t;if(arguments.length){if(!z(r))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.");t=B(r)}else t={};return t.objectMode=!0,new D(t)}var G=i,I=n,K=q;function L(r){var t;if(arguments.length){if(!G(r))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.");t=I(r)}else t={};return e;function e(r,e){return t.transform=r,arguments.length>1?t.flush=e:delete t.flush,new K(t)}}var Q=t,U=e.Transform,X=o,Y=n,Z=g,$=M,rr=S,tr=H,er=Q("transform-stream:ctor");function or(r){var t,e,o;if(e=Y(Z),arguments.length&&(o=$(e,r)))throw o;function n(r){var t,o;if(!(this instanceof n))return arguments.length?new n(r):new n;if(t=Y(e),arguments.length&&(o=$(t,r)))throw o;return er("Creating a transform stream configured with the following options: %s.",JSON.stringify(t)),U.call(this,t),this._destroyed=!1,this}return t=e.transform?e.transform:tr,X(n,U),n.prototype._transform=t,e.flush&&(n.prototype._flush=e.flush),n.prototype.destroy=rr,n}var nr=r,ir=q,sr=F,ar=L,fr=or;nr(ir,"objectMode",sr),nr(ir,"factory",ar),nr(ir,"ctor",fr);export default ir; //# sourceMappingURL=transform.js.map