@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 5.04 kB
JavaScript
// 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-positive-number.js";import o from"./../../assert/is-probability.js";import n from"./../../assert/is-error.js";import s from"./../../utils/copy.js";import a from"./../../utils/inherit.js";import p from"./../../utils/define-nonenumerable-property.js";import m from"./../../utils/define-read-only-accessor.js";import d from"./../../utils/define-read-write-accessor.js";import u from"./../base/negative-binomial.js";import h from"./../../buffer/from-string.js";import g from"./../../assert/is-plain-object.js";import f from"./../../assert/has-own-property.js";import l from"./../../assert/is-boolean.js";import c from"./../../assert/is-nonnegative-number.js";import b from"./../../assert/is-string.js";import y from"./../../assert/is-positive-integer.js";import v from"./../../assert/is-nonnegative-integer.js";import j from"./../../vendor/debug.js";var _=!1,w=null,M="\n",E=!0,T=1e308,O={objectMode:_,encoding:w,sep:M,copy:E,siter:T},P=g,k=f,L=l.isPrimitive,W=c.isPrimitive,S=b.isPrimitive,V=y.isPrimitive,N=v.isPrimitive;function G(e,t){return P(t)?k(t,"sep")&&(e.sep=t.sep,!S(e.sep))?new TypeError("invalid option. `sep` option must be a primitive string. Option: `"+e.sep+"`."):k(t,"objectMode")&&(e.objectMode=t.objectMode,!L(e.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+e.objectMode+"`."):k(t,"encoding")&&(e.encoding=t.encoding,!S(e.encoding)&&null!==e.encoding)?new TypeError("invalid option. `encoding` option must be a primitive string or null. Option: `"+e.encoding+"`."):k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!W(e.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+e.highWaterMark+"`."):k(t,"iter")&&(e.iter=t.iter,!N(e.iter))?new TypeError("invalid option. `iter` option must be a nonnegative integer. Option: `"+e.iter+"`."):k(t,"siter")&&(e.siter=t.siter,!V(e.siter))?new TypeError("invalid option. `siter` option must be a positive integer. Option: `"+e.siter+"`."):(k(t,"prng")&&(e.prng=t.prng),k(t,"seed")&&(e.seed=t.seed),k(t,"state")&&(e.state=t.state),k(t,"copy")&&(e.copy=t.copy),null):new TypeError("invalid argument. Options must be an object. Value: `"+t+"`.")}var R=j,x=R("random:streams:negative-binomial"),C=r.Readable,F=i.isPrimitive,J=o.isPrimitive,A=n,I=s,q=a,z=p,B=e,D=m,H=d,K=u.factory,Q=h,U=O,X=G,Y=x;function Z(){return this._prng.seed}function $(){return this._prng.seedLength}function ee(){return this._prng.stateLength}function te(){return this._prng.byteLength}function re(){return this._prng.state}function ie(e){this._prng.state=e}function oe(){var e,t;if(!this._destroyed)for(e=!0;e;){if(this._i+=1,this._i>this._iter)return Y("Finished generating pseudorandom numbers."),this.push(null);t=this._prng(),Y("Generated a new pseudorandom number. Value: %d. Iter: %d.",t,this._i),!1===this._objectMode&&(t=t.toString(),t=1===this._i?Q(t):Q(this._sep+t)),e=this.push(t),this._i%this._siter==0&&this.emit("state",this.state)}}function ne(e){var r;return this._destroyed?(Y("Attempted to destroy an already destroyed stream."),this):(r=this,this._destroyed=!0,t.nextTick((function(){e&&(Y("Stream was destroyed due to an error. Error: %s.",A(e)?e.message:JSON.stringify(e)),r.emit("error",e));Y("Closing the stream..."),r.emit("close")})),this)}function se(e,t,r){var i,o;if(!(this instanceof se))return arguments.length>2?new se(e,t,r):new se(e,t);if(!F(e))throw new TypeError("invalid argument. First argument must be a positive number. Value: `"+e+"`.");if(!J(t))throw new TypeError("invalid argument. Second argument must be a probability. Value: `"+t+"`.");if(i=I(U),arguments.length>2&&(o=X(i,r)))throw o;return Y("Creating a readable stream configured with the following options: %s.",JSON.stringify(i)),C.call(this,i),z(this,"_destroyed",!1),B(this,"_objectMode",i.objectMode),B(this,"_sep",i.sep),B(this,"_iter",i.iter),B(this,"_siter",i.siter),z(this,"_i",0),B(this,"_prng",K(e,t,i)),B(this,"PRNG",this._prng.PRNG),this}q(se,C),D(se.prototype,"seed",Z),D(se.prototype,"seedLength",$),H(se.prototype,"state",re,ie),D(se.prototype,"stateLength",ee),D(se.prototype,"byteLength",te),B(se.prototype,"_read",oe),B(se.prototype,"destroy",ne);var ae=g,pe=s,me=se;function de(e,t,r){var i;if(arguments.length>2){if(!ae(i=r))throw new TypeError("invalid argument. Options must be an object. Value: `"+i+"`.");i=pe(r,1)}else i={};return i.objectMode=!0,new me(e,t,i)}var ue=s,he=se;function ge(e,t,r){var i,o;return o=1===(i=arguments.length)?ue(e,1):i>2?ue(r,1):{},i<2?n:s;function n(e,t){return new he(e,t,o)}function s(){return new he(e,t,o)}}var fe=e,le=se,ce=de,be=ge;fe(le,"objectMode",ce),fe(le,"factory",be);export default le;
//# sourceMappingURL=negative-binomial.js.map