Skip to content

Commit

Permalink
fix: add plain object checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Jul 26, 2023
1 parent d27583e commit 7118ce2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// MODULES //

var isPositive = require( '@stdlib/assert/is-positive-number' ).isPrimitive;
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -68,13 +71,19 @@ function factory( lambda, options ) {

nargs = arguments.length;
if ( nargs > 1 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
fcn = createStream2;
opts = assign( {}, options );
} else if ( nargs === 1 ) {
if ( isPositive( lambda ) ) {
fcn = createStream2;
opts = {};
} else {
if ( !isPlainObject( lambda ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', lambda ) );
}
opts = assign( {}, lambda );
fcn = createStream1;
}
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/random/streams/f/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

// MODULES //

var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -68,8 +71,14 @@ function factory( d1, d2, options ) {

nargs = arguments.length;
if ( nargs === 1 ) {
if ( !isPlainObject( d1 ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', d1 ) );
}
opts = assign( {}, d1 );
} else if ( nargs > 2 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
opts = assign( {}, options );
} else {
opts = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

// MODULES //

var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -43,6 +45,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -69,8 +72,14 @@ function factory( alpha, s, m, options ) {

nargs = arguments.length;
if ( nargs === 1 ) {
if ( !isPlainObject( alpha ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', alpha ) );
}
opts = assign( {}, alpha );
} else if ( nargs > 3 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
opts = assign( {}, options );
} else {
opts = {};
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/random/streams/gamma/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

// MODULES //

var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -68,8 +71,14 @@ function factory( alpha, beta, options ) {

nargs = arguments.length;
if ( nargs === 1 ) {
if ( !isPlainObject( alpha ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', alpha ) );
}
opts = assign( {}, alpha );
} else if ( nargs > 2 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
opts = assign( {}, options );
} else {
opts = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// MODULES //

var isProbability = require( '@stdlib/assert/is-probability' ).isPrimitive;
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -68,13 +71,19 @@ function factory( p, options ) {

nargs = arguments.length;
if ( nargs > 1 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
fcn = createStream2;
opts = assign( {}, options );
} else if ( nargs === 1 ) {
if ( isProbability( p ) ) {
fcn = createStream2;
opts = {};
} else {
if ( !isPlainObject( p ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', p ) );
}
opts = assign( {}, p );
fcn = createStream1;
}
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/random/streams/gumbel/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

// MODULES //

var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var assign = require( '@stdlib/object/assign' );
var format = require( '@stdlib/string/format' );
var RandomStream = require( './main.js' );


Expand All @@ -42,6 +44,7 @@ var RandomStream = require( './main.js' );
* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state
* @throws {TypeError} options argument must be an object
* @returns {Function} stream factory
*
* @example
Expand All @@ -68,8 +71,14 @@ function factory( mu, beta, options ) {

nargs = arguments.length;
if ( nargs === 1 ) {
if ( !isPlainObject( mu ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', mu ) );
}
opts = assign( {}, mu );
} else if ( nargs > 2 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
opts = assign( {}, options );
} else {
opts = {};
Expand Down

1 comment on commit 7118ce2

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
random/streams/exponential 812/812 92/92 15/15 812/812
random/streams/f 819/819 95/95 15/15 819/819
random/streams/frechet 832/832 98/98 15/15 832/832
random/streams/gamma 819/819 95/95 15/15 819/819
random/streams/geometric 812/812 92/92 15/15 812/812
random/streams/gumbel 821/821 96/96 15/15 821/821

Please sign in to comment.