From 7118ce2be998805e028aff506afa4df4bf037eff Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 26 Jul 2023 19:05:45 -0400 Subject: [PATCH] fix: add plain object checks --- .../@stdlib/random/streams/exponential/lib/factory.js | 9 +++++++++ lib/node_modules/@stdlib/random/streams/f/lib/factory.js | 9 +++++++++ .../@stdlib/random/streams/frechet/lib/factory.js | 9 +++++++++ .../@stdlib/random/streams/gamma/lib/factory.js | 9 +++++++++ .../@stdlib/random/streams/geometric/lib/factory.js | 9 +++++++++ .../@stdlib/random/streams/gumbel/lib/factory.js | 9 +++++++++ 6 files changed, 54 insertions(+) diff --git a/lib/node_modules/@stdlib/random/streams/exponential/lib/factory.js b/lib/node_modules/@stdlib/random/streams/exponential/lib/factory.js index 00b768b5af84..d50fa1c95b7a 100644 --- a/lib/node_modules/@stdlib/random/streams/exponential/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/exponential/lib/factory.js @@ -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' ); @@ -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 @@ -68,6 +71,9 @@ 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 ) { @@ -75,6 +81,9 @@ function factory( lambda, options ) { 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; } diff --git a/lib/node_modules/@stdlib/random/streams/f/lib/factory.js b/lib/node_modules/@stdlib/random/streams/f/lib/factory.js index 7eaf9cdcf74d..1b210ab21ba3 100644 --- a/lib/node_modules/@stdlib/random/streams/f/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/f/lib/factory.js @@ -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' ); @@ -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 @@ -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 = {}; diff --git a/lib/node_modules/@stdlib/random/streams/frechet/lib/factory.js b/lib/node_modules/@stdlib/random/streams/frechet/lib/factory.js index 1eea17af2010..54f39ee888e3 100644 --- a/lib/node_modules/@stdlib/random/streams/frechet/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/frechet/lib/factory.js @@ -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' ); @@ -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 @@ -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 = {}; diff --git a/lib/node_modules/@stdlib/random/streams/gamma/lib/factory.js b/lib/node_modules/@stdlib/random/streams/gamma/lib/factory.js index 97282072e5d1..ba029b06c1fd 100644 --- a/lib/node_modules/@stdlib/random/streams/gamma/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/gamma/lib/factory.js @@ -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' ); @@ -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 @@ -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 = {}; diff --git a/lib/node_modules/@stdlib/random/streams/geometric/lib/factory.js b/lib/node_modules/@stdlib/random/streams/geometric/lib/factory.js index 43b70c859070..6949718590ca 100644 --- a/lib/node_modules/@stdlib/random/streams/geometric/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/geometric/lib/factory.js @@ -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' ); @@ -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 @@ -68,6 +71,9 @@ 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 ) { @@ -75,6 +81,9 @@ function factory( p, options ) { 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; } diff --git a/lib/node_modules/@stdlib/random/streams/gumbel/lib/factory.js b/lib/node_modules/@stdlib/random/streams/gumbel/lib/factory.js index 5953255ca9d7..f0bdb731cb68 100644 --- a/lib/node_modules/@stdlib/random/streams/gumbel/lib/factory.js +++ b/lib/node_modules/@stdlib/random/streams/gumbel/lib/factory.js @@ -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' ); @@ -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 @@ -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 = {};