@@ -3,6 +3,7 @@ import templates from './templates'
33import utils from './utils'
44import $ from './zepto'
55import { MeiliSearch } from 'meilisearch'
6+ import { constructClientAgents } from './agents'
67
78/**
89 * Adds an autocomplete dropdown to an input field
@@ -56,6 +57,7 @@ class DocsSearchBar {
5657 enhancedSearchInput = false ,
5758 layout = 'columns' ,
5859 enableDarkMode = false ,
60+ clientAgents = [ ] ,
5961 } ) {
6062 DocsSearchBar . checkArguments ( {
6163 hostUrl,
@@ -72,6 +74,7 @@ class DocsSearchBar {
7274 enhancedSearchInput,
7375 layout,
7476 enableDarkMode,
77+ clientAgents,
7578 } )
7679
7780 this . apiKey = apiKey
@@ -115,6 +118,7 @@ class DocsSearchBar {
115118 this . client = new MeiliSearch ( {
116119 host : hostUrl ,
117120 apiKey : this . apiKey ,
121+ clientAgents : constructClientAgents ( clientAgents ) ,
118122 } )
119123
120124 DocsSearchBar . addThemeWrapper ( inputSelector , this . enableDarkMode )
@@ -255,6 +259,8 @@ class DocsSearchBar {
255259 false ,
256260 )
257261
262+ DocsSearchBar . typeCheck ( args , [ 'clientAgents' ] , 'array' , true )
263+
258264 DocsSearchBar . typeCheck (
259265 args ,
260266 [ 'queryDataCallback' , 'transformData' , 'queryHook' , 'handleSelected' ] ,
@@ -268,6 +274,20 @@ class DocsSearchBar {
268274 )
269275 }
270276 }
277+ /**
278+ * Throw a type error.
279+ *
280+ * @param {string } argument - Name of the parameter
281+ * @param {string } type - Type the parameter should have
282+ * @param {string } value - Value the parameter has
283+ *
284+ * @returns {void }
285+ */
286+ static throwTypeError ( argument , type , value ) {
287+ throw new Error (
288+ `Error: "${ argument } " must be of type: ${ type } . Found type: ${ typeof value } ` ,
289+ )
290+ }
271291
272292 /**
273293 * Checks if the arguments defined in the check variable are of the supplied
@@ -283,10 +303,12 @@ class DocsSearchBar {
283303 . filter ( ( argument ) => ! optional || args [ argument ] )
284304 . forEach ( ( argument ) => {
285305 const value = args [ argument ]
286- if ( typeof args [ argument ] !== type ) {
287- throw new Error (
288- `Error: "${ argument } " must be of type: ${ type } . Found type: ${ typeof value } ` ,
289- )
306+ if ( type === 'array' ) {
307+ if ( ! Array . isArray ( args [ argument ] ) ) {
308+ DocsSearchBar . throwTypeError ( argument , type , value )
309+ }
310+ } else if ( typeof args [ argument ] !== type ) {
311+ DocsSearchBar . throwTypeError ( argument , type , value )
290312 }
291313 } )
292314 }
0 commit comments