UNPKG

@stdlib/esm

Version:

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

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