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