Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Mar 16, 2022
1 parent 5b9dcb6 commit d621a25
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions timeit/lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimit
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var isNull = require( '@stdlib/assert/is-null' );
var format = require( '@stdlib/string/format' );


// MAIN //
Expand Down Expand Up @@ -56,39 +57,39 @@ var isNull = require( '@stdlib/assert/is-null' );
*/
function validate( opts, options ) {
if ( !isObject( options ) ) {
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
if ( hasOwnProp( options, 'iterations' ) ) {
opts.iterations = options.iterations;
if (
!isPositiveInteger( opts.iterations ) &&
!isNull( opts.iterations )
) {
return new TypeError( 'invalid option. `iterations` option must be a positive integer or null. Option: `' + opts.iterations + '`.' );
return new TypeError( format( 'invalid option. `%s` option must be a positive integer or null. Option: `%s`.', 'iterations', opts.iterations ) );
}
}
if ( hasOwnProp( options, 'repeats' ) ) {
opts.repeats = options.repeats;
if ( !isPositiveInteger( opts.repeats ) ) {
return new TypeError( 'invalid option. `repeats` option must be a positive integer. Option: `' + opts.repeats + '`.' );
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'repeats', opts.repeats ) );
}
}
if ( hasOwnProp( options, 'before' ) ) {
opts.before = options.before;
if ( !isString( opts.before ) ) {
return new TypeError( 'invalid option. `before` option must be a primitive string. Option: `' + opts.before + '`.' );
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'before', opts.before ) );
}
}
if ( hasOwnProp( options, 'after' ) ) {
opts.after = options.after;
if ( !isString( opts.after ) ) {
return new TypeError( 'invalid option. `after` option must be a primitive string. Option: `' + opts.after + '`.' );
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'after', opts.after ) );
}
}
if ( hasOwnProp( options, 'asynchronous' ) ) {
opts.asynchronous = options.asynchronous;
if ( !isBoolean( opts.asynchronous ) ) {
return new TypeError( 'invalid option. `asynchronous` option must be a primitive boolean. Option: `' + opts.asynchronous + '`.' );
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'asynchronous', opts.asynchronous ) );
}
}
return null;
Expand Down

0 comments on commit d621a25

Please sign in to comment.