Skip to content

Commit be5792f

Browse files
committed
Use string formatting
1 parent 9d6d27b commit be5792f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tools/snippets/lib/validate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var format = require( '@stdlib/string/format' );
2526

2627

2728
// MAIN //
@@ -44,12 +45,12 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
4445
*/
4546
function validate( opts, options ) {
4647
if ( !isPlainObject( options ) ) {
47-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
48+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4849
}
4950
if ( hasOwnProp( options, 'TODO' ) ) {
5051
opts.TODO = options.TODO;
5152
if ( !isPlainObject( opts.TODO ) ) {
52-
return new TypeError( 'invalid option. `TODO` option must be a TODO. Option: `' + opts.TODO + '`.' );
53+
return new TypeError( format( 'invalid option. `%s` option must be a TODO. Option: `%s`.', 'TODO', opts.TODO ) );
5354
}
5455
}
5556
return null;

tools/snippets/test/test.validate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var format = require( '@stdlib/string/format' );
2425
var validate = require( './../lib/validate.js' );
2526

2627

@@ -51,7 +52,7 @@ tape( 'the function returns an error if provided an `options` argument which is
5152

5253
for ( i = 0; i < values.length; i++ ) {
5354
err = validate( {}, values[ i ] );
54-
t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] );
55+
t.strictEqual( err instanceof TypeError, true, format( 'returns an error when provided %s', values[i] ) );
5556
}
5657
t.end();
5758
});
@@ -67,7 +68,7 @@ tape( 'the function returns `null` if all options are valid', function test( t )
6768
options = {}; // TODO: add options
6869

6970
err = validate( opts, options );
70-
t.strictEqual( err, null, 'returns null' );
71+
t.strictEqual( err, null, 'returns expected value' );
7172
t.deepEqual( opts, options, 'sets options' );
7273

7374
t.end();
@@ -85,7 +86,7 @@ tape( 'the function will ignore unrecognized options', function test( t ) {
8586
};
8687

8788
err = validate( opts, options );
88-
t.strictEqual( err, null, 'returns null' );
89+
t.strictEqual( err, null, 'returns expected value' );
8990
t.deepEqual( opts, {}, 'ignores unrecognized options' );
9091

9192
t.end();

0 commit comments

Comments
 (0)