UNPKG

@stdlib/esm

Version:

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

3 lines 4.24 kB
// 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 p from"./../../utils/define-nonenumerable-property.js";import d from"./../../buffer/from-string.js";import m from"./../../buffer/ctor.js";import l from"./../../assert/is-plain-object.js";import h 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-string.js";import g from"./../../assert/is-function.js";import b from"./../../vendor/debug.js";var j=!1,y=null,v="\n",_=1,w={objectMode:j,encoding:y,sep:v,dir:_},M=l,O=h,E=u.isPrimitive,z=f.isPrimitive,T=c.isPrimitive,k=g;function x(i,e){return M(e)?O(e,"sep")&&(i.sep=e.sep,!T(i.sep))?new TypeError("invalid option. `sep` option must be a primitive string. Option: `"+i.sep+"`."):O(e,"objectMode")&&(i.objectMode=e.objectMode,!E(i.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+i.objectMode+"`."):O(e,"encoding")&&(i.encoding=e.encoding,!T(i.encoding)&&null!==i.encoding)?new TypeError("invalid option. `encoding` option must be a primitive string or null. Option: `"+i.encoding+"`."):O(e,"highWaterMark")&&(i.highWaterMark=e.highWaterMark,!z(i.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+i.highWaterMark+"`."):O(e,"serialize")&&(i.serialize=e.serialize,!k(i.serialize))?new TypeError("invalid option. `serialize` option must be a function. Option: `"+i.serialize+"`."):O(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 S=b,W=S("from-array-stream"),V=r.Readable,J=t,N=o,P=s,C=n,F=a,I=p,A=i,B=d,R=m,q=w,D=x,G=W;function H(){var i,e,r;if(!this._destroyed)for(i=!0;i;){if(e=null,this._i+=1,this._i>this._src.length)return G("Finished iteration."),this.push(null);r=this._src[this._idx],G("Value: %s. Idx: %d. Iter: %d.",JSON.stringify(r),this._idx,this._i),this._idx+=this._stride,!1===this._objectMode&&("string"==typeof(r=this._serialize(r))?r=1===this._i?B(r):B(this._sep+r):P(r)?this._i>1&&(r=R.concat([B(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 K(i){var r;return this._destroyed?(G("Attempted to destroy an already destroyed stream."),this):(r=this,this._destroyed=!0,e.nextTick((function(){i&&(G("Stream was destroyed due to an error. Error: %s.",N(i)?i.message:JSON.stringify(i)),r.emit("error",i));G("Closing the stream..."),r.emit("close")})),this)}function L(i,e){var r,t;if(!(this instanceof L))return arguments.length>1?new L(i,e):new L(i);if(!J(i))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+i+"`.");if(r=C(q),arguments.length>1&&(t=D(r,e)))throw t;return G("Creating a readable stream configured with the following options: %s.",JSON.stringify(r)),V.call(this,r),I(this,"_destroyed",!1),A(this,"_objectMode",r.objectMode),A(this,"_sep",r.sep),A(this,"_serialize",r.serialize||JSON.stringify),A(this,"_src",i),A(this,"_stride",r.dir),I(this,"_i",0),I(this,"_idx",1===r.dir?0:i.length-1),this}F(L,V),A(L.prototype,"_read",H),A(L.prototype,"destroy",K);var Q=l,U=n,X=L;function Y(i,e){var r;if(arguments.length>1){if(!Q(r=e))throw new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.");r=U(e,1)}else r={};return r.objectMode=!0,new X(i,r)}var Z=n,$=L;function ii(i){var e;return e=arguments.length?Z(i,1):{},r;function r(i){return new $(i,e)}}var ei=i,ri=L,ti=Y,oi=ii;ei(ri,"objectMode",ti),ei(ri,"factory",oi);export default ri; //# sourceMappingURL=from-array.js.map