UNPKG

@stdlib/esm

Version:

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

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