UNPKG

@stdlib/esm

Version:

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

3 lines 4.15 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 r from"./../../vendor/process.js";import t from"./../../vendor/readable-stream.js";import i from"./../../assert/is-error.js";import o from"./../../assert/is-string.js";import n from"./../../assert/is-buffer.js";import s from"./../../assert/is-uint8array.js";import a from"./../../buffer/from-arraybuffer.js";import p from"./../../buffer/from-string.js";import m from"./../../buffer/ctor.js";import f from"./../../utils/copy.js";import u from"./../../utils/inherit.js";import d from"./../../utils/define-nonenumerable-property.js";import h from"./../../assert/is-plain-object.js";import l from"./../../assert/has-own-property.js";import c from"./../../assert/is-boolean.js";import b from"./../../assert/is-nonnegative-number.js";import g from"./../../assert/is-nonnegative-integer.js";import v from"./../../vendor/debug.js";var j=!1,y=null,M="\n",w=1e308,_={objectMode:j,encoding:y,sep:M,iter:w},O=h,E=l,T=c.isPrimitive,k=b.isPrimitive,W=o.isPrimitive,P=g.isPrimitive;function V(e,r){return O(r)?E(r,"sep")&&(e.sep=r.sep,!W(e.sep))?new TypeError("invalid option. `sep` option must be a primitive string. Option: `"+e.sep+"`."):E(r,"objectMode")&&(e.objectMode=r.objectMode,!T(e.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+e.objectMode+"`."):E(r,"encoding")&&(e.encoding=r.encoding,!W(e.encoding)&&null!==e.encoding)?new TypeError("invalid option. `encoding` option must be a primitive string or null. Option: `"+e.encoding+"`."):E(r,"highWaterMark")&&(e.highWaterMark=r.highWaterMark,!k(e.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+e.highWaterMark+"`."):E(r,"iter")&&(e.iter=r.iter,!P(e.iter))?new TypeError("invalid option. `iter` option must be a nonnegative integer. Option: `"+e.iter+"`."):null:new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.")}var S=v,x=S("from-constant-stream"),A=t.Readable,C=i,I=o.isPrimitive,J=n,N=s,B=a,F=p,R=m,U=f,q=u,z=d,D=e,G=_,H=V,K=x;function L(){var e;if(!this._destroyed)for(e=!0;e;){if(this._i+=1,this._i>this._iter)return K("Finished iteration."),this.push(null);K("Value: %s. Iter: %d.",this._value,this._i),e=!1===this._objectMode&&this._i>1?this.push(R.concat([this._sep,this._value])):this.push(this._value)}}function Q(e){var t;return this._destroyed?(K("Attempted to destroy an already destroyed stream."),this):(t=this,this._destroyed=!0,r.nextTick((function(){e&&(K("Stream was destroyed due to an error. Error: %s.",C(e)?e.message:JSON.stringify(e)),t.emit("error",e));K("Closing the stream..."),t.emit("close")})),this)}function X(e,r){var t,i;if(!(this instanceof X))return arguments.length>1?new X(e,r):new X(e);if(t=U(G),arguments.length>1&&(i=H(t,r)))throw i;if(!1===t.objectMode)if(I(e))e=F(e);else if(J(e));else{if(!N(e))throw new TypeError("invalid argument. In binary mode, a provided value must be a string, Buffer, or Uint8Array. Value: `"+e+"`.");e=B(e.buffer,e.byteOffset,e.length)}return K("Creating a readable stream configured with the following options: %s.",JSON.stringify(t)),A.call(this,t),z(this,"_destroyed",!1),D(this,"_objectMode",t.objectMode),D(this,"_sep",F(t.sep)),D(this,"_iter",t.iter),D(this,"_value",e),z(this,"_i",0),this}q(X,A),D(X.prototype,"_read",L),D(X.prototype,"destroy",Q);var Y=h,Z=f,$=X;function ee(e,r){var t;if(arguments.length>1){if(!Y(t=r))throw new TypeError("invalid argument. Options must be an object. Value: `"+t+"`.");t=Z(r,1)}else t={};return t.objectMode=!0,new $(e,t)}var re=l,te=f,ie=X;function oe(e,r){var t,i,o;return 0===(t=arguments.length)?(i={},o=!0):1===t?null!==e&&"object"==typeof e&&(re(e,"sep")||re(e,"iter")||re(e,"objectMode")||re(e,"encoding")||re(e,"highWaterMark"))?(i=te(e,1),o=!0):i={}:i=te(r,1),o?n:s;function n(e){return new ie(e,i)}function s(){return new ie(e,i)}}var ne=e,se=X,ae=ee,pe=oe;ne(se,"objectMode",ae),ne(se,"factory",pe);export default se; //# sourceMappingURL=from-constant.js.map