Skip to content

Commit fb05454

Browse files
committed
Format error messages
1 parent 0ab3e2e commit fb05454

22 files changed

Lines changed: 116 additions & 99 deletions

File tree

lib/node_modules/@stdlib/_tools/github/delete-token/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -40,26 +41,26 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4041
*/
4142
function validate( opts, options ) {
4243
if ( !isObject( options ) ) {
43-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
44+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4445
}
4546
opts.username = options.username;
4647
if ( !isString( opts.username ) ) {
47-
return new TypeError( 'invalid option. `username` option must be a string primitive. Option: `' + opts.username + '`.' );
48+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
4849
}
4950
opts.password = options.password;
5051
if ( !isString( opts.password ) ) {
51-
return new TypeError( 'invalid option. `password` option must be a string primitive. Option: `' + opts.password + '`.' );
52+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'password', opts.password ) );
5253
}
5354
if ( hasOwnProp( options, 'otp' ) ) {
5455
opts.otp = options.otp;
5556
if ( !isString( opts.otp ) ) {
56-
return new TypeError( 'invalid option. `otp` option must be a string primitive. Option: `' + opts.otp + '`.' );
57+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'otp', opts.otp ) );
5758
}
5859
}
5960
if ( hasOwnProp( options, 'useragent' ) ) {
6061
opts.useragent = options.useragent;
6162
if ( !isString( opts.useragent ) ) {
62-
return new TypeError( 'invalid option. `useragent` option must be a string primitive. Option: `' + opts.useragent + '`.' );
63+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6364
}
6465
}
6566
return null;

lib/node_modules/@stdlib/_tools/github/followers/lib/validate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -39,24 +40,24 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
3940
*/
4041
function validate( opts, options ) {
4142
if ( !isObject( options ) ) {
42-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
43+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4344
}
4445
if ( hasOwnProp( options, 'token' ) ) {
4546
opts.token = options.token;
4647
if ( !isString( opts.token ) ) {
47-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
48+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4849
}
4950
}
5051
if ( hasOwnProp( options, 'username' ) ) {
5152
opts.username = options.username;
5253
if ( !isString( opts.username ) ) {
53-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
54+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5455
}
5556
}
5657
if ( hasOwnProp( options, 'useragent' ) ) {
5758
opts.useragent = options.useragent;
5859
if ( !isString( opts.useragent ) ) {
59-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
60+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6061
}
6162
}
6263
return null;

lib/node_modules/@stdlib/_tools/github/following/lib/validate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -39,24 +40,24 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
3940
*/
4041
function validate( opts, options ) {
4142
if ( !isObject( options ) ) {
42-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
43+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4344
}
4445
if ( hasOwnProp( options, 'token' ) ) {
4546
opts.token = options.token;
4647
if ( !isString( opts.token ) ) {
47-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
48+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4849
}
4950
}
5051
if ( hasOwnProp( options, 'username' ) ) {
5152
opts.username = options.username;
5253
if ( !isString( opts.username ) ) {
53-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
54+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5455
}
5556
}
5657
if ( hasOwnProp( options, 'useragent' ) ) {
5758
opts.useragent = options.useragent;
5859
if ( !isString( opts.useragent ) ) {
59-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
60+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6061
}
6162
}
6263
return null;

lib/node_modules/@stdlib/_tools/github/starred/lib/validate.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -41,36 +42,36 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4142
*/
4243
function validate( opts, options ) {
4344
if ( !isObject( options ) ) {
44-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
45+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4546
}
4647
if ( hasOwnProp( options, 'token' ) ) {
4748
opts.token = options.token;
4849
if ( !isString( opts.token ) ) {
49-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
50+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
5051
}
5152
}
5253
if ( hasOwnProp( options, 'username' ) ) {
5354
opts.username = options.username;
5455
if ( !isString( opts.username ) ) {
55-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
56+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5657
}
5758
}
5859
if ( hasOwnProp( options, 'useragent' ) ) {
5960
opts.useragent = options.useragent;
6061
if ( !isString( opts.useragent ) ) {
61-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
62+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6263
}
6364
}
6465
if ( hasOwnProp( options, 'sort' ) ) {
6566
opts.sort = options.sort;
6667
if ( !isString( opts.sort ) ) {
67-
return new TypeError( 'invalid option. Sort option must be a string primitive. Option: `' + opts.sort + '`.' );
68+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'sort', opts.sort ) );
6869
}
6970
}
7071
if ( hasOwnProp( options, 'direction' ) ) {
7172
opts.direction = options.direction;
7273
if ( !isString( opts.direction ) ) {
73-
return new TypeError( 'invalid option. Direction option must be a string primitive. Option: `' + opts.direction + '`.' );
74+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'direction', opts.direction) );
7475
}
7576
}
7677
return null;

lib/node_modules/@stdlib/_tools/github/subscriptions/lib/validate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -39,24 +40,24 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
3940
*/
4041
function validate( opts, options ) {
4142
if ( !isObject( options ) ) {
42-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
43+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4344
}
4445
if ( hasOwnProp( options, 'token' ) ) {
4546
opts.token = options.token;
4647
if ( !isString( opts.token ) ) {
47-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
48+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4849
}
4950
}
5051
if ( hasOwnProp( options, 'username' ) ) {
5152
opts.username = options.username;
5253
if ( !isString( opts.username ) ) {
53-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
54+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5455
}
5556
}
5657
if ( hasOwnProp( options, 'useragent' ) ) {
5758
opts.useragent = options.useragent;
5859
if ( !isString( opts.useragent ) ) {
59-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
60+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6061
}
6162
}
6263
return null;

lib/node_modules/@stdlib/_tools/github/user-details/lib/validate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isObject = require( '@stdlib/assert/is-object' );
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// MAIN //
@@ -40,7 +41,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4041
*/
4142
function validate( opts, options ) {
4243
if ( !isObject( options ) ) {
43-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
44+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4445
}
4546
opts.usernames = options.usernames;
4647
if ( !isStringArray( opts.usernames ) ) {
@@ -49,13 +50,13 @@ function validate( opts, options ) {
4950
if ( hasOwnProp( options, 'token' ) ) {
5051
opts.token = options.token;
5152
if ( !isString( opts.token ) ) {
52-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
53+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
5354
}
5455
}
5556
if ( hasOwnProp( options, 'useragent' ) ) {
5657
opts.useragent = options.useragent;
5758
if ( !isString( opts.useragent ) ) {
58-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
5960
}
6061
}
6162
return null;

lib/node_modules/@stdlib/_tools/github/user-rate-limit/lib/validate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -38,16 +39,16 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
3839
*/
3940
function validate( opts, options ) {
4041
if ( !isObject( options ) ) {
41-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
42+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4243
}
4344
opts.token = options.token;
4445
if ( !isString( opts.token ) ) {
45-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
46+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4647
}
4748
if ( hasOwnProp( options, 'useragent' ) ) {
4849
opts.useragent = options.useragent;
4950
if ( !isString( opts.useragent ) ) {
50-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
51+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
5152
}
5253
}
5354
return null;

lib/node_modules/@stdlib/_tools/github/user-repos/lib/validate.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -44,54 +45,54 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4445
*/
4546
function validate( opts, options ) {
4647
if ( !isObject( 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, 'token' ) ) {
5051
opts.token = options.token;
5152
if ( !isString( opts.token ) ) {
52-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
53+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
5354
}
5455
}
5556
if ( hasOwnProp( options, 'username' ) ) {
5657
opts.username = options.username;
5758
if ( !isString( opts.username ) ) {
58-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5960
}
6061
}
6162
if ( hasOwnProp( options, 'type' ) ) {
6263
opts.type = options.type;
6364
if ( !isString( opts.type ) ) {
64-
return new TypeError( 'invalid option. Type option must be a string primitive. Option: `' + opts.type + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'type', opts.type ) );
6566
}
6667
}
6768
if ( hasOwnProp( options, 'sort' ) ) {
6869
opts.sort = options.sort;
6970
if ( !isString( opts.sort ) ) {
70-
return new TypeError( 'invalid option. Sort option must be a string primitive. Option: `' + opts.sort + '`.' );
71+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'sort', opts.sort ) );
7172
}
7273
}
7374
if ( hasOwnProp( options, 'direction' ) ) {
7475
opts.direction = options.direction;
7576
if ( !isString( opts.direction ) ) {
76-
return new TypeError( 'invalid option. Direction option must be a string primitive. Option: `' + opts.direction + '`.' );
77+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'direction', opts.direction) );
7778
}
7879
}
7980
if ( hasOwnProp( options, 'visibility' ) ) {
8081
opts.visibility = options.visibility;
8182
if ( !isString( opts.visibility ) ) {
82-
return new TypeError( 'invalid option. Visibility option must be a string primitive. Option: `' + opts.visibility + '`.' );
83+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'visibility', opts.visibility ) );
8384
}
8485
}
8586
if ( hasOwnProp( options, 'affiliation' ) ) {
8687
opts.affiliation = options.affiliation;
8788
if ( !isString( opts.affiliation ) ) {
88-
return new TypeError( 'invalid option. Affiliation option must be a string primitive. Option: `' + opts.affiliation + '`.' );
89+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'affiliation', opts.affiliation ) );
8990
}
9091
}
9192
if ( hasOwnProp( options, 'useragent' ) ) {
9293
opts.useragent = options.useragent;
9394
if ( !isString( opts.useragent ) ) {
94-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
95+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
9596
}
9697
}
9798
return null;

lib/node_modules/@stdlib/_tools/pkgs/namespaces/lib/validate.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// VARIABLES //
@@ -57,28 +58,27 @@ var RE = /package\.json$/;
5758
*/
5859
function validate( opts, options ) {
5960
if ( !isObject( options ) ) {
60-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
61-
'`.' );
61+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6262
}
6363
if ( hasOwnProp( options, 'dir' ) ) {
6464
opts.dir = options.dir;
6565
if ( !isString( opts.dir ) ) {
66-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
66+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6767
}
6868
}
6969
if ( hasOwnProp( options, 'pattern' ) ) {
7070
opts.pattern = options.pattern;
7171
if ( !isString( opts.pattern ) ) {
72-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
72+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
7373
}
7474
if ( !RE.test( opts.pattern ) ) {
75-
return new Error( 'invalid option. `pattern` option must end with `package.json`. Option: `' + opts.pattern +'`.' );
75+
return new Error( format( 'invalid option. `%s` option must end with `package.json`. Option: `%s`.', 'pattern', opts.pattern ) );
7676
}
7777
}
7878
if ( hasOwnProp( options, 'ignore' ) ) {
7979
opts.ignore = options.ignore;
8080
if ( !isStringArray( opts.ignore ) ) {
81-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
81+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
8282
}
8383
}
8484
return null;

0 commit comments

Comments
 (0)