@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 4.66 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import i from"./../../utils/define-nonenumerable-read-only-property.js";import e from"./../../vendor/process.js";import r from"./../../vendor/readable-stream.js";import t from"./../../assert/is-array-like-object.js";import o from"./../../assert/is-error.js";import s from"./../../assert/is-buffer.js";import n from"./../../utils/copy.js";import a from"./../../utils/inherit.js";import d from"./../../utils/define-nonenumerable-property.js";import p from"./../../buffer/from-string.js";import h from"./../../buffer/ctor.js";import m from"./../../assert/is-plain-object.js";import l from"./../../assert/has-own-property.js";import u from"./../../assert/is-boolean.js";import f from"./../../assert/is-nonnegative-number.js";import c from"./../../assert/is-nonnegative-integer.js";import g from"./../../assert/is-string.js";import b from"./../../assert/is-function.js";import _ from"./../../vendor/debug.js";var j=!1,v=null,y="\n",w=1e308,M=1,O={objectMode:j,encoding:v,sep:y,iter:w,dir:M},E=m,x=l,T=u.isPrimitive,z=f.isPrimitive,k=c.isPrimitive,S=g.isPrimitive,W=b;function V(i,e){return E(e)?x(e,"sep")&&(i.sep=e.sep,!S(i.sep))?new TypeError("invalid option. `sep` option must be a primitive string. Option: `"+i.sep+"`."):x(e,"objectMode")&&(i.objectMode=e.objectMode,!T(i.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+i.objectMode+"`."):x(e,"encoding")&&(i.encoding=e.encoding,!S(i.encoding)&&null!==i.encoding)?new TypeError("invalid option. `encoding` option must be a primitive string or null. Option: `"+i.encoding+"`."):x(e,"highWaterMark")&&(i.highWaterMark=e.highWaterMark,!z(i.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+i.highWaterMark+"`."):x(e,"serialize")&&(i.serialize=e.serialize,!W(i.serialize))?new TypeError("invalid option. `serialize` option must be a function. Option: `"+i.serialize+"`."):x(e,"iter")&&(i.iter=e.iter,!k(i.iter))?new TypeError("invalid option. `iter` option must be a nonnegative integer. Option: `"+i.iter+"`."):x(e,"dir")&&(i.dir=e.dir,1!==i.dir&&-1!==i.dir)?new TypeError("invalid option. `dir` option must be either `1` or `-1`. Option: `"+i.dir+"`."):null:new TypeError("invalid argument. Options must be an object. Value: `"+e+"`.")}var J=_,N=J("from-circular-array-stream"),P=r.Readable,C=t,F=o,I=s,A=n,B=a,R=d,q=i,D=p,G=h,H=O,K=V,L=N;function Q(){var i,e,r;if(!this._destroyed)for(i=!0;i;){if(e=null,this._i+=1,this._i>this._iter||0===this._src.length)return L("Finished iteration."),this.push(null);this._idx+=this._stride,this._stride>0&&this._idx>=this._src.length?this._idx%=this._src.length:this._stride<0&&this._idx<0&&(this._idx+=this._src.length),r=this._src[this._idx],L("Value: %s. Idx: %d. Iter: %d.",JSON.stringify(r),this._idx,this._i),!1===this._objectMode&&("string"==typeof(r=this._serialize(r))?r=1===this._i?D(r):D(this._sep+r):I(r)?this._i>1&&(r=G.concat([D(this._sep),r])):e=new Error("invalid operation. Serialization function must return a string or Buffer. Value: `"+r+"`.")),e?this.emit("error",e):i=this.push(r)}}function U(i){var r;return this._destroyed?(L("Attempted to destroy an already destroyed stream."),this):(r=this,this._destroyed=!0,e.nextTick((function(){i&&(L("Stream was destroyed due to an error. Error: %s.",F(i)?i.message:JSON.stringify(i)),r.emit("error",i));L("Closing the stream..."),r.emit("close")})),this)}function X(i,e){var r,t;if(!(this instanceof X))return arguments.length>1?new X(i,e):new X(i);if(!C(i))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+i+"`.");if(r=A(H),arguments.length>1&&(t=K(r,e)))throw t;return L("Creating a readable stream configured with the following options: %s.",JSON.stringify(r)),P.call(this,r),R(this,"_destroyed",!1),q(this,"_objectMode",r.objectMode),q(this,"_sep",r.sep),q(this,"_serialize",r.serialize||JSON.stringify),q(this,"_src",i),q(this,"_stride",r.dir),q(this,"_iter",r.iter),R(this,"_i",0),R(this,"_idx",1===r.dir?-1:i.length),this}B(X,P),q(X.prototype,"_read",Q),q(X.prototype,"destroy",U);var Y=m,Z=n,$=X;function ii(i,e){var r;if(arguments.length>1){if(!Y(r=e))throw new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.");r=Z(e,1)}else r={};return r.objectMode=!0,new $(i,r)}var ei=n,ri=X;function ti(i){var e;return e=arguments.length?ei(i,1):{},r;function r(i){return new ri(i,e)}}var oi=i,si=X,ni=ii,ai=ti;oi(si,"objectMode",ni),oi(si,"factory",ai);export default si;
//# sourceMappingURL=from-circular-array.js.map