@@ -74,17 +74,36 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
74
74
name : "searchCategoryBoosts" ,
75
75
help : "Configure search to give a relevance boost to selected categories" ,
76
76
type : ParameterType . Mixed ,
77
+ validate ( value ) {
78
+ if ( ! isObject ( value ) ) {
79
+ throw new Error (
80
+ "The 'searchCategoryBoosts' option must be a non-array object."
81
+ ) ;
82
+ }
83
+
84
+ if ( Object . values ( value ) . some ( ( x ) => typeof x !== "number" ) ) {
85
+ throw new Error (
86
+ "All values of 'searchCategoryBoosts' must be numbers."
87
+ ) ;
88
+ }
89
+ } ,
77
90
} ) ;
78
91
options . addDeclaration ( {
79
92
name : "searchGroupBoosts" ,
80
93
help : 'Configure search to give a relevance boost to selected kinds (eg "class")' ,
81
94
type : ParameterType . Mixed ,
82
95
validate ( value : unknown ) {
96
+ if ( ! isObject ( value ) ) {
97
+ throw new Error (
98
+ "The 'searchGroupBoosts' option must be a non-array object."
99
+ ) ;
100
+ }
101
+
83
102
const validValues = Object . values ( ReflectionKind )
84
103
. filter ( ( v ) => typeof v === "string" )
85
104
. map ( ( v ) => v . toString ( ) ) ;
86
105
87
- for ( const kindName in value as { [ key : string ] : number } ) {
106
+ for ( const kindName in value ) {
88
107
if ( validValues . indexOf ( kindName ) < 0 ) {
89
108
throw new Error (
90
109
`'${ kindName } ' is an invalid value for 'searchGroupBoosts'. Must be one of: ${ validValues . join (
@@ -93,6 +112,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
93
112
) ;
94
113
}
95
114
}
115
+
116
+ if ( Object . values ( value ) . some ( ( x ) => typeof x !== "number" ) ) {
117
+ throw new Error (
118
+ "All values of 'searchGroupBoosts' must be numbers."
119
+ ) ;
120
+ }
96
121
} ,
97
122
} ) ;
98
123
options . addDeclaration ( {
@@ -341,11 +366,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
341
366
help : "Specify the options passed to Marked, the Markdown parser used by TypeDoc." ,
342
367
type : ParameterType . Mixed ,
343
368
validate ( value ) {
344
- if (
345
- typeof value !== "object" ||
346
- Array . isArray ( value ) ||
347
- value == null
348
- ) {
369
+ if ( ! isObject ( value ) ) {
349
370
throw new Error (
350
371
"The 'markedOptions' option must be a non-array object."
351
372
) ;
@@ -357,11 +378,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
357
378
help : "Selectively override the TypeScript compiler options used by TypeDoc." ,
358
379
type : ParameterType . Mixed ,
359
380
validate ( value ) {
360
- if (
361
- typeof value !== "object" ||
362
- Array . isArray ( value ) ||
363
- value == null
364
- ) {
381
+ if ( ! isObject ( value ) ) {
365
382
throw new Error (
366
383
"The 'compilerOptions' option must be a non-array object."
367
384
) ;
@@ -429,3 +446,7 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
429
446
} ,
430
447
} ) ;
431
448
}
449
+
450
+ function isObject ( x : unknown ) : x is Record < string , unknown > {
451
+ return ! ! x && typeof x === "object" && ! Array . isArray ( x ) ;
452
+ }
0 commit comments