@@ -26,6 +26,7 @@ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
26
26
var isNonNegative = require ( '@stdlib/assert-is-nonnegative-number' ) . isPrimitive ;
27
27
var isString = require ( '@stdlib/assert-is-string' ) . isPrimitive ;
28
28
var isFunction = require ( '@stdlib/assert-is-function' ) ;
29
+ var format = require ( '@stdlib/string-format' ) ;
29
30
30
31
31
32
// MAIN //
@@ -56,42 +57,42 @@ var isFunction = require( '@stdlib/assert-is-function' );
56
57
*/
57
58
function validate ( opts , options ) {
58
59
if ( ! isObject ( options ) ) {
59
- return new TypeError ( 'invalid argument. Options must be an object. Value: `' + options + '`.' ) ;
60
+ return new TypeError ( format ( 'invalid argument. Options argument must be an object. Value: `%s`.' , options ) ) ;
60
61
}
61
62
if ( hasOwnProp ( options , 'sep' ) ) {
62
63
opts . sep = options . sep ;
63
64
if ( ! isString ( opts . sep ) ) {
64
- return new TypeError ( 'invalid option. `sep ` option must be a primitive string. Option: `' + opts . sep + '`.' ) ;
65
+ return new TypeError ( format ( 'invalid option. `%s ` option must be a string primitive . Option: `%s`.' , 'sep' , opts . sep ) ) ;
65
66
}
66
67
}
67
68
if ( hasOwnProp ( options , 'objectMode' ) ) {
68
69
opts . objectMode = options . objectMode ;
69
70
if ( ! isBoolean ( opts . objectMode ) ) {
70
- return new TypeError ( 'invalid option. `objectMode ` option must be a primitive boolean. Option: `' + opts . objectMode + '`.' ) ;
71
+ return new TypeError ( format ( 'invalid option. `%s ` option must be a primitive boolean. Option: `%s`.' , 'objectMode' , opts . objectMode ) ) ;
71
72
}
72
73
}
73
74
if ( hasOwnProp ( options , 'encoding' ) ) {
74
75
opts . encoding = options . encoding ;
75
76
if ( ! isString ( opts . encoding ) && opts . encoding !== null ) {
76
- return new TypeError ( 'invalid option. `encoding ` option must be a primitive string or null. Option: `' + opts . encoding + '`.' ) ;
77
+ return new TypeError ( format ( 'invalid option. `%s ` option must be a string primitive or null. Option: `%s`.' , 'encoding' , opts . encoding ) ) ;
77
78
}
78
79
}
79
80
if ( hasOwnProp ( options , 'highWaterMark' ) ) {
80
81
opts . highWaterMark = options . highWaterMark ;
81
82
if ( ! isNonNegative ( opts . highWaterMark ) ) {
82
- return new TypeError ( 'invalid option. `highWaterMark ` option must be a nonnegative number. Option: `' + opts . highWaterMark + '`.' ) ;
83
+ return new TypeError ( format ( 'invalid option. `%s ` option must be a nonnegative number. Option: `%s`.' , 'highWaterMark' , opts . highWaterMark ) ) ;
83
84
}
84
85
}
85
86
if ( hasOwnProp ( options , 'serialize' ) ) {
86
87
opts . serialize = options . serialize ;
87
88
if ( ! isFunction ( opts . serialize ) ) {
88
- return new TypeError ( 'invalid option. `serialize ` option must be a function. Option: `' + opts . serialize + '`.' ) ;
89
+ return new TypeError ( format ( 'invalid option. `%s ` option must be a function. Option: `%s`.' , 'serialize' , opts . serialize ) ) ;
89
90
}
90
91
}
91
92
if ( hasOwnProp ( options , 'dir' ) ) {
92
93
opts . dir = options . dir ;
93
94
if ( opts . dir !== 1 && opts . dir !== - 1 ) {
94
- return new TypeError ( 'invalid option. `dir ` option must be either `1` or `-1`. Option: `' + opts . dir + '`.' ) ;
95
+ return new TypeError ( format ( 'invalid option. `%s ` option must be either `1` or `-1`. Option: `%s`.' , 'dir' , opts . dir ) ) ;
95
96
}
96
97
}
97
98
return null ;
0 commit comments