UNPKG

@stdlib/esm

Version:

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

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