instantsearch.js 4.56.5 → 4.56.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.56.5 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.56.7 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -5590,12 +5590,14 @@
5590
5590
  return target;
5591
5591
  }
5592
5592
 
5593
+ // eslint-disable-next-line no-restricted-syntax
5593
5594
  for (var key in source) {
5594
5595
  if (
5595
5596
  !Object.prototype.hasOwnProperty.call(source, key) ||
5596
5597
  key === '__proto__' ||
5597
5598
  key === 'constructor'
5598
5599
  ) {
5600
+ // eslint-disable-next-line no-continue
5599
5601
  continue;
5600
5602
  }
5601
5603
 
@@ -5603,6 +5605,7 @@
5603
5605
  var targetVal = target[key];
5604
5606
 
5605
5607
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
5608
+ // eslint-disable-next-line no-continue
5606
5609
  continue;
5607
5610
  }
5608
5611
 
@@ -5629,11 +5632,10 @@
5629
5632
  * - treats sparse arrays as sparse
5630
5633
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
5631
5634
  *
5632
- * @param {Object} object The destination object.
5635
+ * @param {Object} target The destination object.
5633
5636
  * @param {...Object} [sources] The source objects.
5634
5637
  * @returns {Object} Returns `object`.
5635
5638
  */
5636
-
5637
5639
  function merge(target) {
5638
5640
  if (!isObjectOrArrayOrFunction(target)) {
5639
5641
  target = {};
@@ -5656,8 +5658,8 @@
5656
5658
  var defaultsPure = function defaultsPure() {
5657
5659
  var sources = Array.prototype.slice.call(arguments);
5658
5660
 
5659
- return sources.reduceRight(function(acc, source) {
5660
- Object.keys(Object(source)).forEach(function(key) {
5661
+ return sources.reduceRight(function (acc, source) {
5662
+ Object.keys(Object(source)).forEach(function (key) {
5661
5663
  if (source[key] === undefined) {
5662
5664
  return;
5663
5665
  }
@@ -5672,7 +5674,7 @@
5672
5674
  };
5673
5675
 
5674
5676
  function intersection(arr1, arr2) {
5675
- return arr1.filter(function(value, index) {
5677
+ return arr1.filter(function (value, index) {
5676
5678
  return (
5677
5679
  arr2.indexOf(value) > -1 &&
5678
5680
  arr1.indexOf(value) === index /* skips duplicates */
@@ -5693,6 +5695,8 @@
5693
5695
  return array[i];
5694
5696
  }
5695
5697
  }
5698
+
5699
+ return undefined;
5696
5700
  };
5697
5701
 
5698
5702
  function valToNumber(v) {
@@ -5704,7 +5708,9 @@
5704
5708
  return v.map(valToNumber);
5705
5709
  }
5706
5710
 
5707
- throw new Error('The value should be a number, a parsable string or an array of those.');
5711
+ throw new Error(
5712
+ 'The value should be a number, a parsable string or an array of those.'
5713
+ );
5708
5714
  }
5709
5715
 
5710
5716
  var valToNumber_1 = valToNumber;
@@ -5718,6 +5724,7 @@
5718
5724
  var i;
5719
5725
  for (i = 0; i < sourceKeys.length; i++) {
5720
5726
  key = sourceKeys[i];
5727
+ // eslint-disable-next-line no-continue
5721
5728
  if (excluded.indexOf(key) >= 0) continue;
5722
5729
  target[key] = source[key];
5723
5730
  }
@@ -5770,9 +5777,9 @@
5770
5777
 
5771
5778
  var valueAsString = '' + value;
5772
5779
 
5773
- var facetRefinement = !refinementList[attribute] ?
5774
- [valueAsString] :
5775
- refinementList[attribute].concat(valueAsString);
5780
+ var facetRefinement = !refinementList[attribute]
5781
+ ? [valueAsString]
5782
+ : refinementList[attribute].concat(valueAsString);
5776
5783
 
5777
5784
  var mod = {};
5778
5785
 
@@ -5789,18 +5796,22 @@
5789
5796
  * @param {string} [value] the value of the refinement
5790
5797
  * @return {RefinementList} a new and updated refinement lst
5791
5798
  */
5792
- removeRefinement: function removeRefinement(refinementList, attribute, value) {
5799
+ removeRefinement: function removeRefinement(
5800
+ refinementList,
5801
+ attribute,
5802
+ value
5803
+ ) {
5793
5804
  if (value === undefined) {
5794
5805
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
5795
5806
  // the form with a string will remove the attribute completely
5796
- return lib.clearRefinement(refinementList, function(v, f) {
5807
+ return lib.clearRefinement(refinementList, function (v, f) {
5797
5808
  return attribute === f;
5798
5809
  });
5799
5810
  }
5800
5811
 
5801
5812
  var valueAsString = '' + value;
5802
5813
 
5803
- return lib.clearRefinement(refinementList, function(v, f) {
5814
+ return lib.clearRefinement(refinementList, function (v, f) {
5804
5815
  return attribute === f && valueAsString === v;
5805
5816
  });
5806
5817
  },
@@ -5811,8 +5822,13 @@
5811
5822
  * @param {string} value the value of the refinement
5812
5823
  * @return {RefinementList} a new and updated list
5813
5824
  */
5814
- toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
5815
- if (value === undefined) throw new Error('toggleRefinement should be used with a value');
5825
+ toggleRefinement: function toggleRefinement(
5826
+ refinementList,
5827
+ attribute,
5828
+ value
5829
+ ) {
5830
+ if (value === undefined)
5831
+ throw new Error('toggleRefinement should be used with a value');
5816
5832
 
5817
5833
  if (lib.isRefined(refinementList, attribute, value)) {
5818
5834
  return lib.removeRefinement(refinementList, attribute, value);
@@ -5831,8 +5847,14 @@
5831
5847
  * @param {string} [refinementType] optional parameter to give more context to the attribute function
5832
5848
  * @return {RefinementList} a new and updated refinement list
5833
5849
  */
5834
- clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
5850
+ clearRefinement: function clearRefinement(
5851
+ refinementList,
5852
+ attribute,
5853
+ refinementType
5854
+ ) {
5835
5855
  if (attribute === undefined) {
5856
+ // return the same object if the list is already empty
5857
+ // this is mainly for tests, as it doesn't have much impact on performance
5836
5858
  if (!objectHasKeys_1(refinementList)) {
5837
5859
  return refinementList;
5838
5860
  }
@@ -5842,23 +5864,32 @@
5842
5864
  } else if (typeof attribute === 'function') {
5843
5865
  var hasChanged = false;
5844
5866
 
5845
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
5867
+ var newRefinementList = Object.keys(refinementList).reduce(function (
5868
+ memo,
5869
+ key
5870
+ ) {
5846
5871
  var values = refinementList[key] || [];
5847
- var facetList = values.filter(function(value) {
5872
+ var facetList = values.filter(function (value) {
5848
5873
  return !attribute(value, key, refinementType);
5849
5874
  });
5850
5875
 
5851
5876
  if (facetList.length !== values.length) {
5852
5877
  hasChanged = true;
5853
5878
  }
5879
+
5854
5880
  memo[key] = facetList;
5855
5881
 
5856
5882
  return memo;
5857
- }, {});
5883
+ },
5884
+ {});
5858
5885
 
5859
5886
  if (hasChanged) return newRefinementList;
5860
5887
  return refinementList;
5861
5888
  }
5889
+
5890
+ // We return nothing if the attribute is not undefined, a string or a function,
5891
+ // as it is not a valid value for a refinement
5892
+ return undefined;
5862
5893
  },
5863
5894
  /**
5864
5895
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -5867,10 +5898,11 @@
5867
5898
  * @param {RefinementList} refinementList the list of refinement
5868
5899
  * @param {string} attribute name of the attribute
5869
5900
  * @param {string} [refinementValue] value of the filter/refinement
5870
- * @return {boolean}
5901
+ * @return {boolean} true if the attribute is refined, false otherwise
5871
5902
  */
5872
5903
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
5873
- var containsRefinements = !!refinementList[attribute] &&
5904
+ var containsRefinements =
5905
+ Boolean(refinementList[attribute]) &&
5874
5906
  refinementList[attribute].length > 0;
5875
5907
 
5876
5908
  if (refinementValue === undefined || !containsRefinements) {
@@ -5880,7 +5912,7 @@
5880
5912
  var refinementValueAsString = '' + refinementValue;
5881
5913
 
5882
5914
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
5883
- }
5915
+ },
5884
5916
  };
5885
5917
 
5886
5918
  var RefinementList = lib;
@@ -5891,12 +5923,15 @@
5891
5923
  * - [5]
5892
5924
  * - [[5]]
5893
5925
  * - [[5,5],[4]]
5926
+ * @param {any} a numeric refinement value
5927
+ * @param {any} b numeric refinement value
5928
+ * @return {boolean} true if the values are equal
5894
5929
  */
5895
5930
  function isEqualNumericRefinement(a, b) {
5896
5931
  if (Array.isArray(a) && Array.isArray(b)) {
5897
5932
  return (
5898
5933
  a.length === b.length &&
5899
- a.every(function(el, i) {
5934
+ a.every(function (el, i) {
5900
5935
  return isEqualNumericRefinement(b[i], el);
5901
5936
  })
5902
5937
  );
@@ -5913,7 +5948,7 @@
5913
5948
  * @return {any} the searched value or undefined
5914
5949
  */
5915
5950
  function findArray(array, searchedValue) {
5916
- return find$1(array, function(currentValue) {
5951
+ return find$1(array, function (currentValue) {
5917
5952
  return isEqualNumericRefinement(currentValue, searchedValue);
5918
5953
  });
5919
5954
  }
@@ -5966,10 +6001,15 @@
5966
6001
  }
5967
6002
  */
5968
6003
  function SearchParameters(newParameters) {
5969
- var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
6004
+ var params = newParameters
6005
+ ? SearchParameters._parseNumbers(newParameters)
6006
+ : {};
5970
6007
 
5971
6008
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
5972
- console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
6009
+ // eslint-disable-next-line no-console
6010
+ console.warn(
6011
+ '[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}'
6012
+ );
5973
6013
  }
5974
6014
  /**
5975
6015
  * This attribute contains the list of all the conjunctive facets
@@ -6069,10 +6109,12 @@
6069
6109
  * be translated into the `facetFilters` attribute.
6070
6110
  * @member {Object.<string, SearchParameters.FacetList>}
6071
6111
  */
6072
- this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
6112
+ this.hierarchicalFacetsRefinements =
6113
+ params.hierarchicalFacetsRefinements || {};
6073
6114
 
6115
+ // eslint-disable-next-line consistent-this
6074
6116
  var self = this;
6075
- Object.keys(params).forEach(function(paramName) {
6117
+ Object.keys(params).forEach(function (paramName) {
6076
6118
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
6077
6119
  var isValueDefined = params[paramName] !== undefined;
6078
6120
 
@@ -6094,8 +6136,8 @@
6094
6136
  * @param {object} partialState full or part of a state
6095
6137
  * @return {object} a new object with the number keys as number
6096
6138
  */
6097
- SearchParameters._parseNumbers = function(partialState) {
6098
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
6139
+ SearchParameters._parseNumbers = function (partialState) {
6140
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
6099
6141
  if (partialState instanceof SearchParameters) return partialState;
6100
6142
 
6101
6143
  var numbers = {};
@@ -6111,10 +6153,10 @@
6111
6153
  'distinct',
6112
6154
  'minimumAroundRadius',
6113
6155
  'hitsPerPage',
6114
- 'minProximity'
6156
+ 'minProximity',
6115
6157
  ];
6116
6158
 
6117
- numberKeys.forEach(function(k) {
6159
+ numberKeys.forEach(function (k) {
6118
6160
  var value = partialState[k];
6119
6161
  if (typeof value === 'string') {
6120
6162
  var parsedValue = parseFloat(value);
@@ -6126,9 +6168,11 @@
6126
6168
  // there's two formats of insideBoundingBox, we need to parse
6127
6169
  // the one which is an array of float geo rectangles
6128
6170
  if (Array.isArray(partialState.insideBoundingBox)) {
6129
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
6171
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
6172
+ geoRect
6173
+ ) {
6130
6174
  if (Array.isArray(geoRect)) {
6131
- return geoRect.map(function(value) {
6175
+ return geoRect.map(function (value) {
6132
6176
  return parseFloat(value);
6133
6177
  });
6134
6178
  }
@@ -6138,14 +6182,14 @@
6138
6182
 
6139
6183
  if (partialState.numericRefinements) {
6140
6184
  var numericRefinements = {};
6141
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
6185
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
6142
6186
  var operators = partialState.numericRefinements[attribute] || {};
6143
6187
  numericRefinements[attribute] = {};
6144
- Object.keys(operators).forEach(function(operator) {
6188
+ Object.keys(operators).forEach(function (operator) {
6145
6189
  var values = operators[operator];
6146
- var parsedValues = values.map(function(v) {
6190
+ var parsedValues = values.map(function (v) {
6147
6191
  if (Array.isArray(v)) {
6148
- return v.map(function(vPrime) {
6192
+ return v.map(function (vPrime) {
6149
6193
  if (typeof vPrime === 'string') {
6150
6194
  return parseFloat(vPrime);
6151
6195
  }
@@ -6175,18 +6219,24 @@
6175
6219
  var instance = new SearchParameters(newParameters);
6176
6220
 
6177
6221
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
6178
- hierarchicalFacets.forEach(function(facet) {
6222
+ hierarchicalFacets.forEach(function (facet) {
6179
6223
  if (facet.rootPath) {
6180
6224
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
6181
6225
 
6182
- if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
6226
+ if (
6227
+ currentRefinement.length > 0 &&
6228
+ currentRefinement[0].indexOf(facet.rootPath) !== 0
6229
+ ) {
6183
6230
  instance = instance.clearRefinements(facet.name);
6184
6231
  }
6185
6232
 
6186
6233
  // get it again in case it has been cleared
6187
6234
  currentRefinement = instance.getHierarchicalRefinement(facet.name);
6188
6235
  if (currentRefinement.length === 0) {
6189
- instance = instance.toggleHierarchicalFacetRefinement(facet.name, facet.rootPath);
6236
+ instance = instance.toggleHierarchicalFacetRefinement(
6237
+ facet.name,
6238
+ facet.rootPath
6239
+ );
6190
6240
  }
6191
6241
  }
6192
6242
  });
@@ -6200,19 +6250,25 @@
6200
6250
  * @param {object|SearchParameters} parameters the new parameters to set
6201
6251
  * @return {Error|null} Error if the modification is invalid, null otherwise
6202
6252
  */
6203
- SearchParameters.validate = function(currentState, parameters) {
6253
+ SearchParameters.validate = function (currentState, parameters) {
6204
6254
  var params = parameters || {};
6205
6255
 
6206
- if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
6256
+ if (
6257
+ currentState.tagFilters &&
6258
+ params.tagRefinements &&
6259
+ params.tagRefinements.length > 0
6260
+ ) {
6207
6261
  return new Error(
6208
6262
  '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
6209
- 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
6263
+ 'an error, if it is really what you want, you should first clear the tags with clearTags method.'
6264
+ );
6210
6265
  }
6211
6266
 
6212
6267
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
6213
6268
  return new Error(
6214
6269
  '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
6215
- 'an error, if it is not, you should first clear the tags with clearTags method.');
6270
+ 'an error, if it is not, you should first clear the tags with clearTags method.'
6271
+ );
6216
6272
  }
6217
6273
 
6218
6274
  if (
@@ -6230,8 +6286,9 @@
6230
6286
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
6231
6287
  return new Error(
6232
6288
  "[Numeric filters] Can't switch from the managed API to the advanced. It" +
6233
- ' is probably an error, if this is really what you want, you have to first' +
6234
- ' clear the numeric filters.');
6289
+ ' is probably an error, if this is really what you want, you have to first' +
6290
+ ' clear the numeric filters.'
6291
+ );
6235
6292
  }
6236
6293
 
6237
6294
  return null;
@@ -6247,7 +6304,7 @@
6247
6304
  * - If not given, means to clear all the filters.
6248
6305
  * - If `string`, means to clear all refinements for the `attribute` named filter.
6249
6306
  * - If `function`, means to clear all the refinements that return truthy values.
6250
- * @return {SearchParameters}
6307
+ * @return {SearchParameters} new instance with filters cleared
6251
6308
  */
6252
6309
  clearRefinements: function clearRefinements(attribute) {
6253
6310
  var patch = {
@@ -6271,13 +6328,14 @@
6271
6328
  this.hierarchicalFacetsRefinements,
6272
6329
  attribute,
6273
6330
  'hierarchicalFacet'
6274
- )
6331
+ ),
6275
6332
  };
6276
6333
  if (
6277
6334
  patch.numericRefinements === this.numericRefinements &&
6278
6335
  patch.facetsRefinements === this.facetsRefinements &&
6279
6336
  patch.facetsExcludes === this.facetsExcludes &&
6280
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
6337
+ patch.disjunctiveFacetsRefinements ===
6338
+ this.disjunctiveFacetsRefinements &&
6281
6339
  patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
6282
6340
  ) {
6283
6341
  return this;
@@ -6287,53 +6345,54 @@
6287
6345
  /**
6288
6346
  * Remove all the refined tags from the SearchParameters
6289
6347
  * @method
6290
- * @return {SearchParameters}
6348
+ * @return {SearchParameters} new instance with tags cleared
6291
6349
  */
6292
6350
  clearTags: function clearTags() {
6293
- if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
6351
+ if (this.tagFilters === undefined && this.tagRefinements.length === 0)
6352
+ return this;
6294
6353
 
6295
6354
  return this.setQueryParameters({
6296
6355
  tagFilters: undefined,
6297
- tagRefinements: []
6356
+ tagRefinements: [],
6298
6357
  });
6299
6358
  },
6300
6359
  /**
6301
6360
  * Set the index.
6302
6361
  * @method
6303
6362
  * @param {string} index the index name
6304
- * @return {SearchParameters}
6363
+ * @return {SearchParameters} new instance
6305
6364
  */
6306
6365
  setIndex: function setIndex(index) {
6307
6366
  if (index === this.index) return this;
6308
6367
 
6309
6368
  return this.setQueryParameters({
6310
- index: index
6369
+ index: index,
6311
6370
  });
6312
6371
  },
6313
6372
  /**
6314
6373
  * Query setter
6315
6374
  * @method
6316
6375
  * @param {string} newQuery value for the new query
6317
- * @return {SearchParameters}
6376
+ * @return {SearchParameters} new instance
6318
6377
  */
6319
6378
  setQuery: function setQuery(newQuery) {
6320
6379
  if (newQuery === this.query) return this;
6321
6380
 
6322
6381
  return this.setQueryParameters({
6323
- query: newQuery
6382
+ query: newQuery,
6324
6383
  });
6325
6384
  },
6326
6385
  /**
6327
6386
  * Page setter
6328
6387
  * @method
6329
6388
  * @param {number} newPage new page number
6330
- * @return {SearchParameters}
6389
+ * @return {SearchParameters} new instance
6331
6390
  */
6332
6391
  setPage: function setPage(newPage) {
6333
6392
  if (newPage === this.page) return this;
6334
6393
 
6335
6394
  return this.setQueryParameters({
6336
- page: newPage
6395
+ page: newPage,
6337
6396
  });
6338
6397
  },
6339
6398
  /**
@@ -6341,11 +6400,11 @@
6341
6400
  * The facets are the simple facets, used for conjunctive (and) faceting.
6342
6401
  * @method
6343
6402
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
6344
- * @return {SearchParameters}
6403
+ * @return {SearchParameters} new instance
6345
6404
  */
6346
6405
  setFacets: function setFacets(facets) {
6347
6406
  return this.setQueryParameters({
6348
- facets: facets
6407
+ facets: facets,
6349
6408
  });
6350
6409
  },
6351
6410
  /**
@@ -6353,11 +6412,11 @@
6353
6412
  * Change the list of disjunctive (or) facets the helper chan handle.
6354
6413
  * @method
6355
6414
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
6356
- * @return {SearchParameters}
6415
+ * @return {SearchParameters} new instance
6357
6416
  */
6358
6417
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
6359
6418
  return this.setQueryParameters({
6360
- disjunctiveFacets: facets
6419
+ disjunctiveFacets: facets,
6361
6420
  });
6362
6421
  },
6363
6422
  /**
@@ -6365,13 +6424,13 @@
6365
6424
  * Hits per page represents the number of hits retrieved for this query
6366
6425
  * @method
6367
6426
  * @param {number} n number of hits retrieved per page of results
6368
- * @return {SearchParameters}
6427
+ * @return {SearchParameters} new instance
6369
6428
  */
6370
6429
  setHitsPerPage: function setHitsPerPage(n) {
6371
6430
  if (this.hitsPerPage === n) return this;
6372
6431
 
6373
6432
  return this.setQueryParameters({
6374
- hitsPerPage: n
6433
+ hitsPerPage: n,
6375
6434
  });
6376
6435
  },
6377
6436
  /**
@@ -6379,13 +6438,13 @@
6379
6438
  * Set the value of typoTolerance
6380
6439
  * @method
6381
6440
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
6382
- * @return {SearchParameters}
6441
+ * @return {SearchParameters} new instance
6383
6442
  */
6384
6443
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
6385
6444
  if (this.typoTolerance === typoTolerance) return this;
6386
6445
 
6387
6446
  return this.setQueryParameters({
6388
- typoTolerance: typoTolerance
6447
+ typoTolerance: typoTolerance,
6389
6448
  });
6390
6449
  },
6391
6450
  /**
@@ -6396,19 +6455,19 @@
6396
6455
  * @param {string} attribute attribute to set the filter on
6397
6456
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
6398
6457
  * @param {number | number[]} value value of the filter
6399
- * @return {SearchParameters}
6458
+ * @return {SearchParameters} new instance
6400
6459
  * @example
6401
6460
  * // for price = 50 or 40
6402
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
6461
+ * state.addNumericRefinement('price', '=', [50, 40]);
6403
6462
  * @example
6404
6463
  * // for size = 38 and 40
6405
- * searchparameter.addNumericRefinement('size', '=', 38);
6406
- * searchparameter.addNumericRefinement('size', '=', 40);
6464
+ * state.addNumericRefinement('size', '=', 38);
6465
+ * state.addNumericRefinement('size', '=', 40);
6407
6466
  */
6408
- addNumericRefinement: function(attribute, operator, v) {
6409
- var value = valToNumber_1(v);
6467
+ addNumericRefinement: function (attribute, operator, value) {
6468
+ var val = valToNumber_1(value);
6410
6469
 
6411
- if (this.isNumericRefined(attribute, operator, value)) return this;
6470
+ if (this.isNumericRefined(attribute, operator, val)) return this;
6412
6471
 
6413
6472
  var mod = merge_1({}, this.numericRefinements);
6414
6473
 
@@ -6418,13 +6477,13 @@
6418
6477
  // Array copy
6419
6478
  mod[attribute][operator] = mod[attribute][operator].slice();
6420
6479
  // Add the element. Concat can't be used here because value can be an array.
6421
- mod[attribute][operator].push(value);
6480
+ mod[attribute][operator].push(val);
6422
6481
  } else {
6423
- mod[attribute][operator] = [value];
6482
+ mod[attribute][operator] = [val];
6424
6483
  }
6425
6484
 
6426
6485
  return this.setQueryParameters({
6427
- numericRefinements: mod
6486
+ numericRefinements: mod,
6428
6487
  });
6429
6488
  },
6430
6489
  /**
@@ -6432,7 +6491,7 @@
6432
6491
  * @param {string} facetName name of the attribute used for faceting
6433
6492
  * @return {string[]} list of refinements
6434
6493
  */
6435
- getConjunctiveRefinements: function(facetName) {
6494
+ getConjunctiveRefinements: function (facetName) {
6436
6495
  if (!this.isConjunctiveFacet(facetName)) {
6437
6496
  return [];
6438
6497
  }
@@ -6443,7 +6502,7 @@
6443
6502
  * @param {string} facetName name of the attribute used for faceting
6444
6503
  * @return {string[]} list of refinements
6445
6504
  */
6446
- getDisjunctiveRefinements: function(facetName) {
6505
+ getDisjunctiveRefinements: function (facetName) {
6447
6506
  if (!this.isDisjunctiveFacet(facetName)) {
6448
6507
  return [];
6449
6508
  }
@@ -6454,7 +6513,7 @@
6454
6513
  * @param {string} facetName name of the attribute used for faceting
6455
6514
  * @return {string[]} list of refinements
6456
6515
  */
6457
- getHierarchicalRefinement: function(facetName) {
6516
+ getHierarchicalRefinement: function (facetName) {
6458
6517
  // we send an array but we currently do not support multiple
6459
6518
  // hierarchicalRefinements for a hierarchicalFacet
6460
6519
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -6464,7 +6523,7 @@
6464
6523
  * @param {string} facetName name of the attribute used for faceting
6465
6524
  * @return {string[]} list of refinements
6466
6525
  */
6467
- getExcludeRefinements: function(facetName) {
6526
+ getExcludeRefinements: function (facetName) {
6468
6527
  if (!this.isConjunctiveFacet(facetName)) {
6469
6528
  return [];
6470
6529
  }
@@ -6477,36 +6536,43 @@
6477
6536
  * @param {string} attribute attribute to set the filter on
6478
6537
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
6479
6538
  * @param {number} [number] the value to be removed
6480
- * @return {SearchParameters}
6539
+ * @return {SearchParameters} new instance
6481
6540
  */
6482
- removeNumericRefinement: function(attribute, operator, paramValue) {
6541
+ removeNumericRefinement: function (attribute, operator, number) {
6542
+ var paramValue = number;
6483
6543
  if (paramValue !== undefined) {
6484
6544
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
6485
6545
  return this;
6486
6546
  }
6487
6547
  return this.setQueryParameters({
6488
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6548
+ numericRefinements: this._clearNumericRefinements(function (
6549
+ value,
6550
+ key
6551
+ ) {
6489
6552
  return (
6490
6553
  key === attribute &&
6491
6554
  value.op === operator &&
6492
6555
  isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
6493
6556
  );
6494
- })
6557
+ }),
6495
6558
  });
6496
6559
  } else if (operator !== undefined) {
6497
6560
  if (!this.isNumericRefined(attribute, operator)) return this;
6498
6561
  return this.setQueryParameters({
6499
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6562
+ numericRefinements: this._clearNumericRefinements(function (
6563
+ value,
6564
+ key
6565
+ ) {
6500
6566
  return key === attribute && value.op === operator;
6501
- })
6567
+ }),
6502
6568
  });
6503
6569
  }
6504
6570
 
6505
6571
  if (!this.isNumericRefined(attribute)) return this;
6506
6572
  return this.setQueryParameters({
6507
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6573
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
6508
6574
  return key === attribute;
6509
- })
6575
+ }),
6510
6576
  });
6511
6577
  },
6512
6578
  /**
@@ -6514,7 +6580,7 @@
6514
6580
  * @param {string} facetName name of the attribute used for faceting
6515
6581
  * @return {SearchParameters.OperatorList} list of refinements
6516
6582
  */
6517
- getNumericRefinements: function(facetName) {
6583
+ getNumericRefinements: function (facetName) {
6518
6584
  return this.numericRefinements[facetName] || {};
6519
6585
  },
6520
6586
  /**
@@ -6523,8 +6589,11 @@
6523
6589
  * @param {string} operator operator applied on the refined values
6524
6590
  * @return {Array.<number|number[]>} refined values
6525
6591
  */
6526
- getNumericRefinement: function(attribute, operator) {
6527
- return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
6592
+ getNumericRefinement: function (attribute, operator) {
6593
+ return (
6594
+ this.numericRefinements[attribute] &&
6595
+ this.numericRefinements[attribute][operator]
6596
+ );
6528
6597
  },
6529
6598
  /**
6530
6599
  * Clear numeric filters.
@@ -6534,7 +6603,7 @@
6534
6603
  * - If not given, means to clear all the filters.
6535
6604
  * - If `string`, means to clear all refinements for the `attribute` named filter.
6536
6605
  * - If `function`, means to clear all the refinements that return truthy values.
6537
- * @return {Object.<string, OperatorList>}
6606
+ * @return {Object.<string, OperatorList>} new numeric refinements
6538
6607
  */
6539
6608
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
6540
6609
  if (attribute === undefined) {
@@ -6547,39 +6616,50 @@
6547
6616
  } else if (typeof attribute === 'function') {
6548
6617
  var hasChanged = false;
6549
6618
  var numericRefinements = this.numericRefinements;
6550
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
6551
- var operators = numericRefinements[key];
6552
- var operatorList = {};
6553
-
6554
- operators = operators || {};
6555
- Object.keys(operators).forEach(function(operator) {
6556
- var values = operators[operator] || [];
6557
- var outValues = [];
6558
- values.forEach(function(value) {
6559
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
6560
- if (!predicateResult) outValues.push(value);
6619
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(
6620
+ function (memo, key) {
6621
+ var operators = numericRefinements[key];
6622
+ var operatorList = {};
6623
+
6624
+ operators = operators || {};
6625
+ Object.keys(operators).forEach(function (operator) {
6626
+ var values = operators[operator] || [];
6627
+ var outValues = [];
6628
+ values.forEach(function (value) {
6629
+ var predicateResult = attribute(
6630
+ { val: value, op: operator },
6631
+ key,
6632
+ 'numeric'
6633
+ );
6634
+ if (!predicateResult) outValues.push(value);
6635
+ });
6636
+ if (outValues.length !== values.length) {
6637
+ hasChanged = true;
6638
+ }
6639
+ operatorList[operator] = outValues;
6561
6640
  });
6562
- if (outValues.length !== values.length) {
6563
- hasChanged = true;
6564
- }
6565
- operatorList[operator] = outValues;
6566
- });
6567
6641
 
6568
- memo[key] = operatorList;
6642
+ memo[key] = operatorList;
6569
6643
 
6570
- return memo;
6571
- }, {});
6644
+ return memo;
6645
+ },
6646
+ {}
6647
+ );
6572
6648
 
6573
6649
  if (hasChanged) return newNumericRefinements;
6574
6650
  return this.numericRefinements;
6575
6651
  }
6652
+
6653
+ // We return nothing if the attribute is not undefined, a string or a function,
6654
+ // as it is not a valid value for a refinement
6655
+ return undefined;
6576
6656
  },
6577
6657
  /**
6578
6658
  * Add a facet to the facets attribute of the helper configuration, if it
6579
6659
  * isn't already present.
6580
6660
  * @method
6581
6661
  * @param {string} facet facet name to add
6582
- * @return {SearchParameters}
6662
+ * @return {SearchParameters} new instance
6583
6663
  */
6584
6664
  addFacet: function addFacet(facet) {
6585
6665
  if (this.isConjunctiveFacet(facet)) {
@@ -6587,7 +6667,7 @@
6587
6667
  }
6588
6668
 
6589
6669
  return this.setQueryParameters({
6590
- facets: this.facets.concat([facet])
6670
+ facets: this.facets.concat([facet]),
6591
6671
  });
6592
6672
  },
6593
6673
  /**
@@ -6595,7 +6675,7 @@
6595
6675
  * configuration, if it isn't already present.
6596
6676
  * @method
6597
6677
  * @param {string} facet disjunctive facet name to add
6598
- * @return {SearchParameters}
6678
+ * @return {SearchParameters} new instance
6599
6679
  */
6600
6680
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
6601
6681
  if (this.isDisjunctiveFacet(facet)) {
@@ -6603,7 +6683,7 @@
6603
6683
  }
6604
6684
 
6605
6685
  return this.setQueryParameters({
6606
- disjunctiveFacets: this.disjunctiveFacets.concat([facet])
6686
+ disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
6607
6687
  });
6608
6688
  },
6609
6689
  /**
@@ -6611,17 +6691,20 @@
6611
6691
  * configuration.
6612
6692
  * @method
6613
6693
  * @param {object} hierarchicalFacet hierarchical facet to add
6614
- * @return {SearchParameters}
6694
+ * @return {SearchParameters} new instance
6615
6695
  * @throws will throw an error if a hierarchical facet with the same name was already declared
6616
6696
  */
6617
6697
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
6618
6698
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
6619
6699
  throw new Error(
6620
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
6700
+ 'Cannot declare two hierarchical facets with the same name: `' +
6701
+ hierarchicalFacet.name +
6702
+ '`'
6703
+ );
6621
6704
  }
6622
6705
 
6623
6706
  return this.setQueryParameters({
6624
- hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
6707
+ hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
6625
6708
  });
6626
6709
  },
6627
6710
  /**
@@ -6629,16 +6712,24 @@
6629
6712
  * @method
6630
6713
  * @param {string} facet attribute to apply the faceting on
6631
6714
  * @param {string} value value of the attribute (will be converted to string)
6632
- * @return {SearchParameters}
6715
+ * @return {SearchParameters} new instance
6633
6716
  */
6634
6717
  addFacetRefinement: function addFacetRefinement(facet, value) {
6635
6718
  if (!this.isConjunctiveFacet(facet)) {
6636
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6719
+ throw new Error(
6720
+ facet +
6721
+ ' is not defined in the facets attribute of the helper configuration'
6722
+ );
6637
6723
  }
6638
- if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6724
+ if (RefinementList.isRefined(this.facetsRefinements, facet, value))
6725
+ return this;
6639
6726
 
6640
6727
  return this.setQueryParameters({
6641
- facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
6728
+ facetsRefinements: RefinementList.addRefinement(
6729
+ this.facetsRefinements,
6730
+ facet,
6731
+ value
6732
+ ),
6642
6733
  });
6643
6734
  },
6644
6735
  /**
@@ -6646,16 +6737,24 @@
6646
6737
  * @method
6647
6738
  * @param {string} facet attribute to apply the exclusion on
6648
6739
  * @param {string} value value of the attribute (will be converted to string)
6649
- * @return {SearchParameters}
6740
+ * @return {SearchParameters} new instance
6650
6741
  */
6651
6742
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
6652
6743
  if (!this.isConjunctiveFacet(facet)) {
6653
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6744
+ throw new Error(
6745
+ facet +
6746
+ ' is not defined in the facets attribute of the helper configuration'
6747
+ );
6654
6748
  }
6655
- if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6749
+ if (RefinementList.isRefined(this.facetsExcludes, facet, value))
6750
+ return this;
6656
6751
 
6657
6752
  return this.setQueryParameters({
6658
- facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
6753
+ facetsExcludes: RefinementList.addRefinement(
6754
+ this.facetsExcludes,
6755
+ facet,
6756
+ value
6757
+ ),
6659
6758
  });
6660
6759
  },
6661
6760
  /**
@@ -6663,31 +6762,42 @@
6663
6762
  * @method
6664
6763
  * @param {string} facet attribute to apply the faceting on
6665
6764
  * @param {string} value value of the attribute (will be converted to string)
6666
- * @return {SearchParameters}
6765
+ * @return {SearchParameters} new instance
6667
6766
  */
6668
- addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
6767
+ addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
6768
+ facet,
6769
+ value
6770
+ ) {
6669
6771
  if (!this.isDisjunctiveFacet(facet)) {
6670
6772
  throw new Error(
6671
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6773
+ facet +
6774
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
6775
+ );
6672
6776
  }
6673
6777
 
6674
- if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6778
+ if (
6779
+ RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
6780
+ )
6781
+ return this;
6675
6782
 
6676
6783
  return this.setQueryParameters({
6677
6784
  disjunctiveFacetsRefinements: RefinementList.addRefinement(
6678
- this.disjunctiveFacetsRefinements, facet, value)
6785
+ this.disjunctiveFacetsRefinements,
6786
+ facet,
6787
+ value
6788
+ ),
6679
6789
  });
6680
6790
  },
6681
6791
  /**
6682
6792
  * addTagRefinement adds a tag to the list used to filter the results
6683
6793
  * @param {string} tag tag to be added
6684
- * @return {SearchParameters}
6794
+ * @return {SearchParameters} new instance
6685
6795
  */
6686
6796
  addTagRefinement: function addTagRefinement(tag) {
6687
6797
  if (this.isTagRefined(tag)) return this;
6688
6798
 
6689
6799
  var modification = {
6690
- tagRefinements: this.tagRefinements.concat(tag)
6800
+ tagRefinements: this.tagRefinements.concat(tag),
6691
6801
  };
6692
6802
 
6693
6803
  return this.setQueryParameters(modification);
@@ -6697,7 +6807,7 @@
6697
6807
  * is present.
6698
6808
  * @method
6699
6809
  * @param {string} facet facet name to remove
6700
- * @return {SearchParameters}
6810
+ * @return {SearchParameters} new instance
6701
6811
  */
6702
6812
  removeFacet: function removeFacet(facet) {
6703
6813
  if (!this.isConjunctiveFacet(facet)) {
@@ -6705,9 +6815,9 @@
6705
6815
  }
6706
6816
 
6707
6817
  return this.clearRefinements(facet).setQueryParameters({
6708
- facets: this.facets.filter(function(f) {
6818
+ facets: this.facets.filter(function (f) {
6709
6819
  return f !== facet;
6710
- })
6820
+ }),
6711
6821
  });
6712
6822
  },
6713
6823
  /**
@@ -6715,7 +6825,7 @@
6715
6825
  * helper configuration, if it is present.
6716
6826
  * @method
6717
6827
  * @param {string} facet disjunctive facet name to remove
6718
- * @return {SearchParameters}
6828
+ * @return {SearchParameters} new instance
6719
6829
  */
6720
6830
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
6721
6831
  if (!this.isDisjunctiveFacet(facet)) {
@@ -6723,9 +6833,9 @@
6723
6833
  }
6724
6834
 
6725
6835
  return this.clearRefinements(facet).setQueryParameters({
6726
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
6836
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
6727
6837
  return f !== facet;
6728
- })
6838
+ }),
6729
6839
  });
6730
6840
  },
6731
6841
  /**
@@ -6733,7 +6843,7 @@
6733
6843
  * helper configuration, if it is present.
6734
6844
  * @method
6735
6845
  * @param {string} facet hierarchical facet name to remove
6736
- * @return {SearchParameters}
6846
+ * @return {SearchParameters} new instance
6737
6847
  */
6738
6848
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
6739
6849
  if (!this.isHierarchicalFacet(facet)) {
@@ -6741,9 +6851,9 @@
6741
6851
  }
6742
6852
 
6743
6853
  return this.clearRefinements(facet).setQueryParameters({
6744
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
6854
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
6745
6855
  return f.name !== facet;
6746
- })
6856
+ }),
6747
6857
  });
6748
6858
  },
6749
6859
  /**
@@ -6753,16 +6863,24 @@
6753
6863
  * @method
6754
6864
  * @param {string} facet name of the attribute used for faceting
6755
6865
  * @param {string} [value] value used to filter
6756
- * @return {SearchParameters}
6866
+ * @return {SearchParameters} new instance
6757
6867
  */
6758
6868
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
6759
6869
  if (!this.isConjunctiveFacet(facet)) {
6760
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6870
+ throw new Error(
6871
+ facet +
6872
+ ' is not defined in the facets attribute of the helper configuration'
6873
+ );
6761
6874
  }
6762
- if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6875
+ if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
6876
+ return this;
6763
6877
 
6764
6878
  return this.setQueryParameters({
6765
- facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
6879
+ facetsRefinements: RefinementList.removeRefinement(
6880
+ this.facetsRefinements,
6881
+ facet,
6882
+ value
6883
+ ),
6766
6884
  });
6767
6885
  },
6768
6886
  /**
@@ -6770,16 +6888,24 @@
6770
6888
  * @method
6771
6889
  * @param {string} facet name of the attribute used for faceting
6772
6890
  * @param {string} value value used to filter
6773
- * @return {SearchParameters}
6891
+ * @return {SearchParameters} new instance
6774
6892
  */
6775
6893
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
6776
6894
  if (!this.isConjunctiveFacet(facet)) {
6777
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6895
+ throw new Error(
6896
+ facet +
6897
+ ' is not defined in the facets attribute of the helper configuration'
6898
+ );
6778
6899
  }
6779
- if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6900
+ if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
6901
+ return this;
6780
6902
 
6781
6903
  return this.setQueryParameters({
6782
- facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
6904
+ facetsExcludes: RefinementList.removeRefinement(
6905
+ this.facetsExcludes,
6906
+ facet,
6907
+ value
6908
+ ),
6783
6909
  });
6784
6910
  },
6785
6911
  /**
@@ -6787,33 +6913,44 @@
6787
6913
  * @method
6788
6914
  * @param {string} facet name of the attribute used for faceting
6789
6915
  * @param {string} value value used to filter
6790
- * @return {SearchParameters}
6916
+ * @return {SearchParameters} new instance
6791
6917
  */
6792
- removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
6918
+ removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
6919
+ facet,
6920
+ value
6921
+ ) {
6793
6922
  if (!this.isDisjunctiveFacet(facet)) {
6794
6923
  throw new Error(
6795
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6924
+ facet +
6925
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
6926
+ );
6796
6927
  }
6797
- if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6928
+ if (
6929
+ !RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
6930
+ )
6931
+ return this;
6798
6932
 
6799
6933
  return this.setQueryParameters({
6800
6934
  disjunctiveFacetsRefinements: RefinementList.removeRefinement(
6801
- this.disjunctiveFacetsRefinements, facet, value)
6935
+ this.disjunctiveFacetsRefinements,
6936
+ facet,
6937
+ value
6938
+ ),
6802
6939
  });
6803
6940
  },
6804
6941
  /**
6805
6942
  * Remove a tag from the list of tag refinements
6806
6943
  * @method
6807
6944
  * @param {string} tag the tag to remove
6808
- * @return {SearchParameters}
6945
+ * @return {SearchParameters} new instance
6809
6946
  */
6810
6947
  removeTagRefinement: function removeTagRefinement(tag) {
6811
6948
  if (!this.isTagRefined(tag)) return this;
6812
6949
 
6813
6950
  var modification = {
6814
- tagRefinements: this.tagRefinements.filter(function(t) {
6951
+ tagRefinements: this.tagRefinements.filter(function (t) {
6815
6952
  return t !== tag;
6816
- })
6953
+ }),
6817
6954
  };
6818
6955
 
6819
6956
  return this.setQueryParameters(modification);
@@ -6823,7 +6960,7 @@
6823
6960
  * and hierarchical facets
6824
6961
  * @param {string} facet the facet to refine
6825
6962
  * @param {string} value the associated value
6826
- * @return {SearchParameters}
6963
+ * @return {SearchParameters} new instance
6827
6964
  * @throws will throw an error if the facet is not declared in the settings of the helper
6828
6965
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
6829
6966
  */
@@ -6835,7 +6972,7 @@
6835
6972
  * and hierarchical facets
6836
6973
  * @param {string} facet the facet to refine
6837
6974
  * @param {string} value the associated value
6838
- * @return {SearchParameters}
6975
+ * @return {SearchParameters} new instance
6839
6976
  * @throws will throw an error if the facet is not declared in the settings of the helper
6840
6977
  */
6841
6978
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -6847,23 +6984,36 @@
6847
6984
  return this.toggleDisjunctiveFacetRefinement(facet, value);
6848
6985
  }
6849
6986
 
6850
- throw new Error('Cannot refine the undeclared facet ' + facet +
6851
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
6987
+ throw new Error(
6988
+ 'Cannot refine the undeclared facet ' +
6989
+ facet +
6990
+ '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets'
6991
+ );
6852
6992
  },
6853
6993
  /**
6854
6994
  * Switch the refinement applied over a facet/value
6855
6995
  * @method
6856
6996
  * @param {string} facet name of the attribute used for faceting
6857
6997
  * @param {value} value value used for filtering
6858
- * @return {SearchParameters}
6998
+ * @return {SearchParameters} new instance
6859
6999
  */
6860
- toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
7000
+ toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
7001
+ facet,
7002
+ value
7003
+ ) {
6861
7004
  if (!this.isConjunctiveFacet(facet)) {
6862
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
7005
+ throw new Error(
7006
+ facet +
7007
+ ' is not defined in the facets attribute of the helper configuration'
7008
+ );
6863
7009
  }
6864
7010
 
6865
7011
  return this.setQueryParameters({
6866
- facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
7012
+ facetsRefinements: RefinementList.toggleRefinement(
7013
+ this.facetsRefinements,
7014
+ facet,
7015
+ value
7016
+ ),
6867
7017
  });
6868
7018
  },
6869
7019
  /**
@@ -6871,15 +7021,25 @@
6871
7021
  * @method
6872
7022
  * @param {string} facet name of the attribute used for faceting
6873
7023
  * @param {value} value value used for filtering
6874
- * @return {SearchParameters}
7024
+ * @return {SearchParameters} new instance
6875
7025
  */
6876
- toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
7026
+ toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
7027
+ facet,
7028
+ value
7029
+ ) {
6877
7030
  if (!this.isConjunctiveFacet(facet)) {
6878
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
7031
+ throw new Error(
7032
+ facet +
7033
+ ' is not defined in the facets attribute of the helper configuration'
7034
+ );
6879
7035
  }
6880
7036
 
6881
7037
  return this.setQueryParameters({
6882
- facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
7038
+ facetsExcludes: RefinementList.toggleRefinement(
7039
+ this.facetsExcludes,
7040
+ facet,
7041
+ value
7042
+ ),
6883
7043
  });
6884
7044
  },
6885
7045
  /**
@@ -6887,17 +7047,25 @@
6887
7047
  * @method
6888
7048
  * @param {string} facet name of the attribute used for faceting
6889
7049
  * @param {value} value value used for filtering
6890
- * @return {SearchParameters}
7050
+ * @return {SearchParameters} new instance
6891
7051
  */
6892
- toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
7052
+ toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
7053
+ facet,
7054
+ value
7055
+ ) {
6893
7056
  if (!this.isDisjunctiveFacet(facet)) {
6894
7057
  throw new Error(
6895
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
7058
+ facet +
7059
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
7060
+ );
6896
7061
  }
6897
7062
 
6898
7063
  return this.setQueryParameters({
6899
7064
  disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
6900
- this.disjunctiveFacetsRefinements, facet, value)
7065
+ this.disjunctiveFacetsRefinements,
7066
+ facet,
7067
+ value
7068
+ ),
6901
7069
  });
6902
7070
  },
6903
7071
  /**
@@ -6905,29 +7073,38 @@
6905
7073
  * @method
6906
7074
  * @param {string} facet name of the attribute used for faceting
6907
7075
  * @param {value} value value used for filtering
6908
- * @return {SearchParameters}
7076
+ * @return {SearchParameters} new instance
6909
7077
  */
6910
- toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
7078
+ toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
7079
+ facet,
7080
+ value
7081
+ ) {
6911
7082
  if (!this.isHierarchicalFacet(facet)) {
6912
7083
  throw new Error(
6913
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
7084
+ facet +
7085
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration'
7086
+ );
6914
7087
  }
6915
7088
 
6916
- var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
7089
+ var separator = this._getHierarchicalFacetSeparator(
7090
+ this.getHierarchicalFacetByName(facet)
7091
+ );
6917
7092
 
6918
7093
  var mod = {};
6919
7094
 
6920
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
6921
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
7095
+ var upOneOrMultipleLevel =
7096
+ this.hierarchicalFacetsRefinements[facet] !== undefined &&
7097
+ this.hierarchicalFacetsRefinements[facet].length > 0 &&
6922
7098
  // remove current refinement:
6923
7099
  // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
6924
- this.hierarchicalFacetsRefinements[facet][0] === value ||
6925
- // remove a parent refinement of the current refinement:
6926
- // - refinement was 'beer > IPA > Flying dog'
6927
- // - call is toggleRefine('beer > IPA')
6928
- // - refinement should be `beer`
6929
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
6930
- );
7100
+ (this.hierarchicalFacetsRefinements[facet][0] === value ||
7101
+ // remove a parent refinement of the current refinement:
7102
+ // - refinement was 'beer > IPA > Flying dog'
7103
+ // - call is toggleRefine('beer > IPA')
7104
+ // - refinement should be `beer`
7105
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(
7106
+ value + separator
7107
+ ) === 0);
6931
7108
 
6932
7109
  if (upOneOrMultipleLevel) {
6933
7110
  if (value.indexOf(separator) === -1) {
@@ -6941,7 +7118,11 @@
6941
7118
  }
6942
7119
 
6943
7120
  return this.setQueryParameters({
6944
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7121
+ hierarchicalFacetsRefinements: defaultsPure(
7122
+ {},
7123
+ mod,
7124
+ this.hierarchicalFacetsRefinements
7125
+ ),
6945
7126
  });
6946
7127
  },
6947
7128
 
@@ -6952,17 +7133,24 @@
6952
7133
  * @return {SearchParameter} the new state
6953
7134
  * @throws Error if the facet is not defined or if the facet is refined
6954
7135
  */
6955
- addHierarchicalFacetRefinement: function(facet, path) {
7136
+ addHierarchicalFacetRefinement: function (facet, path) {
6956
7137
  if (this.isHierarchicalFacetRefined(facet)) {
6957
7138
  throw new Error(facet + ' is already refined.');
6958
7139
  }
6959
7140
  if (!this.isHierarchicalFacet(facet)) {
6960
- throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration.');
7141
+ throw new Error(
7142
+ facet +
7143
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration.'
7144
+ );
6961
7145
  }
6962
7146
  var mod = {};
6963
7147
  mod[facet] = [path];
6964
7148
  return this.setQueryParameters({
6965
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7149
+ hierarchicalFacetsRefinements: defaultsPure(
7150
+ {},
7151
+ mod,
7152
+ this.hierarchicalFacetsRefinements
7153
+ ),
6966
7154
  });
6967
7155
  },
6968
7156
 
@@ -6972,21 +7160,25 @@
6972
7160
  * @return {SearchParameter} the new state
6973
7161
  * @throws Error if the facet is not defined or if the facet is not refined
6974
7162
  */
6975
- removeHierarchicalFacetRefinement: function(facet) {
7163
+ removeHierarchicalFacetRefinement: function (facet) {
6976
7164
  if (!this.isHierarchicalFacetRefined(facet)) {
6977
7165
  return this;
6978
7166
  }
6979
7167
  var mod = {};
6980
7168
  mod[facet] = [];
6981
7169
  return this.setQueryParameters({
6982
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
7170
+ hierarchicalFacetsRefinements: defaultsPure(
7171
+ {},
7172
+ mod,
7173
+ this.hierarchicalFacetsRefinements
7174
+ ),
6983
7175
  });
6984
7176
  },
6985
7177
  /**
6986
7178
  * Switch the tag refinement
6987
7179
  * @method
6988
7180
  * @param {string} tag the tag to remove or add
6989
- * @return {SearchParameters}
7181
+ * @return {SearchParameters} new instance
6990
7182
  */
6991
7183
  toggleTagRefinement: function toggleTagRefinement(tag) {
6992
7184
  if (this.isTagRefined(tag)) {
@@ -6999,27 +7191,27 @@
6999
7191
  * Test if the facet name is from one of the disjunctive facets
7000
7192
  * @method
7001
7193
  * @param {string} facet facet name to test
7002
- * @return {boolean}
7194
+ * @return {boolean} true if facet is a disjunctive facet
7003
7195
  */
7004
- isDisjunctiveFacet: function(facet) {
7196
+ isDisjunctiveFacet: function (facet) {
7005
7197
  return this.disjunctiveFacets.indexOf(facet) > -1;
7006
7198
  },
7007
7199
  /**
7008
7200
  * Test if the facet name is from one of the hierarchical facets
7009
7201
  * @method
7010
7202
  * @param {string} facetName facet name to test
7011
- * @return {boolean}
7203
+ * @return {boolean} true if facetName is a hierarchical facet
7012
7204
  */
7013
- isHierarchicalFacet: function(facetName) {
7205
+ isHierarchicalFacet: function (facetName) {
7014
7206
  return this.getHierarchicalFacetByName(facetName) !== undefined;
7015
7207
  },
7016
7208
  /**
7017
7209
  * Test if the facet name is from one of the conjunctive/normal facets
7018
7210
  * @method
7019
7211
  * @param {string} facet facet name to test
7020
- * @return {boolean}
7212
+ * @return {boolean} true if facet is a conjunctive facet
7021
7213
  */
7022
- isConjunctiveFacet: function(facet) {
7214
+ isConjunctiveFacet: function (facet) {
7023
7215
  return this.facets.indexOf(facet) > -1;
7024
7216
  },
7025
7217
  /**
@@ -7060,13 +7252,17 @@
7060
7252
  * @param {string} facet name of the attribute for used for faceting
7061
7253
  * @param {string} value optional, will test if the value is used for refinement
7062
7254
  * if there is one, otherwise will test if the facet contains any refinement
7063
- * @return {boolean}
7255
+ * @return {boolean} true if the facet is refined
7064
7256
  */
7065
7257
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
7066
7258
  if (!this.isDisjunctiveFacet(facet)) {
7067
7259
  return false;
7068
7260
  }
7069
- return RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value);
7261
+ return RefinementList.isRefined(
7262
+ this.disjunctiveFacetsRefinements,
7263
+ facet,
7264
+ value
7265
+ );
7070
7266
  },
7071
7267
  /**
7072
7268
  * Returns true if the facet contains a refinement, or if a value passed is a
@@ -7075,9 +7271,12 @@
7075
7271
  * @param {string} facet name of the attribute for used for faceting
7076
7272
  * @param {string} value optional, will test if the value is used for refinement
7077
7273
  * if there is one, otherwise will test if the facet contains any refinement
7078
- * @return {boolean}
7274
+ * @return {boolean} true if the facet is refined
7079
7275
  */
7080
- isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
7276
+ isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
7277
+ facet,
7278
+ value
7279
+ ) {
7081
7280
  if (!this.isHierarchicalFacet(facet)) {
7082
7281
  return false;
7083
7282
  }
@@ -7102,7 +7301,7 @@
7102
7301
  */
7103
7302
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
7104
7303
  if (value === undefined && operator === undefined) {
7105
- return !!this.numericRefinements[attribute];
7304
+ return Boolean(this.numericRefinements[attribute]);
7106
7305
  }
7107
7306
 
7108
7307
  var isOperatorDefined =
@@ -7124,7 +7323,7 @@
7124
7323
  * Returns true if the tag refined, false otherwise
7125
7324
  * @method
7126
7325
  * @param {string} tag the tag to check
7127
- * @return {boolean}
7326
+ * @return {boolean} true if tag is refined
7128
7327
  */
7129
7328
  isTagRefined: function isTagRefined(tag) {
7130
7329
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -7134,22 +7333,24 @@
7134
7333
  * @method
7135
7334
  * @param {string} facet name of the attribute used for faceting
7136
7335
  * @param {value} value value used for filtering
7137
- * @return {string[]}
7336
+ * @return {string[]} returns the list of refinements
7138
7337
  */
7139
7338
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
7339
+ // eslint-disable-next-line consistent-this
7140
7340
  var self = this;
7141
7341
 
7142
7342
  // attributes used for numeric filter can also be disjunctive
7143
7343
  var disjunctiveNumericRefinedFacets = intersection_1(
7144
- Object.keys(this.numericRefinements).filter(function(facet) {
7344
+ Object.keys(this.numericRefinements).filter(function (facet) {
7145
7345
  return Object.keys(self.numericRefinements[facet]).length > 0;
7146
7346
  }),
7147
7347
  this.disjunctiveFacets
7148
7348
  );
7149
7349
 
7150
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
7151
- return self.disjunctiveFacetsRefinements[facet].length > 0;
7152
- })
7350
+ return Object.keys(this.disjunctiveFacetsRefinements)
7351
+ .filter(function (facet) {
7352
+ return self.disjunctiveFacetsRefinements[facet].length > 0;
7353
+ })
7153
7354
  .concat(disjunctiveNumericRefinedFacets)
7154
7355
  .concat(this.getRefinedHierarchicalFacets());
7155
7356
  },
@@ -7158,15 +7359,18 @@
7158
7359
  * @method
7159
7360
  * @param {string} facet name of the attribute used for faceting
7160
7361
  * @param {value} value value used for filtering
7161
- * @return {string[]}
7362
+ * @return {string[]} returns the list of refinements
7162
7363
  */
7163
7364
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
7365
+ // eslint-disable-next-line consistent-this
7164
7366
  var self = this;
7165
7367
  return intersection_1(
7166
7368
  // enforce the order between the two arrays,
7167
7369
  // so that refinement name index === hierarchical facet index
7168
- this.hierarchicalFacets.map(function(facet) { return facet.name; }),
7169
- Object.keys(this.hierarchicalFacetsRefinements).filter(function(facet) {
7370
+ this.hierarchicalFacets.map(function (facet) {
7371
+ return facet.name;
7372
+ }),
7373
+ Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
7170
7374
  return self.hierarchicalFacetsRefinements[facet].length > 0;
7171
7375
  })
7172
7376
  );
@@ -7174,12 +7378,12 @@
7174
7378
  /**
7175
7379
  * Returned the list of all disjunctive facets not refined
7176
7380
  * @method
7177
- * @return {string[]}
7381
+ * @return {string[]} returns the list of facets that are not refined
7178
7382
  */
7179
- getUnrefinedDisjunctiveFacets: function() {
7383
+ getUnrefinedDisjunctiveFacets: function () {
7180
7384
  var refinedFacets = this.getRefinedDisjunctiveFacets();
7181
7385
 
7182
- return this.disjunctiveFacets.filter(function(f) {
7386
+ return this.disjunctiveFacets.filter(function (f) {
7183
7387
  return refinedFacets.indexOf(f) === -1;
7184
7388
  });
7185
7389
  },
@@ -7196,17 +7400,22 @@
7196
7400
  'disjunctiveFacetsRefinements',
7197
7401
  'numericRefinements',
7198
7402
  'tagRefinements',
7199
- 'hierarchicalFacetsRefinements'
7403
+ 'hierarchicalFacetsRefinements',
7200
7404
  ],
7405
+
7201
7406
  getQueryParams: function getQueryParams() {
7202
7407
  var managedParameters = this.managedParameters;
7203
7408
 
7204
7409
  var queryParams = {};
7205
7410
 
7411
+ // eslint-disable-next-line consistent-this
7206
7412
  var self = this;
7207
- Object.keys(this).forEach(function(paramName) {
7413
+ Object.keys(this).forEach(function (paramName) {
7208
7414
  var paramValue = self[paramName];
7209
- if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
7415
+ if (
7416
+ managedParameters.indexOf(paramName) === -1 &&
7417
+ paramValue !== undefined
7418
+ ) {
7210
7419
  queryParams[paramName] = paramValue;
7211
7420
  }
7212
7421
  });
@@ -7247,30 +7456,32 @@
7247
7456
  throw error;
7248
7457
  }
7249
7458
 
7459
+ // eslint-disable-next-line consistent-this
7250
7460
  var self = this;
7251
7461
  var nextWithNumbers = SearchParameters._parseNumbers(params);
7252
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
7462
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
7253
7463
  acc[key] = self[key];
7254
7464
  return acc;
7255
7465
  }, {});
7256
7466
 
7257
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
7258
- function(previous, key) {
7259
- var isPreviousValueDefined = previous[key] !== undefined;
7260
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
7467
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
7468
+ previous,
7469
+ key
7470
+ ) {
7471
+ var isPreviousValueDefined = previous[key] !== undefined;
7472
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
7261
7473
 
7262
- if (isPreviousValueDefined && !isNextValueDefined) {
7263
- return omit$1(previous, [key]);
7264
- }
7474
+ if (isPreviousValueDefined && !isNextValueDefined) {
7475
+ return omit$1(previous, [key]);
7476
+ }
7265
7477
 
7266
- if (isNextValueDefined) {
7267
- previous[key] = nextWithNumbers[key];
7268
- }
7478
+ if (isNextValueDefined) {
7479
+ previous[key] = nextWithNumbers[key];
7480
+ }
7269
7481
 
7270
- return previous;
7271
- },
7272
- previousPlainObject
7273
- );
7482
+ return previous;
7483
+ },
7484
+ previousPlainObject);
7274
7485
 
7275
7486
  return new this.constructor(nextPlainObject);
7276
7487
  },
@@ -7281,7 +7492,7 @@
7281
7492
  * the page is set -> return a new instance with a page of 0
7282
7493
  * @return {SearchParameters} a new updated instance
7283
7494
  */
7284
- resetPage: function() {
7495
+ resetPage: function () {
7285
7496
  if (this.page === undefined) {
7286
7497
  return this;
7287
7498
  }
@@ -7291,40 +7502,40 @@
7291
7502
 
7292
7503
  /**
7293
7504
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7294
- * @param {object} hierarchicalFacet
7505
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7295
7506
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7296
7507
  */
7297
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
7508
+ _getHierarchicalFacetSortBy: function (hierarchicalFacet) {
7298
7509
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
7299
7510
  },
7300
7511
 
7301
7512
  /**
7302
7513
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7303
7514
  * @private
7304
- * @param {object} hierarchicalFacet
7515
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7305
7516
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7306
7517
  */
7307
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
7518
+ _getHierarchicalFacetSeparator: function (hierarchicalFacet) {
7308
7519
  return hierarchicalFacet.separator || ' > ';
7309
7520
  },
7310
7521
 
7311
7522
  /**
7312
7523
  * Helper function to get the hierarchicalFacet prefix path or null
7313
7524
  * @private
7314
- * @param {object} hierarchicalFacet
7525
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7315
7526
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
7316
7527
  */
7317
- _getHierarchicalRootPath: function(hierarchicalFacet) {
7528
+ _getHierarchicalRootPath: function (hierarchicalFacet) {
7318
7529
  return hierarchicalFacet.rootPath || null;
7319
7530
  },
7320
7531
 
7321
7532
  /**
7322
7533
  * Helper function to check if we show the parent level of the hierarchicalFacet
7323
7534
  * @private
7324
- * @param {object} hierarchicalFacet
7535
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7325
7536
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
7326
7537
  */
7327
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
7538
+ _getHierarchicalShowParentLevel: function (hierarchicalFacet) {
7328
7539
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
7329
7540
  return hierarchicalFacet.showParentLevel;
7330
7541
  }
@@ -7333,16 +7544,13 @@
7333
7544
 
7334
7545
  /**
7335
7546
  * Helper function to get the hierarchicalFacet by it's name
7336
- * @param {string} hierarchicalFacetName
7547
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
7337
7548
  * @return {object} a hierarchicalFacet
7338
7549
  */
7339
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
7340
- return find$1(
7341
- this.hierarchicalFacets,
7342
- function(f) {
7343
- return f.name === hierarchicalFacetName;
7344
- }
7345
- );
7550
+ getHierarchicalFacetByName: function (hierarchicalFacetName) {
7551
+ return find$1(this.hierarchicalFacets, function (f) {
7552
+ return f.name === hierarchicalFacetName;
7553
+ });
7346
7554
  },
7347
7555
 
7348
7556
  /**
@@ -7350,7 +7558,7 @@
7350
7558
  * @param {string} facetName Hierarchical facet name
7351
7559
  * @return {array.<string>} the path as an array of string
7352
7560
  */
7353
- getHierarchicalFacetBreadcrumb: function(facetName) {
7561
+ getHierarchicalFacetBreadcrumb: function (facetName) {
7354
7562
  if (!this.isHierarchicalFacet(facetName)) {
7355
7563
  return [];
7356
7564
  }
@@ -7362,14 +7570,14 @@
7362
7570
  this.getHierarchicalFacetByName(facetName)
7363
7571
  );
7364
7572
  var path = refinement.split(separator);
7365
- return path.map(function(part) {
7573
+ return path.map(function (part) {
7366
7574
  return part.trim();
7367
7575
  });
7368
7576
  },
7369
7577
 
7370
- toString: function() {
7578
+ toString: function () {
7371
7579
  return JSON.stringify(this, null, 2);
7372
- }
7580
+ },
7373
7581
  };
7374
7582
 
7375
7583
  /**
@@ -7413,6 +7621,7 @@
7413
7621
  * @param {Array<object>} collection object with keys in attributes
7414
7622
  * @param {Array<string>} iteratees attributes
7415
7623
  * @param {Array<string>} orders asc | desc
7624
+ * @return {Array<object>} sorted collection
7416
7625
  */
7417
7626
  function orderBy(collection, iteratees, orders) {
7418
7627
  if (!Array.isArray(collection)) {
@@ -7423,13 +7632,13 @@
7423
7632
  orders = [];
7424
7633
  }
7425
7634
 
7426
- var result = collection.map(function(value, index) {
7635
+ var result = collection.map(function (value, index) {
7427
7636
  return {
7428
- criteria: iteratees.map(function(iteratee) {
7637
+ criteria: iteratees.map(function (iteratee) {
7429
7638
  return value[iteratee];
7430
7639
  }),
7431
7640
  index: index,
7432
- value: value
7641
+ value: value,
7433
7642
  };
7434
7643
  });
7435
7644
 
@@ -7454,7 +7663,7 @@
7454
7663
  return object.index - other.index;
7455
7664
  });
7456
7665
 
7457
- return result.map(function(res) {
7666
+ return result.map(function (res) {
7458
7667
  return res.value;
7459
7668
  });
7460
7669
  }
@@ -7490,7 +7699,7 @@
7490
7699
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
7491
7700
  */
7492
7701
  var formatSort = function formatSort(sortBy, defaults) {
7493
- var defaultInstructions = (defaults || []).map(function(sort) {
7702
+ var defaultInstructions = (defaults || []).map(function (sort) {
7494
7703
  return sort.split(':');
7495
7704
  });
7496
7705
 
@@ -7498,11 +7707,12 @@
7498
7707
  function preparePredicate(out, sort) {
7499
7708
  var sortInstruction = sort.split(':');
7500
7709
 
7501
- var matchingDefault = find$1(defaultInstructions, function(
7502
- defaultInstruction
7503
- ) {
7504
- return defaultInstruction[0] === sortInstruction[0];
7505
- });
7710
+ var matchingDefault = find$1(
7711
+ defaultInstructions,
7712
+ function (defaultInstruction) {
7713
+ return defaultInstruction[0] === sortInstruction[0];
7714
+ }
7715
+ );
7506
7716
 
7507
7717
  if (sortInstruction.length > 1 || !matchingDefault) {
7508
7718
  out[0].push(sortInstruction[0]);
@@ -7522,7 +7732,7 @@
7522
7732
  * Replaces a leading - with \-
7523
7733
  * @private
7524
7734
  * @param {any} value the facet value to replace
7525
- * @returns any
7735
+ * @returns {any} the escaped facet value or the value if it was not a string
7526
7736
  */
7527
7737
  function escapeFacetValue$1(value) {
7528
7738
  if (typeof value !== 'string') return value;
@@ -7534,7 +7744,7 @@
7534
7744
  * Replaces a leading \- with -
7535
7745
  * @private
7536
7746
  * @param {any} value the escaped facet value
7537
- * @returns any
7747
+ * @returns {any} the unescaped facet value or the value if it was not a string
7538
7748
  */
7539
7749
  function unescapeFacetValue$1(value) {
7540
7750
  if (typeof value !== 'string') return value;
@@ -7544,7 +7754,7 @@
7544
7754
 
7545
7755
  var escapeFacetValue_1 = {
7546
7756
  escapeFacetValue: escapeFacetValue$1,
7547
- unescapeFacetValue: unescapeFacetValue$1
7757
+ unescapeFacetValue: unescapeFacetValue$1,
7548
7758
  };
7549
7759
 
7550
7760
  var generateHierarchicalTree_1 = generateTrees;
@@ -7563,20 +7773,17 @@
7563
7773
  (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
7564
7774
  state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
7565
7775
  '';
7566
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
7567
- hierarchicalFacet
7568
- );
7569
- var hierarchicalRootPath = state._getHierarchicalRootPath(
7570
- hierarchicalFacet
7571
- );
7572
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
7573
- hierarchicalFacet
7574
- );
7776
+ var hierarchicalSeparator =
7777
+ state._getHierarchicalFacetSeparator(hierarchicalFacet);
7778
+ var hierarchicalRootPath =
7779
+ state._getHierarchicalRootPath(hierarchicalFacet);
7780
+ var hierarchicalShowParentLevel =
7781
+ state._getHierarchicalShowParentLevel(hierarchicalFacet);
7575
7782
  var sortBy = formatSort(
7576
7783
  state._getHierarchicalFacetSortBy(hierarchicalFacet)
7577
7784
  );
7578
7785
 
7579
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
7786
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
7580
7787
  return facetResult.exhaustive;
7581
7788
  });
7582
7789
 
@@ -7603,7 +7810,7 @@
7603
7810
  path: null, // root level, no path
7604
7811
  escapedValue: null,
7605
7812
  exhaustive: rootExhaustive,
7606
- data: null
7813
+ data: null,
7607
7814
  });
7608
7815
  };
7609
7816
  }
@@ -7632,7 +7839,7 @@
7632
7839
  * @type {object[]]} hierarchical data
7633
7840
  */
7634
7841
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
7635
- parent = find$1(data, function(subtree) {
7842
+ parent = find$1(data, function (subtree) {
7636
7843
  return subtree.isRefined;
7637
7844
  });
7638
7845
  level++;
@@ -7653,10 +7860,10 @@
7653
7860
  // showing up
7654
7861
 
7655
7862
  var picked = Object.keys(hierarchicalFacetResult.data)
7656
- .map(function(facetValue) {
7863
+ .map(function (facetValue) {
7657
7864
  return [facetValue, hierarchicalFacetResult.data[facetValue]];
7658
7865
  })
7659
- .filter(function(tuple) {
7866
+ .filter(function (tuple) {
7660
7867
  var facetValue = tuple[0];
7661
7868
  return onlyMatchingTree(
7662
7869
  facetValue,
@@ -7669,7 +7876,7 @@
7669
7876
  });
7670
7877
 
7671
7878
  parent.data = orderBy_1(
7672
- picked.map(function(tuple) {
7879
+ picked.map(function (tuple) {
7673
7880
  var facetValue = tuple[0];
7674
7881
  var facetCount = tuple[1];
7675
7882
 
@@ -7690,6 +7897,7 @@
7690
7897
  };
7691
7898
  }
7692
7899
 
7900
+ // eslint-disable-next-line max-params
7693
7901
  function onlyMatchingTree(
7694
7902
  facetValue,
7695
7903
  parentPath,
@@ -7746,7 +7954,7 @@
7746
7954
  currentRefinement === facetValue ||
7747
7955
  currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
7748
7956
  exhaustive: exhaustive,
7749
- data: null
7957
+ data: null,
7750
7958
  };
7751
7959
  }
7752
7960
 
@@ -7797,12 +8005,14 @@
7797
8005
  */
7798
8006
 
7799
8007
  /**
7800
- * @param {string[]} attributes
8008
+ * Turn an array of attributes in an object of attributes with their position in the array as value
8009
+ * @param {string[]} attributes the list of attributes in the record
8010
+ * @return {object} the list of attributes indexed by attribute name
7801
8011
  */
7802
8012
  function getIndices(attributes) {
7803
8013
  var indices = {};
7804
8014
 
7805
- attributes.forEach(function(val, idx) {
8015
+ attributes.forEach(function (val, idx) {
7806
8016
  indices[val] = idx;
7807
8017
  });
7808
8018
 
@@ -7822,22 +8032,24 @@
7822
8032
  */
7823
8033
 
7824
8034
  /**
7825
- * @param {HierarchicalFacet[]} hierarchicalFacets
7826
- * @param {string} hierarchicalAttributeName
8035
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
8036
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
8037
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
7827
8038
  */
7828
8039
  function findMatchingHierarchicalFacetFromAttributeName(
7829
8040
  hierarchicalFacets,
7830
8041
  hierarchicalAttributeName
7831
8042
  ) {
7832
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
7833
- hierarchicalFacet
7834
- ) {
7835
- var facetNames = hierarchicalFacet.attributes || [];
7836
- return facetNames.indexOf(hierarchicalAttributeName) > -1;
7837
- });
8043
+ return find$1(
8044
+ hierarchicalFacets,
8045
+ function facetKeyMatchesAttribute(hierarchicalFacet) {
8046
+ var facetNames = hierarchicalFacet.attributes || [];
8047
+ return facetNames.indexOf(hierarchicalAttributeName) > -1;
8048
+ }
8049
+ );
7838
8050
  }
7839
8051
 
7840
- /*eslint-disable */
8052
+ // eslint-disable-next-line valid-jsdoc
7841
8053
  /**
7842
8054
  * Constructor for SearchResults
7843
8055
  * @class
@@ -7968,21 +8180,21 @@
7968
8180
  "index": "bestbuy"
7969
8181
  }
7970
8182
  **/
7971
- /*eslint-enable */
7972
8183
  function SearchResults(state, results, options) {
7973
8184
  var mainSubResponse = results[0];
7974
8185
 
7975
8186
  this._rawResults = results;
7976
8187
 
8188
+ // eslint-disable-next-line consistent-this
7977
8189
  var self = this;
7978
8190
 
7979
8191
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
7980
- Object.keys(mainSubResponse).forEach(function(key) {
8192
+ Object.keys(mainSubResponse).forEach(function (key) {
7981
8193
  self[key] = mainSubResponse[key];
7982
8194
  });
7983
8195
 
7984
8196
  // Make every key of the result options reachable from the instance
7985
- Object.keys(options || {}).forEach(function(key) {
8197
+ Object.keys(options || {}).forEach(function (key) {
7986
8198
  self[key] = options[key];
7987
8199
  });
7988
8200
 
@@ -8004,8 +8216,8 @@
8004
8216
  * all the records that match the search parameters. Each record is
8005
8217
  * augmented with a new attribute `_highlightResult`
8006
8218
  * which is an object keyed by attribute and with the following properties:
8007
- * - `value` : the value of the facet highlighted (html)
8008
- * - `matchLevel`: full, partial or none depending on how the query terms match
8219
+ * - `value` : the value of the facet highlighted (html)
8220
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
8009
8221
  * @name hits
8010
8222
  * @member {object[]}
8011
8223
  * @memberof SearchResults
@@ -8126,7 +8338,7 @@
8126
8338
  * @memberof SearchResults
8127
8339
  * @instance
8128
8340
  */
8129
- this.processingTimeMS = results.reduce(function(sum, result) {
8341
+ this.processingTimeMS = results.reduce(function (sum, result) {
8130
8342
  return result.processingTimeMS === undefined
8131
8343
  ? sum
8132
8344
  : sum + result.processingTimeMS;
@@ -8141,9 +8353,11 @@
8141
8353
  * disjunctive facets results
8142
8354
  * @member {SearchResults.HierarchicalFacet[]}
8143
8355
  */
8144
- this.hierarchicalFacets = state.hierarchicalFacets.map(function initFutureTree() {
8145
- return [];
8146
- });
8356
+ this.hierarchicalFacets = state.hierarchicalFacets.map(
8357
+ function initFutureTree() {
8358
+ return [];
8359
+ }
8360
+ );
8147
8361
  /**
8148
8362
  * other facets results
8149
8363
  * @member {SearchResults.Facet[]}
@@ -8161,7 +8375,7 @@
8161
8375
 
8162
8376
  var mainFacets = mainSubResponse.facets || {};
8163
8377
 
8164
- Object.keys(mainFacets).forEach(function(facetKey) {
8378
+ Object.keys(mainFacets).forEach(function (facetKey) {
8165
8379
  var facetValueObject = mainFacets[facetKey];
8166
8380
 
8167
8381
  var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
@@ -8173,13 +8387,13 @@
8173
8387
  // Place the hierarchicalFacet data at the correct index depending on
8174
8388
  // the attributes order that was defined at the helper initialization
8175
8389
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
8176
- var idxAttributeName = findIndex$1(state.hierarchicalFacets, function(f) {
8390
+ var idxAttributeName = findIndex$1(state.hierarchicalFacets, function (f) {
8177
8391
  return f.name === hierarchicalFacet.name;
8178
8392
  });
8179
8393
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
8180
8394
  attribute: facetKey,
8181
8395
  data: facetValueObject,
8182
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8396
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
8183
8397
  };
8184
8398
  } else {
8185
8399
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
@@ -8191,18 +8405,26 @@
8191
8405
  self.disjunctiveFacets[position] = {
8192
8406
  name: facetKey,
8193
8407
  data: facetValueObject,
8194
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8408
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
8195
8409
  };
8196
- assignFacetStats(self.disjunctiveFacets[position], mainSubResponse.facets_stats, facetKey);
8410
+ assignFacetStats(
8411
+ self.disjunctiveFacets[position],
8412
+ mainSubResponse.facets_stats,
8413
+ facetKey
8414
+ );
8197
8415
  }
8198
8416
  if (isFacetConjunctive) {
8199
8417
  position = facetsIndices[facetKey];
8200
8418
  self.facets[position] = {
8201
8419
  name: facetKey,
8202
8420
  data: facetValueObject,
8203
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8421
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
8204
8422
  };
8205
- assignFacetStats(self.facets[position], mainSubResponse.facets_stats, facetKey);
8423
+ assignFacetStats(
8424
+ self.facets[position],
8425
+ mainSubResponse.facets_stats,
8426
+ facetKey
8427
+ );
8206
8428
  }
8207
8429
  }
8208
8430
  });
@@ -8211,24 +8433,27 @@
8211
8433
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
8212
8434
 
8213
8435
  // aggregate the refined disjunctive facets
8214
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
8436
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
8215
8437
  var result = results[nextDisjunctiveResult];
8216
8438
  var facets = result && result.facets ? result.facets : {};
8217
8439
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
8218
8440
 
8219
8441
  // There should be only item in facets.
8220
- Object.keys(facets).forEach(function(dfacet) {
8442
+ Object.keys(facets).forEach(function (dfacet) {
8221
8443
  var facetResults = facets[dfacet];
8222
8444
 
8223
8445
  var position;
8224
8446
 
8225
8447
  if (hierarchicalFacet) {
8226
- position = findIndex$1(state.hierarchicalFacets, function(f) {
8448
+ position = findIndex$1(state.hierarchicalFacets, function (f) {
8227
8449
  return f.name === hierarchicalFacet.name;
8228
8450
  });
8229
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
8230
- return f.attribute === dfacet;
8231
- });
8451
+ var attributeIndex = findIndex$1(
8452
+ self.hierarchicalFacets[position],
8453
+ function (f) {
8454
+ return f.attribute === dfacet;
8455
+ }
8456
+ );
8232
8457
 
8233
8458
  // previous refinements and no results so not able to find it
8234
8459
  if (attributeIndex === -1) {
@@ -8243,20 +8468,31 @@
8243
8468
  } else {
8244
8469
  position = disjunctiveFacetsIndices[dfacet];
8245
8470
 
8246
- var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
8471
+ var dataFromMainRequest =
8472
+ (mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
8247
8473
 
8248
8474
  self.disjunctiveFacets[position] = {
8249
8475
  name: dfacet,
8250
8476
  data: defaultsPure({}, facetResults, dataFromMainRequest),
8251
- exhaustive: result.exhaustiveFacetsCount
8477
+ exhaustive: result.exhaustiveFacetsCount,
8252
8478
  };
8253
- assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
8479
+ assignFacetStats(
8480
+ self.disjunctiveFacets[position],
8481
+ result.facets_stats,
8482
+ dfacet
8483
+ );
8254
8484
 
8255
8485
  if (state.disjunctiveFacetsRefinements[dfacet]) {
8256
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
8486
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (
8487
+ refinementValue
8488
+ ) {
8257
8489
  // add the disjunctive refinements if it is no more retrieved
8258
- if (!self.disjunctiveFacets[position].data[refinementValue] &&
8259
- state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
8490
+ if (
8491
+ !self.disjunctiveFacets[position].data[refinementValue] &&
8492
+ state.disjunctiveFacetsRefinements[dfacet].indexOf(
8493
+ unescapeFacetValue$3(refinementValue)
8494
+ ) > -1
8495
+ ) {
8260
8496
  self.disjunctiveFacets[position].data[refinementValue] = 0;
8261
8497
  }
8262
8498
  });
@@ -8267,30 +8503,34 @@
8267
8503
  });
8268
8504
 
8269
8505
  // if we have some parent level values for hierarchical facets, merge them
8270
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
8506
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
8271
8507
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
8272
8508
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
8273
8509
 
8274
8510
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
8275
8511
  // if we are already at a root refinement (or no refinement at all), there is no
8276
8512
  // root level values request
8277
- if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
8513
+ if (
8514
+ currentRefinement.length === 0 ||
8515
+ currentRefinement[0].split(separator).length < 2
8516
+ ) {
8278
8517
  return;
8279
8518
  }
8280
8519
 
8281
- results.slice(nextDisjunctiveResult).forEach(function(result) {
8282
- var facets = result && result.facets
8283
- ? result.facets
8284
- : {};
8520
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
8521
+ var facets = result && result.facets ? result.facets : {};
8285
8522
 
8286
- Object.keys(facets).forEach(function(dfacet) {
8523
+ Object.keys(facets).forEach(function (dfacet) {
8287
8524
  var facetResults = facets[dfacet];
8288
- var position = findIndex$1(state.hierarchicalFacets, function(f) {
8525
+ var position = findIndex$1(state.hierarchicalFacets, function (f) {
8289
8526
  return f.name === hierarchicalFacet.name;
8290
8527
  });
8291
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
8292
- return f.attribute === dfacet;
8293
- });
8528
+ var attributeIndex = findIndex$1(
8529
+ self.hierarchicalFacets[position],
8530
+ function (f) {
8531
+ return f.attribute === dfacet;
8532
+ }
8533
+ );
8294
8534
 
8295
8535
  // previous refinements and no results so not able to find it
8296
8536
  if (attributeIndex === -1) {
@@ -8309,7 +8549,8 @@
8309
8549
 
8310
8550
  if (currentRefinement.length > 0) {
8311
8551
  var root = currentRefinement[0].split(separator)[0];
8312
- defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
8552
+ defaultData[root] =
8553
+ self.hierarchicalFacets[position][attributeIndex].data[root];
8313
8554
  }
8314
8555
 
8315
8556
  self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
@@ -8324,17 +8565,17 @@
8324
8565
  });
8325
8566
 
8326
8567
  // add the excludes
8327
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
8568
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
8328
8569
  var excludes = state.facetsExcludes[facetName];
8329
8570
  var position = facetsIndices[facetName];
8330
8571
 
8331
8572
  self.facets[position] = {
8332
8573
  name: facetName,
8333
8574
  data: mainFacets[facetName],
8334
- exhaustive: mainSubResponse.exhaustiveFacetsCount
8575
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
8335
8576
  };
8336
- excludes.forEach(function(facetValue) {
8337
- self.facets[position] = self.facets[position] || {name: facetName};
8577
+ excludes.forEach(function (facetValue) {
8578
+ self.facets[position] = self.facets[position] || { name: facetName };
8338
8579
  self.facets[position].data = self.facets[position].data || {};
8339
8580
  self.facets[position].data[facetValue] = 0;
8340
8581
  });
@@ -8343,7 +8584,9 @@
8343
8584
  /**
8344
8585
  * @type {Array}
8345
8586
  */
8346
- this.hierarchicalFacets = this.hierarchicalFacets.map(generateHierarchicalTree_1(state));
8587
+ this.hierarchicalFacets = this.hierarchicalFacets.map(
8588
+ generateHierarchicalTree_1(state)
8589
+ );
8347
8590
 
8348
8591
  /**
8349
8592
  * @type {Array}
@@ -8363,14 +8606,16 @@
8363
8606
  * @param {string} name name of the faceted attribute
8364
8607
  * @return {SearchResults.Facet} the facet object
8365
8608
  */
8366
- SearchResults.prototype.getFacetByName = function(name) {
8609
+ SearchResults.prototype.getFacetByName = function (name) {
8367
8610
  function predicate(facet) {
8368
8611
  return facet.name === name;
8369
8612
  }
8370
8613
 
8371
- return find$1(this.facets, predicate) ||
8614
+ return (
8615
+ find$1(this.facets, predicate) ||
8372
8616
  find$1(this.disjunctiveFacets, predicate) ||
8373
- find$1(this.hierarchicalFacets, predicate);
8617
+ find$1(this.hierarchicalFacets, predicate)
8618
+ );
8374
8619
  };
8375
8620
 
8376
8621
  /**
@@ -8389,55 +8634,70 @@
8389
8634
  var facet = find$1(results.facets, predicate);
8390
8635
  if (!facet) return [];
8391
8636
 
8392
- return Object.keys(facet.data).map(function(name) {
8637
+ return Object.keys(facet.data).map(function (name) {
8393
8638
  var value = escapeFacetValue$3(name);
8394
8639
  return {
8395
8640
  name: name,
8396
8641
  escapedValue: value,
8397
8642
  count: facet.data[name],
8398
8643
  isRefined: results._state.isFacetRefined(attribute, value),
8399
- isExcluded: results._state.isExcludeRefined(attribute, name)
8644
+ isExcluded: results._state.isExcludeRefined(attribute, name),
8400
8645
  };
8401
8646
  });
8402
8647
  } else if (results._state.isDisjunctiveFacet(attribute)) {
8403
8648
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
8404
8649
  if (!disjunctiveFacet) return [];
8405
8650
 
8406
- return Object.keys(disjunctiveFacet.data).map(function(name) {
8651
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
8407
8652
  var value = escapeFacetValue$3(name);
8408
8653
  return {
8409
8654
  name: name,
8410
8655
  escapedValue: value,
8411
8656
  count: disjunctiveFacet.data[name],
8412
- isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
8657
+ isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
8413
8658
  };
8414
8659
  });
8415
8660
  } else if (results._state.isHierarchicalFacet(attribute)) {
8416
8661
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
8417
8662
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
8418
8663
 
8419
- var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
8420
- var currentRefinementSplit = unescapeFacetValue$3(
8664
+ var hierarchicalFacet =
8665
+ results._state.getHierarchicalFacetByName(attribute);
8666
+ var separator =
8667
+ results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
8668
+ var currentRefinement = unescapeFacetValue$3(
8421
8669
  results._state.getHierarchicalRefinement(attribute)[0] || ''
8422
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
8670
+ );
8671
+
8672
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
8673
+ currentRefinement = currentRefinement.replace(
8674
+ hierarchicalFacet.rootPath + separator,
8675
+ ''
8676
+ );
8677
+ }
8678
+
8679
+ var currentRefinementSplit = currentRefinement.split(separator);
8423
8680
  currentRefinementSplit.unshift(attribute);
8424
8681
 
8425
8682
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
8426
8683
 
8427
8684
  return hierarchicalFacetValues;
8428
8685
  }
8686
+
8687
+ return undefined;
8429
8688
  }
8430
8689
 
8431
8690
  /**
8432
8691
  * Set the isRefined of a hierarchical facet result based on the current state.
8433
8692
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
8434
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
8693
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
8435
8694
  * @param {number} depth recursion depth in the currentRefinement
8695
+ * @return {undefined} function mutates the item
8436
8696
  */
8437
8697
  function setIsRefined(item, currentRefinement, depth) {
8438
8698
  item.isRefined = item.name === currentRefinement[depth];
8439
8699
  if (item.data) {
8440
- item.data.forEach(function(child) {
8700
+ item.data.forEach(function (child) {
8441
8701
  setIsRefined(child, currentRefinement, depth + 1);
8442
8702
  });
8443
8703
  }
@@ -8446,10 +8706,11 @@
8446
8706
  /**
8447
8707
  * Sort nodes of a hierarchical or disjunctive facet results
8448
8708
  * @private
8449
- * @param {function} sortFn
8709
+ * @param {function} sortFn sort function to apply
8450
8710
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
8451
8711
  * @param {string[]} names attribute names
8452
8712
  * @param {number} [level=0] current index in the names array
8713
+ * @return {HierarchicalFacet|Array} sorted node
8453
8714
  */
8454
8715
  function recSort(sortFn, node, names, level) {
8455
8716
  level = level || 0;
@@ -8462,11 +8723,11 @@
8462
8723
  return node;
8463
8724
  }
8464
8725
 
8465
- var children = node.data.map(function(childNode) {
8726
+ var children = node.data.map(function (childNode) {
8466
8727
  return recSort(sortFn, childNode, names, level + 1);
8467
8728
  });
8468
8729
  var sortedChildren = sortFn(children, names[level]);
8469
- var newNode = defaultsPure({data: sortedChildren}, node);
8730
+ var newNode = defaultsPure({ data: sortedChildren }, node);
8470
8731
  return newNode;
8471
8732
  }
8472
8733
 
@@ -8487,7 +8748,7 @@
8487
8748
  * Sorts facet arrays via their facet ordering
8488
8749
  * @param {Array} facetValues the values
8489
8750
  * @param {FacetOrdering} facetOrdering the ordering
8490
- * @returns {Array}
8751
+ * @returns {Array} the sorted facet values
8491
8752
  */
8492
8753
  function sortViaFacetOrdering(facetValues, facetOrdering) {
8493
8754
  var orderedFacets = [];
@@ -8498,12 +8759,12 @@
8498
8759
  * an object with the keys being the values in order, the values their index:
8499
8760
  * ['one', 'two'] -> { one: 0, two: 1 }
8500
8761
  */
8501
- var reverseOrder = order.reduce(function(acc, name, i) {
8762
+ var reverseOrder = order.reduce(function (acc, name, i) {
8502
8763
  acc[name] = i;
8503
8764
  return acc;
8504
8765
  }, {});
8505
8766
 
8506
- facetValues.forEach(function(item) {
8767
+ facetValues.forEach(function (item) {
8507
8768
  // hierarchical facets get sorted using their raw name
8508
8769
  var name = item.path || item.name;
8509
8770
  if (reverseOrder[name] !== undefined) {
@@ -8513,7 +8774,7 @@
8513
8774
  }
8514
8775
  });
8515
8776
 
8516
- orderedFacets = orderedFacets.filter(function(facet) {
8777
+ orderedFacets = orderedFacets.filter(function (facet) {
8517
8778
  return facet;
8518
8779
  });
8519
8780
 
@@ -8522,7 +8783,10 @@
8522
8783
  if (sortRemainingBy === 'hidden') {
8523
8784
  return orderedFacets;
8524
8785
  } else if (sortRemainingBy === 'alpha') {
8525
- ordering = [['path', 'name'], ['asc', 'asc']];
8786
+ ordering = [
8787
+ ['path', 'name'],
8788
+ ['asc', 'asc'],
8789
+ ];
8526
8790
  } else {
8527
8791
  ordering = [['count'], ['desc']];
8528
8792
  }
@@ -8535,7 +8799,7 @@
8535
8799
  /**
8536
8800
  * @param {SearchResults} results the search results class
8537
8801
  * @param {string} attribute the attribute to retrieve ordering of
8538
- * @returns {FacetOrdering=}
8802
+ * @returns {FacetOrdering | undefined} the facet ordering
8539
8803
  */
8540
8804
  function getFacetOrdering(results, attribute) {
8541
8805
  return (
@@ -8594,7 +8858,7 @@
8594
8858
  * });
8595
8859
  * });
8596
8860
  */
8597
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
8861
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
8598
8862
  var facetValues = extractNormalizedFacetValues(this, attribute);
8599
8863
  if (!facetValues) {
8600
8864
  return undefined;
@@ -8604,9 +8868,10 @@
8604
8868
  sortBy: SearchResults.DEFAULT_SORT,
8605
8869
  // if no sortBy is given, attempt to sort based on facetOrdering
8606
8870
  // if it is given, we still allow to sort via facet ordering first
8607
- facetOrdering: !(opts && opts.sortBy)
8871
+ facetOrdering: !(opts && opts.sortBy),
8608
8872
  });
8609
8873
 
8874
+ // eslint-disable-next-line consistent-this
8610
8875
  var results = this;
8611
8876
  var attributes;
8612
8877
  if (Array.isArray(facetValues)) {
@@ -8616,25 +8881,29 @@
8616
8881
  attributes = config.attributes;
8617
8882
  }
8618
8883
 
8619
- return recSort(function(data, facetName) {
8620
- if (options.facetOrdering) {
8621
- var facetOrdering = getFacetOrdering(results, facetName);
8622
- if (Boolean(facetOrdering)) {
8623
- return sortViaFacetOrdering(data, facetOrdering);
8884
+ return recSort(
8885
+ function (data, facetName) {
8886
+ if (options.facetOrdering) {
8887
+ var facetOrdering = getFacetOrdering(results, facetName);
8888
+ if (facetOrdering) {
8889
+ return sortViaFacetOrdering(data, facetOrdering);
8890
+ }
8624
8891
  }
8625
- }
8626
8892
 
8627
- if (Array.isArray(options.sortBy)) {
8628
- var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
8629
- return orderBy_1(data, order[0], order[1]);
8630
- } else if (typeof options.sortBy === 'function') {
8631
- return vanillaSortFn(options.sortBy, data);
8632
- }
8633
- throw new Error(
8634
- 'options.sortBy is optional but if defined it must be ' +
8635
- 'either an array of string (predicates) or a sorting function'
8636
- );
8637
- }, facetValues, attributes);
8893
+ if (Array.isArray(options.sortBy)) {
8894
+ var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
8895
+ return orderBy_1(data, order[0], order[1]);
8896
+ } else if (typeof options.sortBy === 'function') {
8897
+ return vanillaSortFn(options.sortBy, data);
8898
+ }
8899
+ throw new Error(
8900
+ 'options.sortBy is optional but if defined it must be ' +
8901
+ 'either an array of string (predicates) or a sorting function'
8902
+ );
8903
+ },
8904
+ facetValues,
8905
+ attributes
8906
+ );
8638
8907
  };
8639
8908
 
8640
8909
  /**
@@ -8643,7 +8912,7 @@
8643
8912
  * @param {string} attribute name of the faceted attribute
8644
8913
  * @return {object} The stats of the facet
8645
8914
  */
8646
- SearchResults.prototype.getFacetStats = function(attribute) {
8915
+ SearchResults.prototype.getFacetStats = function (attribute) {
8647
8916
  if (this._state.isConjunctiveFacet(attribute)) {
8648
8917
  return getFacetStatsIfAvailable(this.facets, attribute);
8649
8918
  } else if (this._state.isDisjunctiveFacet(attribute)) {
@@ -8660,10 +8929,11 @@
8660
8929
 
8661
8930
  /**
8662
8931
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
8663
- * @param {string} facetName
8932
+ * @param {string} facetName The attribute to look for
8933
+ * @return {object|undefined} The stats of the facet
8664
8934
  */
8665
8935
  function getFacetStatsIfAvailable(facetList, facetName) {
8666
- var data = find$1(facetList, function(facet) {
8936
+ var data = find$1(facetList, function (facet) {
8667
8937
  return facet.name === facetName;
8668
8938
  });
8669
8939
  return data && data.stats;
@@ -8681,53 +8951,76 @@
8681
8951
  *
8682
8952
  * @return {Array.<Refinement>} all the refinements
8683
8953
  */
8684
- SearchResults.prototype.getRefinements = function() {
8954
+ SearchResults.prototype.getRefinements = function () {
8685
8955
  var state = this._state;
8956
+ // eslint-disable-next-line consistent-this
8686
8957
  var results = this;
8687
8958
  var res = [];
8688
8959
 
8689
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
8690
- state.facetsRefinements[attributeName].forEach(function(name) {
8691
- res.push(getRefinement$1(state, 'facet', attributeName, name, results.facets));
8960
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
8961
+ state.facetsRefinements[attributeName].forEach(function (name) {
8962
+ res.push(
8963
+ getRefinement$1(state, 'facet', attributeName, name, results.facets)
8964
+ );
8692
8965
  });
8693
8966
  });
8694
8967
 
8695
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
8696
- state.facetsExcludes[attributeName].forEach(function(name) {
8697
- res.push(getRefinement$1(state, 'exclude', attributeName, name, results.facets));
8968
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
8969
+ state.facetsExcludes[attributeName].forEach(function (name) {
8970
+ res.push(
8971
+ getRefinement$1(state, 'exclude', attributeName, name, results.facets)
8972
+ );
8698
8973
  });
8699
8974
  });
8700
8975
 
8701
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
8702
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
8703
- res.push(getRefinement$1(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
8976
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
8977
+ attributeName
8978
+ ) {
8979
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
8980
+ res.push(
8981
+ getRefinement$1(
8982
+ state,
8983
+ 'disjunctive',
8984
+ attributeName,
8985
+ name,
8986
+ results.disjunctiveFacets
8987
+ )
8988
+ );
8704
8989
  });
8705
8990
  });
8706
8991
 
8707
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
8708
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
8709
- res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
8992
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
8993
+ attributeName
8994
+ ) {
8995
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
8996
+ res.push(
8997
+ getHierarchicalRefinement(
8998
+ state,
8999
+ attributeName,
9000
+ name,
9001
+ results.hierarchicalFacets
9002
+ )
9003
+ );
8710
9004
  });
8711
9005
  });
8712
9006
 
8713
-
8714
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
9007
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
8715
9008
  var operators = state.numericRefinements[attributeName];
8716
- Object.keys(operators).forEach(function(operator) {
8717
- operators[operator].forEach(function(value) {
9009
+ Object.keys(operators).forEach(function (operator) {
9010
+ operators[operator].forEach(function (value) {
8718
9011
  res.push({
8719
9012
  type: 'numeric',
8720
9013
  attributeName: attributeName,
8721
9014
  name: value,
8722
9015
  numericValue: value,
8723
- operator: operator
9016
+ operator: operator,
8724
9017
  });
8725
9018
  });
8726
9019
  });
8727
9020
  });
8728
9021
 
8729
- state.tagRefinements.forEach(function(name) {
8730
- res.push({type: 'tag', attributeName: '_tags', name: name});
9022
+ state.tagRefinements.forEach(function (name) {
9023
+ res.push({ type: 'tag', attributeName: '_tags', name: name });
8731
9024
  });
8732
9025
 
8733
9026
  return res;
@@ -8741,14 +9034,15 @@
8741
9034
  */
8742
9035
 
8743
9036
  /**
8744
- * @param {*} state
8745
- * @param {*} type
8746
- * @param {string} attributeName
8747
- * @param {*} name
8748
- * @param {Facet[]} resultsFacets
9037
+ * @param {SearchParameters} state the current state
9038
+ * @param {string} type the type of the refinement
9039
+ * @param {string} attributeName The attribute of the facet
9040
+ * @param {*} name The name of the facet
9041
+ * @param {Facet[]} resultsFacets facets from the results
9042
+ * @return {Refinement} the refinement
8749
9043
  */
8750
9044
  function getRefinement$1(state, type, attributeName, name, resultsFacets) {
8751
- var facet = find$1(resultsFacets, function(f) {
9045
+ var facet = find$1(resultsFacets, function (f) {
8752
9046
  return f.name === attributeName;
8753
9047
  });
8754
9048
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
@@ -8759,27 +9053,29 @@
8759
9053
  attributeName: attributeName,
8760
9054
  name: name,
8761
9055
  count: count,
8762
- exhaustive: exhaustive
9056
+ exhaustive: exhaustive,
8763
9057
  };
8764
9058
  }
8765
9059
 
8766
9060
  /**
8767
- * @param {*} state
8768
- * @param {string} attributeName
8769
- * @param {*} name
8770
- * @param {Facet[]} resultsFacets
9061
+ * @param {SearchParameters} state the current state
9062
+ * @param {string} attributeName the attribute of the hierarchical facet
9063
+ * @param {string} name the name of the facet
9064
+ * @param {Facet[]} resultsFacets facets from the results
9065
+ * @return {HierarchicalFacet} the hierarchical facet
8771
9066
  */
8772
9067
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
8773
9068
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
8774
9069
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
8775
9070
  var split = name.split(separator);
8776
- var rootFacet = find$1(resultsFacets, function(facet) {
9071
+ var rootFacet = find$1(resultsFacets, function (facet) {
8777
9072
  return facet.name === attributeName;
8778
9073
  });
8779
9074
 
8780
- var facet = split.reduce(function(intermediateFacet, part) {
9075
+ var facet = split.reduce(function (intermediateFacet, part) {
8781
9076
  var newFacet =
8782
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
9077
+ intermediateFacet &&
9078
+ find$1(intermediateFacet.data, function (f) {
8783
9079
  return f.name === part;
8784
9080
  });
8785
9081
  return newFacet !== undefined ? newFacet : intermediateFacet;
@@ -8794,7 +9090,7 @@
8794
9090
  attributeName: attributeName,
8795
9091
  name: path,
8796
9092
  count: count,
8797
- exhaustive: exhaustive
9093
+ exhaustive: exhaustive,
8798
9094
  };
8799
9095
  }
8800
9096
 
@@ -9109,8 +9405,8 @@
9109
9405
  value: ctor,
9110
9406
  enumerable: false,
9111
9407
  writable: true,
9112
- configurable: true
9113
- }
9408
+ configurable: true,
9409
+ },
9114
9410
  });
9115
9411
  }
9116
9412
 
@@ -9125,6 +9421,8 @@
9125
9421
  * - result: when the response is retrieved from Algolia and is processed.
9126
9422
  * This event contains a {@link SearchResults} object and the
9127
9423
  * {@link SearchParameters} corresponding to this answer.
9424
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
9425
+ * @param {function} fn the function to create the derived state
9128
9426
  */
9129
9427
  function DerivedHelper(mainHelper, fn) {
9130
9428
  this.main = mainHelper;
@@ -9139,12 +9437,12 @@
9139
9437
  * @return {undefined}
9140
9438
  * @throws Error if the derived helper is already detached
9141
9439
  */
9142
- DerivedHelper.prototype.detach = function() {
9440
+ DerivedHelper.prototype.detach = function () {
9143
9441
  this.removeAllListeners();
9144
9442
  this.main.detachDerivedHelper(this);
9145
9443
  };
9146
9444
 
9147
- DerivedHelper.prototype.getModifiedState = function(parameters) {
9445
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
9148
9446
  return this.fn(parameters);
9149
9447
  };
9150
9448
 
@@ -9152,10 +9450,10 @@
9152
9450
 
9153
9451
  function sortObject(obj) {
9154
9452
  return Object.keys(obj)
9155
- .sort(function(a, b) {
9453
+ .sort(function (a, b) {
9156
9454
  return a.localeCompare(b);
9157
9455
  })
9158
- .reduce(function(acc, curr) {
9456
+ .reduce(function (acc, curr) {
9159
9457
  acc[curr] = obj[curr];
9160
9458
  return acc;
9161
9459
  }, {});
@@ -9166,6 +9464,8 @@
9166
9464
  * Get all the queries to send to the client, those queries can used directly
9167
9465
  * with the Algolia client.
9168
9466
  * @private
9467
+ * @param {string} index The name of the index
9468
+ * @param {SearchParameters} state The state from which to get the queries
9169
9469
  * @return {object[]} The queries
9170
9470
  */
9171
9471
  _getQueries: function getQueries(index, state) {
@@ -9174,39 +9474,47 @@
9174
9474
  // One query for the hits
9175
9475
  queries.push({
9176
9476
  indexName: index,
9177
- params: requestBuilder._getHitsSearchParams(state)
9477
+ params: requestBuilder._getHitsSearchParams(state),
9178
9478
  });
9179
9479
 
9180
9480
  // One for each disjunctive facets
9181
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
9481
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
9182
9482
  queries.push({
9183
9483
  indexName: index,
9184
- params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
9484
+ params: requestBuilder._getDisjunctiveFacetSearchParams(
9485
+ state,
9486
+ refinedFacet
9487
+ ),
9185
9488
  });
9186
9489
  });
9187
9490
 
9188
9491
  // More to get the parent levels of the hierarchical facets when refined
9189
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
9492
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
9190
9493
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
9191
9494
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
9192
9495
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9193
9496
 
9194
9497
  // If we are deeper than level 0 (starting from `beer > IPA`)
9195
9498
  // we want to get all parent values
9196
- if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
9499
+ if (
9500
+ currentRefinement.length > 0 &&
9501
+ currentRefinement[0].split(separator).length > 1
9502
+ ) {
9197
9503
  // We generate a map of the filters we will use for our facet values queries
9198
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
9199
- function createFiltersMap(map, segment, level) {
9504
+ var filtersMap = currentRefinement[0]
9505
+ .split(separator)
9506
+ .slice(0, -1)
9507
+ .reduce(function createFiltersMap(map, segment, level) {
9200
9508
  return map.concat({
9201
9509
  attribute: hierarchicalFacet.attributes[level],
9202
- value: level === 0
9203
- ? segment
9204
- : [map[map.length - 1].value, segment].join(separator)
9510
+ value:
9511
+ level === 0
9512
+ ? segment
9513
+ : [map[map.length - 1].value, segment].join(separator),
9205
9514
  });
9206
- }
9207
- , []);
9515
+ }, []);
9208
9516
 
9209
- filtersMap.forEach(function(filter, level) {
9517
+ filtersMap.forEach(function (filter, level) {
9210
9518
  var params = requestBuilder._getDisjunctiveFacetSearchParams(
9211
9519
  state,
9212
9520
  filter.attribute,
@@ -9215,37 +9523,48 @@
9215
9523
 
9216
9524
  // Keep facet filters unrelated to current hierarchical attributes
9217
9525
  function hasHierarchicalFacetFilter(value) {
9218
- return hierarchicalFacet.attributes.some(function(attribute) {
9526
+ return hierarchicalFacet.attributes.some(function (attribute) {
9219
9527
  return attribute === value.split(':')[0];
9220
9528
  });
9221
9529
  }
9222
9530
 
9223
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
9224
- if (Array.isArray(facetFilter)) {
9225
- var filtered = facetFilter.filter(function(filterValue) {
9226
- return !hasHierarchicalFacetFilter(filterValue);
9227
- });
9531
+ var filteredFacetFilters = (params.facetFilters || []).reduce(
9532
+ function (acc, facetFilter) {
9533
+ if (Array.isArray(facetFilter)) {
9534
+ var filtered = facetFilter.filter(function (filterValue) {
9535
+ return !hasHierarchicalFacetFilter(filterValue);
9536
+ });
9228
9537
 
9229
- if (filtered.length > 0) {
9230
- acc.push(filtered);
9538
+ if (filtered.length > 0) {
9539
+ acc.push(filtered);
9540
+ }
9231
9541
  }
9232
- }
9233
9542
 
9234
- if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
9235
- acc.push(facetFilter);
9236
- }
9543
+ if (
9544
+ typeof facetFilter === 'string' &&
9545
+ !hasHierarchicalFacetFilter(facetFilter)
9546
+ ) {
9547
+ acc.push(facetFilter);
9548
+ }
9237
9549
 
9238
- return acc;
9239
- }, []);
9550
+ return acc;
9551
+ },
9552
+ []
9553
+ );
9240
9554
 
9241
9555
  var parent = filtersMap[level - 1];
9242
9556
  if (level > 0) {
9243
- params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
9557
+ params.facetFilters = filteredFacetFilters.concat(
9558
+ parent.attribute + ':' + parent.value
9559
+ );
9244
9560
  } else {
9245
- params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
9561
+ params.facetFilters =
9562
+ filteredFacetFilters.length > 0
9563
+ ? filteredFacetFilters
9564
+ : undefined;
9246
9565
  }
9247
9566
 
9248
- queries.push({indexName: index, params: params});
9567
+ queries.push({ indexName: index, params: params });
9249
9568
  });
9250
9569
  }
9251
9570
  });
@@ -9256,20 +9575,20 @@
9256
9575
  /**
9257
9576
  * Build search parameters used to fetch hits
9258
9577
  * @private
9259
- * @return {object.<string, any>}
9578
+ * @param {SearchParameters} state The state from which to get the queries
9579
+ * @return {object.<string, any>} The search parameters for hits
9260
9580
  */
9261
- _getHitsSearchParams: function(state) {
9581
+ _getHitsSearchParams: function (state) {
9262
9582
  var facets = state.facets
9263
9583
  .concat(state.disjunctiveFacets)
9264
9584
  .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
9265
9585
 
9266
-
9267
9586
  var facetFilters = requestBuilder._getFacetFilters(state);
9268
9587
  var numericFilters = requestBuilder._getNumericFilters(state);
9269
9588
  var tagFilters = requestBuilder._getTagFilters(state);
9270
9589
  var additionalParams = {
9271
9590
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
9272
- tagFilters: tagFilters
9591
+ tagFilters: tagFilters,
9273
9592
  };
9274
9593
 
9275
9594
  if (facetFilters.length > 0) {
@@ -9286,19 +9605,28 @@
9286
9605
  /**
9287
9606
  * Build search parameters used to fetch a disjunctive facet
9288
9607
  * @private
9608
+ * @param {SearchParameters} state The state from which to get the queries
9289
9609
  * @param {string} facet the associated facet name
9290
9610
  * @param {boolean} hierarchicalRootLevel ?? FIXME
9291
- * @return {object}
9611
+ * @return {object} The search parameters for a disjunctive facet
9292
9612
  */
9293
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
9294
- var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
9613
+ _getDisjunctiveFacetSearchParams: function (
9614
+ state,
9615
+ facet,
9616
+ hierarchicalRootLevel
9617
+ ) {
9618
+ var facetFilters = requestBuilder._getFacetFilters(
9619
+ state,
9620
+ facet,
9621
+ hierarchicalRootLevel
9622
+ );
9295
9623
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
9296
9624
  var tagFilters = requestBuilder._getTagFilters(state);
9297
9625
  var additionalParams = {
9298
9626
  hitsPerPage: 0,
9299
9627
  page: 0,
9300
9628
  analytics: false,
9301
- clickAnalytics: false
9629
+ clickAnalytics: false,
9302
9630
  };
9303
9631
 
9304
9632
  if (tagFilters.length > 0) {
@@ -9308,11 +9636,12 @@
9308
9636
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
9309
9637
 
9310
9638
  if (hierarchicalFacet) {
9311
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
9312
- state,
9313
- hierarchicalFacet,
9314
- hierarchicalRootLevel
9315
- );
9639
+ additionalParams.facets =
9640
+ requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
9641
+ state,
9642
+ hierarchicalFacet,
9643
+ hierarchicalRootLevel
9644
+ );
9316
9645
  } else {
9317
9646
  additionalParams.facets = facet;
9318
9647
  }
@@ -9331,24 +9660,25 @@
9331
9660
  /**
9332
9661
  * Return the numeric filters in an algolia request fashion
9333
9662
  * @private
9663
+ * @param {SearchParameters} state the state from which to get the filters
9334
9664
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
9335
9665
  * @return {string[]} the numeric filters in the algolia format
9336
9666
  */
9337
- _getNumericFilters: function(state, facetName) {
9667
+ _getNumericFilters: function (state, facetName) {
9338
9668
  if (state.numericFilters) {
9339
9669
  return state.numericFilters;
9340
9670
  }
9341
9671
 
9342
9672
  var numericFilters = [];
9343
9673
 
9344
- Object.keys(state.numericRefinements).forEach(function(attribute) {
9674
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
9345
9675
  var operators = state.numericRefinements[attribute] || {};
9346
- Object.keys(operators).forEach(function(operator) {
9676
+ Object.keys(operators).forEach(function (operator) {
9347
9677
  var values = operators[operator] || [];
9348
9678
  if (facetName !== attribute) {
9349
- values.forEach(function(value) {
9679
+ values.forEach(function (value) {
9350
9680
  if (Array.isArray(value)) {
9351
- var vs = value.map(function(v) {
9681
+ var vs = value.map(function (v) {
9352
9682
  return attribute + operator + v;
9353
9683
  });
9354
9684
  numericFilters.push(vs);
@@ -9364,11 +9694,12 @@
9364
9694
  },
9365
9695
 
9366
9696
  /**
9367
- * Return the tags filters depending
9697
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
9368
9698
  * @private
9369
- * @return {string}
9699
+ * @param {SearchParameters} state the state from which to get the filters
9700
+ * @return {string} Tag filters in a single string
9370
9701
  */
9371
- _getTagFilters: function(state) {
9702
+ _getTagFilters: function (state) {
9372
9703
  if (state.tagFilters) {
9373
9704
  return state.tagFilters;
9374
9705
  }
@@ -9376,50 +9707,52 @@
9376
9707
  return state.tagRefinements.join(',');
9377
9708
  },
9378
9709
 
9379
-
9380
9710
  /**
9381
9711
  * Build facetFilters parameter based on current refinements. The array returned
9382
9712
  * contains strings representing the facet filters in the algolia format.
9383
9713
  * @private
9714
+ * @param {SearchParameters} state The state from which to get the queries
9384
9715
  * @param {string} [facet] if set, the current disjunctive facet
9385
- * @return {array.<string>}
9716
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
9717
+ * @return {array.<string>} The facet filters in the algolia format
9386
9718
  */
9387
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
9719
+ _getFacetFilters: function (state, facet, hierarchicalRootLevel) {
9388
9720
  var facetFilters = [];
9389
9721
 
9390
9722
  var facetsRefinements = state.facetsRefinements || {};
9391
- Object.keys(facetsRefinements).forEach(function(facetName) {
9723
+ Object.keys(facetsRefinements).forEach(function (facetName) {
9392
9724
  var facetValues = facetsRefinements[facetName] || [];
9393
- facetValues.forEach(function(facetValue) {
9725
+ facetValues.forEach(function (facetValue) {
9394
9726
  facetFilters.push(facetName + ':' + facetValue);
9395
9727
  });
9396
9728
  });
9397
9729
 
9398
9730
  var facetsExcludes = state.facetsExcludes || {};
9399
- Object.keys(facetsExcludes).forEach(function(facetName) {
9731
+ Object.keys(facetsExcludes).forEach(function (facetName) {
9400
9732
  var facetValues = facetsExcludes[facetName] || [];
9401
- facetValues.forEach(function(facetValue) {
9733
+ facetValues.forEach(function (facetValue) {
9402
9734
  facetFilters.push(facetName + ':-' + facetValue);
9403
9735
  });
9404
9736
  });
9405
9737
 
9406
9738
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
9407
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
9739
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
9408
9740
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
9409
9741
  if (facetName === facet || !facetValues || facetValues.length === 0) {
9410
9742
  return;
9411
9743
  }
9412
9744
  var orFilters = [];
9413
9745
 
9414
- facetValues.forEach(function(facetValue) {
9746
+ facetValues.forEach(function (facetValue) {
9415
9747
  orFilters.push(facetName + ':' + facetValue);
9416
9748
  });
9417
9749
 
9418
9750
  facetFilters.push(orFilters);
9419
9751
  });
9420
9752
 
9421
- var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
9422
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
9753
+ var hierarchicalFacetsRefinements =
9754
+ state.hierarchicalFacetsRefinements || {};
9755
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
9423
9756
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
9424
9757
  var facetValue = facetValues[0];
9425
9758
 
@@ -9437,8 +9770,13 @@
9437
9770
  if (facet === facetName) {
9438
9771
  // if we are at the root level already, no need to ask for facet values, we get them from
9439
9772
  // the hits query
9440
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
9441
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
9773
+ if (
9774
+ facetValue.indexOf(separator) === -1 ||
9775
+ (!rootPath && hierarchicalRootLevel === true) ||
9776
+ (rootPath &&
9777
+ rootPath.split(separator).length ===
9778
+ facetValue.split(separator).length)
9779
+ ) {
9442
9780
  return;
9443
9781
  }
9444
9782
 
@@ -9465,13 +9803,18 @@
9465
9803
  return facetFilters;
9466
9804
  },
9467
9805
 
9468
- _getHitsHierarchicalFacetsAttributes: function(state) {
9806
+ _getHitsHierarchicalFacetsAttributes: function (state) {
9469
9807
  var out = [];
9470
9808
 
9471
9809
  return state.hierarchicalFacets.reduce(
9472
9810
  // ask for as much levels as there's hierarchical refinements
9473
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
9474
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
9811
+ function getHitsAttributesForHierarchicalFacet(
9812
+ allAttributes,
9813
+ hierarchicalFacet
9814
+ ) {
9815
+ var hierarchicalRefinement = state.getHierarchicalRefinement(
9816
+ hierarchicalFacet.name
9817
+ )[0];
9475
9818
 
9476
9819
  // if no refinement, ask for root level
9477
9820
  if (!hierarchicalRefinement) {
@@ -9484,10 +9827,16 @@
9484
9827
  var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
9485
9828
 
9486
9829
  return allAttributes.concat(newAttributes);
9487
- }, out);
9830
+ },
9831
+ out
9832
+ );
9488
9833
  },
9489
9834
 
9490
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
9835
+ _getDisjunctiveHierarchicalFacetAttribute: function (
9836
+ state,
9837
+ hierarchicalFacet,
9838
+ rootLevel
9839
+ ) {
9491
9840
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9492
9841
  if (rootLevel === true) {
9493
9842
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -9499,7 +9848,8 @@
9499
9848
  return [hierarchicalFacet.attributes[attributeIndex]];
9500
9849
  }
9501
9850
 
9502
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
9851
+ var hierarchicalRefinement =
9852
+ state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
9503
9853
  // if refinement is 'beers > IPA > Flying dog',
9504
9854
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
9505
9855
 
@@ -9507,28 +9857,30 @@
9507
9857
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
9508
9858
  },
9509
9859
 
9510
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
9511
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
9512
- state.clearRefinements(facetName) :
9513
- state;
9860
+ getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
9861
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
9862
+ ? state.clearRefinements(facetName)
9863
+ : state;
9514
9864
  var searchForFacetSearchParameters = {
9515
9865
  facetQuery: query,
9516
- facetName: facetName
9866
+ facetName: facetName,
9517
9867
  };
9518
9868
  if (typeof maxFacetHits === 'number') {
9519
9869
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
9520
9870
  }
9521
- return sortObject(merge_1(
9522
- {},
9523
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
9524
- searchForFacetSearchParameters
9525
- ));
9526
- }
9871
+ return sortObject(
9872
+ merge_1(
9873
+ {},
9874
+ requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
9875
+ searchForFacetSearchParameters
9876
+ )
9877
+ );
9878
+ },
9527
9879
  };
9528
9880
 
9529
9881
  var requestBuilder_1 = requestBuilder;
9530
9882
 
9531
- var version = '3.13.2';
9883
+ var version = '3.13.5';
9532
9884
 
9533
9885
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
9534
9886
 
@@ -9658,19 +10010,19 @@
9658
10010
  * method is called, it triggers a `search` event. The results will
9659
10011
  * be available through the `result` event. If an error occurs, an
9660
10012
  * `error` will be fired instead.
9661
- * @return {AlgoliaSearchHelper}
10013
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9662
10014
  * @fires search
9663
10015
  * @fires result
9664
10016
  * @fires error
9665
10017
  * @chainable
9666
10018
  */
9667
- AlgoliaSearchHelper.prototype.search = function() {
9668
- this._search({onlyWithDerivedHelpers: false});
10019
+ AlgoliaSearchHelper.prototype.search = function () {
10020
+ this._search({ onlyWithDerivedHelpers: false });
9669
10021
  return this;
9670
10022
  };
9671
10023
 
9672
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
9673
- this._search({onlyWithDerivedHelpers: true});
10024
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
10025
+ this._search({ onlyWithDerivedHelpers: true });
9674
10026
  return this;
9675
10027
  };
9676
10028
 
@@ -9679,7 +10031,7 @@
9679
10031
  * for the hits
9680
10032
  * @return {object} Query Parameters
9681
10033
  */
9682
- AlgoliaSearchHelper.prototype.getQuery = function() {
10034
+ AlgoliaSearchHelper.prototype.getQuery = function () {
9683
10035
  var state = this.state;
9684
10036
  return requestBuilder_1._getHitsSearchParams(state);
9685
10037
  };
@@ -9691,7 +10043,7 @@
9691
10043
  * same as a search call before calling searchOnce.
9692
10044
  * @param {object} options can contain all the parameters that can be set to SearchParameters
9693
10045
  * plus the index
9694
- * @param {function} [callback] optional callback executed when the response from the
10046
+ * @param {function} [cb] optional callback executed when the response from the
9695
10047
  * server is back.
9696
10048
  * @return {promise|undefined} if a callback is passed the method returns undefined
9697
10049
  * otherwise it returns a promise containing an object with two keys :
@@ -9720,21 +10072,24 @@
9720
10072
  * // }
9721
10073
  * }
9722
10074
  */
9723
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
9724
- var tempState = !options ? this.state : this.state.setQueryParameters(options);
10075
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
10076
+ var tempState = !options
10077
+ ? this.state
10078
+ : this.state.setQueryParameters(options);
9725
10079
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
10080
+ // eslint-disable-next-line consistent-this
9726
10081
  var self = this;
9727
10082
 
9728
10083
  this._currentNbQueries++;
9729
10084
 
9730
10085
  this.emit('searchOnce', {
9731
- state: tempState
10086
+ state: tempState,
9732
10087
  });
9733
10088
 
9734
10089
  if (cb) {
9735
10090
  this.client
9736
10091
  .search(queries)
9737
- .then(function(content) {
10092
+ .then(function (content) {
9738
10093
  self._currentNbQueries--;
9739
10094
  if (self._currentNbQueries === 0) {
9740
10095
  self.emit('searchQueueEmpty');
@@ -9742,7 +10097,7 @@
9742
10097
 
9743
10098
  cb(null, new SearchResults_1(tempState, content.results), tempState);
9744
10099
  })
9745
- .catch(function(err) {
10100
+ .catch(function (err) {
9746
10101
  self._currentNbQueries--;
9747
10102
  if (self._currentNbQueries === 0) {
9748
10103
  self.emit('searchQueueEmpty');
@@ -9754,22 +10109,25 @@
9754
10109
  return undefined;
9755
10110
  }
9756
10111
 
9757
- return this.client.search(queries).then(function(content) {
9758
- self._currentNbQueries--;
9759
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9760
- return {
9761
- content: new SearchResults_1(tempState, content.results),
9762
- state: tempState,
9763
- _originalResponse: content
9764
- };
9765
- }, function(e) {
9766
- self._currentNbQueries--;
9767
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9768
- throw e;
9769
- });
10112
+ return this.client.search(queries).then(
10113
+ function (content) {
10114
+ self._currentNbQueries--;
10115
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10116
+ return {
10117
+ content: new SearchResults_1(tempState, content.results),
10118
+ state: tempState,
10119
+ _originalResponse: content,
10120
+ };
10121
+ },
10122
+ function (e) {
10123
+ self._currentNbQueries--;
10124
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10125
+ throw e;
10126
+ }
10127
+ );
9770
10128
  };
9771
10129
 
9772
- /**
10130
+ /**
9773
10131
  * Start the search for answers with the parameters set in the state.
9774
10132
  * This method returns a promise.
9775
10133
  * @param {Object} options - the options for answers API call
@@ -9780,7 +10138,8 @@
9780
10138
  * @return {promise} the answer results
9781
10139
  * @deprecated answers is deprecated and will be replaced with new initiatives
9782
10140
  */
9783
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
10141
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
10142
+ // eslint-disable-next-line no-console
9784
10143
  console.warn('[algoliasearch-helper] answers is no longer supported');
9785
10144
  var state = this.state;
9786
10145
  var derivedHelper = this.derivedHelpers[0];
@@ -9791,19 +10150,20 @@
9791
10150
  var data = merge_1(
9792
10151
  {
9793
10152
  attributesForPrediction: options.attributesForPrediction,
9794
- nbHits: options.nbHits
10153
+ nbHits: options.nbHits,
9795
10154
  },
9796
10155
  {
9797
10156
  params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
9798
10157
  'attributesToSnippet',
9799
10158
  'hitsPerPage',
9800
10159
  'restrictSearchableAttributes',
9801
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
9802
- ])
10160
+ 'snippetEllipsisText',
10161
+ ]),
9803
10162
  }
9804
10163
  );
9805
10164
 
9806
- var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
10165
+ var errorMessage =
10166
+ 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
9807
10167
  if (typeof this.client.initIndex !== 'function') {
9808
10168
  throw new Error(errorMessage);
9809
10169
  }
@@ -9848,7 +10208,12 @@
9848
10208
  * it in the generated query.
9849
10209
  * @return {promise.<FacetSearchResult>} the results of the search
9850
10210
  */
9851
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
10211
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
10212
+ facet,
10213
+ query,
10214
+ maxFacetHits,
10215
+ userState
10216
+ ) {
9852
10217
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
9853
10218
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
9854
10219
  if (
@@ -9863,15 +10228,21 @@
9863
10228
 
9864
10229
  var state = this.state.setQueryParameters(userState || {});
9865
10230
  var isDisjunctive = state.isDisjunctiveFacet(facet);
9866
- var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
10231
+ var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
10232
+ facet,
10233
+ query,
10234
+ maxFacetHits,
10235
+ state
10236
+ );
9867
10237
 
9868
10238
  this._currentNbQueries++;
10239
+ // eslint-disable-next-line consistent-this
9869
10240
  var self = this;
9870
10241
  var searchForFacetValuesPromise;
9871
10242
  // newer algoliasearch ^3.27.1 - ~4.0.0
9872
10243
  if (clientHasSFFV) {
9873
10244
  searchForFacetValuesPromise = this.client.searchForFacetValues([
9874
- {indexName: state.index, params: algoliaQuery}
10245
+ { indexName: state.index, params: algoliaQuery },
9875
10246
  ]);
9876
10247
  // algoliasearch < 3.27.1
9877
10248
  } else if (clientHasInitIndex) {
@@ -9888,8 +10259,8 @@
9888
10259
  type: 'facet',
9889
10260
  facet: facet,
9890
10261
  indexName: state.index,
9891
- params: algoliaQuery
9892
- }
10262
+ params: algoliaQuery,
10263
+ },
9893
10264
  ])
9894
10265
  .then(function processResponse(response) {
9895
10266
  return response.results[0];
@@ -9899,28 +10270,31 @@
9899
10270
  this.emit('searchForFacetValues', {
9900
10271
  state: state,
9901
10272
  facet: facet,
9902
- query: query
10273
+ query: query,
9903
10274
  });
9904
10275
 
9905
- return searchForFacetValuesPromise.then(function addIsRefined(content) {
9906
- self._currentNbQueries--;
9907
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10276
+ return searchForFacetValuesPromise.then(
10277
+ function addIsRefined(content) {
10278
+ self._currentNbQueries--;
10279
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9908
10280
 
9909
- content = Array.isArray(content) ? content[0] : content;
10281
+ content = Array.isArray(content) ? content[0] : content;
9910
10282
 
9911
- content.facetHits.forEach(function(f) {
9912
- f.escapedValue = escapeFacetValue$4(f.value);
9913
- f.isRefined = isDisjunctive
9914
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
9915
- : state.isFacetRefined(facet, f.escapedValue);
9916
- });
10283
+ content.facetHits.forEach(function (f) {
10284
+ f.escapedValue = escapeFacetValue$4(f.value);
10285
+ f.isRefined = isDisjunctive
10286
+ ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
10287
+ : state.isFacetRefined(facet, f.escapedValue);
10288
+ });
9917
10289
 
9918
- return content;
9919
- }, function(e) {
9920
- self._currentNbQueries--;
9921
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9922
- throw e;
9923
- });
10290
+ return content;
10291
+ },
10292
+ function (e) {
10293
+ self._currentNbQueries--;
10294
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
10295
+ throw e;
10296
+ }
10297
+ );
9924
10298
  };
9925
10299
 
9926
10300
  /**
@@ -9928,14 +10302,14 @@
9928
10302
  *
9929
10303
  * This method resets the current page to 0.
9930
10304
  * @param {string} q the user query
9931
- * @return {AlgoliaSearchHelper}
10305
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9932
10306
  * @fires change
9933
10307
  * @chainable
9934
10308
  */
9935
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
10309
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
9936
10310
  this._change({
9937
10311
  state: this.state.resetPage().setQuery(q),
9938
- isPageReset: true
10312
+ isPageReset: true,
9939
10313
  });
9940
10314
 
9941
10315
  return this;
@@ -9949,7 +10323,7 @@
9949
10323
  *
9950
10324
  * This method resets the current page to 0.
9951
10325
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
9952
- * @return {AlgoliaSearchHelper}
10326
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9953
10327
  * @fires change
9954
10328
  * @chainable
9955
10329
  * @example
@@ -9964,10 +10338,10 @@
9964
10338
  * return type === 'exclude' && attribute === 'category';
9965
10339
  * }).search();
9966
10340
  */
9967
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
10341
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
9968
10342
  this._change({
9969
10343
  state: this.state.resetPage().clearRefinements(name),
9970
- isPageReset: true
10344
+ isPageReset: true,
9971
10345
  });
9972
10346
 
9973
10347
  return this;
@@ -9977,14 +10351,14 @@
9977
10351
  * Remove all the tag filters.
9978
10352
  *
9979
10353
  * This method resets the current page to 0.
9980
- * @return {AlgoliaSearchHelper}
10354
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9981
10355
  * @fires change
9982
10356
  * @chainable
9983
10357
  */
9984
- AlgoliaSearchHelper.prototype.clearTags = function() {
10358
+ AlgoliaSearchHelper.prototype.clearTags = function () {
9985
10359
  this._change({
9986
10360
  state: this.state.resetPage().clearTags(),
9987
- isPageReset: true
10361
+ isPageReset: true,
9988
10362
  });
9989
10363
 
9990
10364
  return this;
@@ -9997,23 +10371,27 @@
9997
10371
  * This method resets the current page to 0.
9998
10372
  * @param {string} facet the facet to refine
9999
10373
  * @param {string} value the associated value (will be converted to string)
10000
- * @return {AlgoliaSearchHelper}
10374
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10001
10375
  * @fires change
10002
10376
  * @chainable
10003
10377
  */
10004
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
10378
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
10379
+ facet,
10380
+ value
10381
+ ) {
10005
10382
  this._change({
10006
10383
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
10007
- isPageReset: true
10384
+ isPageReset: true,
10008
10385
  });
10009
10386
 
10010
10387
  return this;
10011
10388
  };
10012
10389
 
10390
+ // eslint-disable-next-line valid-jsdoc
10013
10391
  /**
10014
10392
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
10015
10393
  */
10016
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
10394
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
10017
10395
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
10018
10396
  };
10019
10397
 
@@ -10025,15 +10403,18 @@
10025
10403
  * This method resets the current page to 0.
10026
10404
  * @param {string} facet the facet name
10027
10405
  * @param {string} path the hierarchical facet path
10028
- * @return {AlgoliaSearchHelper}
10406
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10029
10407
  * @throws Error if the facet is not defined or if the facet is refined
10030
10408
  * @chainable
10031
10409
  * @fires change
10032
10410
  */
10033
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
10411
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
10412
+ facet,
10413
+ path
10414
+ ) {
10034
10415
  this._change({
10035
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
10036
- isPageReset: true
10416
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
10417
+ isPageReset: true,
10037
10418
  });
10038
10419
 
10039
10420
  return this;
@@ -10047,14 +10428,20 @@
10047
10428
  * @param {string} attribute the attribute on which the numeric filter applies
10048
10429
  * @param {string} operator the operator of the filter
10049
10430
  * @param {number} value the value of the filter
10050
- * @return {AlgoliaSearchHelper}
10431
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10051
10432
  * @fires change
10052
10433
  * @chainable
10053
10434
  */
10054
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
10435
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (
10436
+ attribute,
10437
+ operator,
10438
+ value
10439
+ ) {
10055
10440
  this._change({
10056
- state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
10057
- isPageReset: true
10441
+ state: this.state
10442
+ .resetPage()
10443
+ .addNumericRefinement(attribute, operator, value),
10444
+ isPageReset: true,
10058
10445
  });
10059
10446
 
10060
10447
  return this;
@@ -10067,27 +10454,27 @@
10067
10454
  * This method resets the current page to 0.
10068
10455
  * @param {string} facet the facet to refine
10069
10456
  * @param {string} value the associated value (will be converted to string)
10070
- * @return {AlgoliaSearchHelper}
10457
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10071
10458
  * @fires change
10072
10459
  * @chainable
10073
10460
  */
10074
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
10461
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
10075
10462
  this._change({
10076
10463
  state: this.state.resetPage().addFacetRefinement(facet, value),
10077
- isPageReset: true
10464
+ isPageReset: true,
10078
10465
  });
10079
10466
 
10080
10467
  return this;
10081
10468
  };
10082
10469
 
10470
+ // eslint-disable-next-line valid-jsdoc
10083
10471
  /**
10084
10472
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
10085
10473
  */
10086
- AlgoliaSearchHelper.prototype.addRefine = function() {
10474
+ AlgoliaSearchHelper.prototype.addRefine = function () {
10087
10475
  return this.addFacetRefinement.apply(this, arguments);
10088
10476
  };
10089
10477
 
10090
-
10091
10478
  /**
10092
10479
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
10093
10480
  * filter is already set, it doesn't change the filters.
@@ -10095,23 +10482,24 @@
10095
10482
  * This method resets the current page to 0.
10096
10483
  * @param {string} facet the facet to refine
10097
10484
  * @param {string} value the associated value (will be converted to string)
10098
- * @return {AlgoliaSearchHelper}
10485
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10099
10486
  * @fires change
10100
10487
  * @chainable
10101
10488
  */
10102
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
10489
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
10103
10490
  this._change({
10104
10491
  state: this.state.resetPage().addExcludeRefinement(facet, value),
10105
- isPageReset: true
10492
+ isPageReset: true,
10106
10493
  });
10107
10494
 
10108
10495
  return this;
10109
10496
  };
10110
10497
 
10498
+ // eslint-disable-next-line valid-jsdoc
10111
10499
  /**
10112
10500
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
10113
10501
  */
10114
- AlgoliaSearchHelper.prototype.addExclude = function() {
10502
+ AlgoliaSearchHelper.prototype.addExclude = function () {
10115
10503
  return this.addFacetExclusion.apply(this, arguments);
10116
10504
  };
10117
10505
 
@@ -10121,14 +10509,14 @@
10121
10509
  *
10122
10510
  * This method resets the current page to 0.
10123
10511
  * @param {string} tag the tag to add to the filter
10124
- * @return {AlgoliaSearchHelper}
10512
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10125
10513
  * @fires change
10126
10514
  * @chainable
10127
10515
  */
10128
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
10516
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
10129
10517
  this._change({
10130
10518
  state: this.state.resetPage().addTagRefinement(tag),
10131
- isPageReset: true
10519
+ isPageReset: true,
10132
10520
  });
10133
10521
 
10134
10522
  return this;
@@ -10148,14 +10536,20 @@
10148
10536
  * @param {string} attribute the attribute on which the numeric filter applies
10149
10537
  * @param {string} [operator] the operator of the filter
10150
10538
  * @param {number} [value] the value of the filter
10151
- * @return {AlgoliaSearchHelper}
10539
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10152
10540
  * @fires change
10153
10541
  * @chainable
10154
10542
  */
10155
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
10543
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
10544
+ attribute,
10545
+ operator,
10546
+ value
10547
+ ) {
10156
10548
  this._change({
10157
- state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
10158
- isPageReset: true
10549
+ state: this.state
10550
+ .resetPage()
10551
+ .removeNumericRefinement(attribute, operator, value),
10552
+ isPageReset: true,
10159
10553
  });
10160
10554
 
10161
10555
  return this;
@@ -10171,38 +10565,46 @@
10171
10565
  * This method resets the current page to 0.
10172
10566
  * @param {string} facet the facet to refine
10173
10567
  * @param {string} [value] the associated value
10174
- * @return {AlgoliaSearchHelper}
10568
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10175
10569
  * @fires change
10176
10570
  * @chainable
10177
10571
  */
10178
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
10572
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
10573
+ facet,
10574
+ value
10575
+ ) {
10179
10576
  this._change({
10180
- state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
10181
- isPageReset: true
10577
+ state: this.state
10578
+ .resetPage()
10579
+ .removeDisjunctiveFacetRefinement(facet, value),
10580
+ isPageReset: true,
10182
10581
  });
10183
10582
 
10184
10583
  return this;
10185
10584
  };
10186
10585
 
10586
+ // eslint-disable-next-line valid-jsdoc
10187
10587
  /**
10188
10588
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
10189
10589
  */
10190
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
10590
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
10191
10591
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
10192
10592
  };
10193
10593
 
10194
10594
  /**
10195
10595
  * Removes the refinement set on a hierarchical facet.
10196
10596
  * @param {string} facet the facet name
10197
- * @return {AlgoliaSearchHelper}
10597
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10198
10598
  * @throws Error if the facet is not defined or if the facet is not refined
10199
10599
  * @fires change
10200
10600
  * @chainable
10201
10601
  */
10202
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
10602
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
10603
+ facet
10604
+ ) {
10203
10605
  this._change({
10204
10606
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
10205
- isPageReset: true
10607
+ isPageReset: true,
10206
10608
  });
10207
10609
 
10208
10610
  return this;
@@ -10218,23 +10620,24 @@
10218
10620
  * This method resets the current page to 0.
10219
10621
  * @param {string} facet the facet to refine
10220
10622
  * @param {string} [value] the associated value
10221
- * @return {AlgoliaSearchHelper}
10623
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10222
10624
  * @fires change
10223
10625
  * @chainable
10224
10626
  */
10225
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
10627
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
10226
10628
  this._change({
10227
10629
  state: this.state.resetPage().removeFacetRefinement(facet, value),
10228
- isPageReset: true
10630
+ isPageReset: true,
10229
10631
  });
10230
10632
 
10231
10633
  return this;
10232
10634
  };
10233
10635
 
10636
+ // eslint-disable-next-line valid-jsdoc
10234
10637
  /**
10235
10638
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
10236
10639
  */
10237
- AlgoliaSearchHelper.prototype.removeRefine = function() {
10640
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
10238
10641
  return this.removeFacetRefinement.apply(this, arguments);
10239
10642
  };
10240
10643
 
@@ -10248,23 +10651,24 @@
10248
10651
  * This method resets the current page to 0.
10249
10652
  * @param {string} facet the facet to refine
10250
10653
  * @param {string} [value] the associated value
10251
- * @return {AlgoliaSearchHelper}
10654
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10252
10655
  * @fires change
10253
10656
  * @chainable
10254
10657
  */
10255
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
10658
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
10256
10659
  this._change({
10257
10660
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
10258
- isPageReset: true
10661
+ isPageReset: true,
10259
10662
  });
10260
10663
 
10261
10664
  return this;
10262
10665
  };
10263
10666
 
10667
+ // eslint-disable-next-line valid-jsdoc
10264
10668
  /**
10265
10669
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
10266
10670
  */
10267
- AlgoliaSearchHelper.prototype.removeExclude = function() {
10671
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
10268
10672
  return this.removeFacetExclusion.apply(this, arguments);
10269
10673
  };
10270
10674
 
@@ -10274,14 +10678,14 @@
10274
10678
  *
10275
10679
  * This method resets the current page to 0.
10276
10680
  * @param {string} tag tag to remove from the filter
10277
- * @return {AlgoliaSearchHelper}
10681
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10278
10682
  * @fires change
10279
10683
  * @chainable
10280
10684
  */
10281
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
10685
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
10282
10686
  this._change({
10283
10687
  state: this.state.resetPage().removeTagRefinement(tag),
10284
- isPageReset: true
10688
+ isPageReset: true,
10285
10689
  });
10286
10690
 
10287
10691
  return this;
@@ -10294,23 +10698,24 @@
10294
10698
  * This method resets the current page to 0.
10295
10699
  * @param {string} facet the facet to refine
10296
10700
  * @param {string} value the associated value
10297
- * @return {AlgoliaSearchHelper}
10701
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10298
10702
  * @fires change
10299
10703
  * @chainable
10300
10704
  */
10301
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
10705
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
10302
10706
  this._change({
10303
10707
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
10304
- isPageReset: true
10708
+ isPageReset: true,
10305
10709
  });
10306
10710
 
10307
10711
  return this;
10308
10712
  };
10309
10713
 
10714
+ // eslint-disable-next-line valid-jsdoc
10310
10715
  /**
10311
10716
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
10312
10717
  */
10313
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
10718
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
10314
10719
  return this.toggleFacetExclusion.apply(this, arguments);
10315
10720
  };
10316
10721
 
@@ -10323,13 +10728,13 @@
10323
10728
  * This method resets the current page to 0.
10324
10729
  * @param {string} facet the facet to refine
10325
10730
  * @param {string} value the associated value
10326
- * @return {AlgoliaSearchHelper}
10731
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10327
10732
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
10328
10733
  * @fires change
10329
10734
  * @chainable
10330
10735
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
10331
10736
  */
10332
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
10737
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
10333
10738
  return this.toggleFacetRefinement(facet, value);
10334
10739
  };
10335
10740
 
@@ -10342,24 +10747,25 @@
10342
10747
  * This method resets the current page to 0.
10343
10748
  * @param {string} facet the facet to refine
10344
10749
  * @param {string} value the associated value
10345
- * @return {AlgoliaSearchHelper}
10750
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10346
10751
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
10347
10752
  * @fires change
10348
10753
  * @chainable
10349
10754
  */
10350
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
10755
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
10351
10756
  this._change({
10352
10757
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
10353
- isPageReset: true
10758
+ isPageReset: true,
10354
10759
  });
10355
10760
 
10356
10761
  return this;
10357
10762
  };
10358
10763
 
10764
+ // eslint-disable-next-line valid-jsdoc
10359
10765
  /**
10360
10766
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
10361
10767
  */
10362
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
10768
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
10363
10769
  return this.toggleFacetRefinement.apply(this, arguments);
10364
10770
  };
10365
10771
 
@@ -10369,14 +10775,14 @@
10369
10775
  *
10370
10776
  * This method resets the current page to 0.
10371
10777
  * @param {string} tag tag to remove or add
10372
- * @return {AlgoliaSearchHelper}
10778
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10373
10779
  * @fires change
10374
10780
  * @chainable
10375
10781
  */
10376
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
10782
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
10377
10783
  this._change({
10378
10784
  state: this.state.resetPage().toggleTagRefinement(tag),
10379
- isPageReset: true
10785
+ isPageReset: true,
10380
10786
  });
10381
10787
 
10382
10788
  return this;
@@ -10384,14 +10790,14 @@
10384
10790
 
10385
10791
  /**
10386
10792
  * Increments the page number by one.
10387
- * @return {AlgoliaSearchHelper}
10793
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10388
10794
  * @fires change
10389
10795
  * @chainable
10390
10796
  * @example
10391
10797
  * helper.setPage(0).nextPage().getPage();
10392
10798
  * // returns 1
10393
10799
  */
10394
- AlgoliaSearchHelper.prototype.nextPage = function() {
10800
+ AlgoliaSearchHelper.prototype.nextPage = function () {
10395
10801
  var page = this.state.page || 0;
10396
10802
  return this.setPage(page + 1);
10397
10803
  };
@@ -10399,26 +10805,30 @@
10399
10805
  /**
10400
10806
  * Decrements the page number by one.
10401
10807
  * @fires change
10402
- * @return {AlgoliaSearchHelper}
10808
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10403
10809
  * @chainable
10404
10810
  * @example
10405
10811
  * helper.setPage(1).previousPage().getPage();
10406
10812
  * // returns 0
10407
10813
  */
10408
- AlgoliaSearchHelper.prototype.previousPage = function() {
10814
+ AlgoliaSearchHelper.prototype.previousPage = function () {
10409
10815
  var page = this.state.page || 0;
10410
10816
  return this.setPage(page - 1);
10411
10817
  };
10412
10818
 
10413
10819
  /**
10414
10820
  * @private
10821
+ * @param {number} page The page number
10822
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10823
+ * @chainable
10824
+ * @fires change
10415
10825
  */
10416
10826
  function setCurrentPage(page) {
10417
10827
  if (page < 0) throw new Error('Page requested below 0.');
10418
10828
 
10419
10829
  this._change({
10420
10830
  state: this.state.setPage(page),
10421
- isPageReset: false
10831
+ isPageReset: false,
10422
10832
  });
10423
10833
 
10424
10834
  return this;
@@ -10428,7 +10838,7 @@
10428
10838
  * Change the current page
10429
10839
  * @deprecated
10430
10840
  * @param {number} page The page number
10431
- * @return {AlgoliaSearchHelper}
10841
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10432
10842
  * @fires change
10433
10843
  * @chainable
10434
10844
  */
@@ -10438,7 +10848,7 @@
10438
10848
  * Updates the current page.
10439
10849
  * @function
10440
10850
  * @param {number} page The page number
10441
- * @return {AlgoliaSearchHelper}
10851
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10442
10852
  * @fires change
10443
10853
  * @chainable
10444
10854
  */
@@ -10449,14 +10859,14 @@
10449
10859
  *
10450
10860
  * This method resets the current page to 0.
10451
10861
  * @param {string} name the index name
10452
- * @return {AlgoliaSearchHelper}
10862
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10453
10863
  * @fires change
10454
10864
  * @chainable
10455
10865
  */
10456
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
10866
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
10457
10867
  this._change({
10458
10868
  state: this.state.resetPage().setIndex(name),
10459
- isPageReset: true
10869
+ isPageReset: true,
10460
10870
  });
10461
10871
 
10462
10872
  return this;
@@ -10473,16 +10883,16 @@
10473
10883
  * This method resets the current page to 0.
10474
10884
  * @param {string} parameter name of the parameter to update
10475
10885
  * @param {any} value new value of the parameter
10476
- * @return {AlgoliaSearchHelper}
10886
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10477
10887
  * @fires change
10478
10888
  * @chainable
10479
10889
  * @example
10480
10890
  * helper.setQueryParameter('hitsPerPage', 20).search();
10481
10891
  */
10482
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
10892
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
10483
10893
  this._change({
10484
10894
  state: this.state.resetPage().setQueryParameter(parameter, value),
10485
- isPageReset: true
10895
+ isPageReset: true,
10486
10896
  });
10487
10897
 
10488
10898
  return this;
@@ -10491,14 +10901,14 @@
10491
10901
  /**
10492
10902
  * Set the whole state (warning: will erase previous state)
10493
10903
  * @param {SearchParameters} newState the whole new state
10494
- * @return {AlgoliaSearchHelper}
10904
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10495
10905
  * @fires change
10496
10906
  * @chainable
10497
10907
  */
10498
- AlgoliaSearchHelper.prototype.setState = function(newState) {
10908
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
10499
10909
  this._change({
10500
10910
  state: SearchParameters_1.make(newState),
10501
- isPageReset: false
10911
+ isPageReset: false,
10502
10912
  });
10503
10913
 
10504
10914
  return this;
@@ -10509,7 +10919,7 @@
10509
10919
  * Do not use this method unless you know what you are doing. (see the example
10510
10920
  * for a legit use case)
10511
10921
  * @param {SearchParameters} newState the whole new state
10512
- * @return {AlgoliaSearchHelper}
10922
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10513
10923
  * @example
10514
10924
  * helper.on('change', function(state){
10515
10925
  * // In this function you might want to find a way to store the state in the url/history
@@ -10521,10 +10931,11 @@
10521
10931
  * }
10522
10932
  * @chainable
10523
10933
  */
10524
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
10525
- this.state = new SearchParameters_1(newState);
10526
- return this;
10527
- };
10934
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
10935
+ function (newState) {
10936
+ this.state = new SearchParameters_1(newState);
10937
+ return this;
10938
+ };
10528
10939
 
10529
10940
  /**
10530
10941
  * Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
@@ -10549,7 +10960,7 @@
10549
10960
  * helper.hasRefinements('categories'); // true
10550
10961
  *
10551
10962
  */
10552
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
10963
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
10553
10964
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
10554
10965
  return true;
10555
10966
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -10574,7 +10985,7 @@
10574
10985
  *
10575
10986
  * @param {string} facet name of the attribute for used for faceting
10576
10987
  * @param {string} [value] optional value. If passed will test that this value
10577
- * is filtering the given facet.
10988
+ * is filtering the given facet.
10578
10989
  * @return {boolean} true if refined
10579
10990
  * @example
10580
10991
  * helper.isExcludeRefined('color'); // false
@@ -10587,42 +10998,43 @@
10587
10998
  * helper.isExcludeRefined('color', 'blue') // false
10588
10999
  * helper.isExcludeRefined('color', 'red') // true
10589
11000
  */
10590
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
11001
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
10591
11002
  return this.state.isExcludeRefined(facet, value);
10592
11003
  };
10593
11004
 
11005
+ // eslint-disable-next-line valid-jsdoc
10594
11006
  /**
10595
11007
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
10596
11008
  */
10597
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
11009
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
10598
11010
  return this.state.isDisjunctiveFacetRefined(facet, value);
10599
11011
  };
10600
11012
 
10601
11013
  /**
10602
11014
  * Check if the string is a currently filtering tag.
10603
11015
  * @param {string} tag tag to check
10604
- * @return {boolean}
11016
+ * @return {boolean} true if the tag is currently refined
10605
11017
  */
10606
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
11018
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
10607
11019
  return this.state.isTagRefined(tag);
10608
11020
  };
10609
11021
 
11022
+ // eslint-disable-next-line valid-jsdoc
10610
11023
  /**
10611
11024
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
10612
11025
  */
10613
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
11026
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
10614
11027
  return this.hasTagRefinements.apply(this, arguments);
10615
11028
  };
10616
11029
 
10617
-
10618
11030
  /**
10619
11031
  * Get the name of the currently used index.
10620
- * @return {string}
11032
+ * @return {string} name of the index
10621
11033
  * @example
10622
11034
  * helper.setIndex('highestPrice_products').getIndex();
10623
11035
  * // returns 'highestPrice_products'
10624
11036
  */
10625
- AlgoliaSearchHelper.prototype.getIndex = function() {
11037
+ AlgoliaSearchHelper.prototype.getIndex = function () {
10626
11038
  return this.state.index;
10627
11039
  };
10628
11040
 
@@ -10648,7 +11060,7 @@
10648
11060
  *
10649
11061
  * @return {string[]} The list of tags currently set.
10650
11062
  */
10651
- AlgoliaSearchHelper.prototype.getTags = function() {
11063
+ AlgoliaSearchHelper.prototype.getTags = function () {
10652
11064
  return this.state.tagRefinements;
10653
11065
  };
10654
11066
 
@@ -10696,47 +11108,48 @@
10696
11108
  * // }
10697
11109
  * // ]
10698
11110
  */
10699
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
11111
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
10700
11112
  var refinements = [];
10701
11113
 
10702
11114
  if (this.state.isConjunctiveFacet(facetName)) {
10703
11115
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
10704
11116
 
10705
- conjRefinements.forEach(function(r) {
11117
+ conjRefinements.forEach(function (r) {
10706
11118
  refinements.push({
10707
11119
  value: r,
10708
- type: 'conjunctive'
11120
+ type: 'conjunctive',
10709
11121
  });
10710
11122
  });
10711
11123
 
10712
11124
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
10713
11125
 
10714
- excludeRefinements.forEach(function(r) {
11126
+ excludeRefinements.forEach(function (r) {
10715
11127
  refinements.push({
10716
11128
  value: r,
10717
- type: 'exclude'
11129
+ type: 'exclude',
10718
11130
  });
10719
11131
  });
10720
11132
  } else if (this.state.isDisjunctiveFacet(facetName)) {
10721
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
11133
+ var disjunctiveRefinements =
11134
+ this.state.getDisjunctiveRefinements(facetName);
10722
11135
 
10723
- disjRefinements.forEach(function(r) {
11136
+ disjunctiveRefinements.forEach(function (r) {
10724
11137
  refinements.push({
10725
11138
  value: r,
10726
- type: 'disjunctive'
11139
+ type: 'disjunctive',
10727
11140
  });
10728
11141
  });
10729
11142
  }
10730
11143
 
10731
11144
  var numericRefinements = this.state.getNumericRefinements(facetName);
10732
11145
 
10733
- Object.keys(numericRefinements).forEach(function(operator) {
11146
+ Object.keys(numericRefinements).forEach(function (operator) {
10734
11147
  var value = numericRefinements[operator];
10735
11148
 
10736
11149
  refinements.push({
10737
11150
  value: value,
10738
11151
  operator: operator,
10739
- type: 'numeric'
11152
+ type: 'numeric',
10740
11153
  });
10741
11154
  });
10742
11155
 
@@ -10749,7 +11162,10 @@
10749
11162
  * @param {string} operator operator applied on the refined values
10750
11163
  * @return {Array.<number|number[]>} refined values
10751
11164
  */
10752
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
11165
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (
11166
+ attribute,
11167
+ operator
11168
+ ) {
10753
11169
  return this.state.getNumericRefinement(attribute, operator);
10754
11170
  };
10755
11171
 
@@ -10758,7 +11174,9 @@
10758
11174
  * @param {string} facetName Hierarchical facet name
10759
11175
  * @return {array.<string>} the path as an array of string
10760
11176
  */
10761
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
11177
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
11178
+ facetName
11179
+ ) {
10762
11180
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
10763
11181
  };
10764
11182
 
@@ -10767,12 +11185,14 @@
10767
11185
  /**
10768
11186
  * Perform the underlying queries
10769
11187
  * @private
10770
- * @return {undefined}
11188
+ * @param {object} options options for the query
11189
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
11190
+ * @return {undefined} does not return anything
10771
11191
  * @fires search
10772
11192
  * @fires result
10773
11193
  * @fires error
10774
11194
  */
10775
- AlgoliaSearchHelper.prototype._search = function(options) {
11195
+ AlgoliaSearchHelper.prototype._search = function (options) {
10776
11196
  var state = this.state;
10777
11197
  var states = [];
10778
11198
  var mainQueries = [];
@@ -10783,16 +11203,16 @@
10783
11203
  states.push({
10784
11204
  state: state,
10785
11205
  queriesCount: mainQueries.length,
10786
- helper: this
11206
+ helper: this,
10787
11207
  });
10788
11208
 
10789
11209
  this.emit('search', {
10790
11210
  state: state,
10791
- results: this.lastResults
11211
+ results: this.lastResults,
10792
11212
  });
10793
11213
  }
10794
11214
 
10795
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
11215
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
10796
11216
  var derivedState = derivedHelper.getModifiedState(state);
10797
11217
  var derivedStateQueries = derivedState.index
10798
11218
  ? requestBuilder_1._getQueries(derivedState.index, derivedState)
@@ -10801,12 +11221,12 @@
10801
11221
  states.push({
10802
11222
  state: derivedState,
10803
11223
  queriesCount: derivedStateQueries.length,
10804
- helper: derivedHelper
11224
+ helper: derivedHelper,
10805
11225
  });
10806
11226
 
10807
11227
  derivedHelper.emit('search', {
10808
11228
  state: derivedState,
10809
- results: derivedHelper.lastResults
11229
+ results: derivedHelper.lastResults,
10810
11230
  });
10811
11231
 
10812
11232
  return derivedStateQueries;
@@ -10818,21 +11238,24 @@
10818
11238
  this._currentNbQueries++;
10819
11239
 
10820
11240
  if (!queries.length) {
10821
- return Promise.resolve({results: []}).then(
11241
+ return Promise.resolve({ results: [] }).then(
10822
11242
  this._dispatchAlgoliaResponse.bind(this, states, queryId)
10823
11243
  );
10824
11244
  }
10825
11245
 
10826
11246
  try {
10827
- this.client.search(queries)
11247
+ this.client
11248
+ .search(queries)
10828
11249
  .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
10829
11250
  .catch(this._dispatchAlgoliaError.bind(this, queryId));
10830
11251
  } catch (error) {
10831
11252
  // If we reach this part, we're in an internal error state
10832
11253
  this.emit('error', {
10833
- error: error
11254
+ error: error,
10834
11255
  });
10835
11256
  }
11257
+
11258
+ return undefined;
10836
11259
  };
10837
11260
 
10838
11261
  /**
@@ -10840,28 +11263,31 @@
10840
11263
  * usable object that merge the results of all the batch requests. It will dispatch
10841
11264
  * over the different helper + derived helpers (when there are some).
10842
11265
  * @private
10843
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
10844
- * state state used for to generate the request
11266
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
10845
11267
  * @param {number} queryId id of the current request
10846
11268
  * @param {object} content content of the response
10847
11269
  * @return {undefined}
10848
11270
  */
10849
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
10850
- // FIXME remove the number of outdated queries discarded instead of just one
11271
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
11272
+ states,
11273
+ queryId,
11274
+ content
11275
+ ) {
11276
+ // @TODO remove the number of outdated queries discarded instead of just one
10851
11277
 
10852
11278
  if (queryId < this._lastQueryIdReceived) {
10853
11279
  // Outdated answer
10854
11280
  return;
10855
11281
  }
10856
11282
 
10857
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
11283
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
10858
11284
  this._lastQueryIdReceived = queryId;
10859
11285
 
10860
11286
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
10861
11287
 
10862
11288
  var results = content.results.slice();
10863
11289
 
10864
- states.forEach(function(s) {
11290
+ states.forEach(function (s) {
10865
11291
  var state = s.state;
10866
11292
  var queriesCount = s.queriesCount;
10867
11293
  var helper = s.helper;
@@ -10870,21 +11296,24 @@
10870
11296
  if (!state.index) {
10871
11297
  helper.emit('result', {
10872
11298
  results: null,
10873
- state: state
11299
+ state: state,
10874
11300
  });
10875
11301
  return;
10876
11302
  }
10877
11303
 
10878
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
11304
+ helper.lastResults = new SearchResults_1(state, specificResults);
10879
11305
 
10880
11306
  helper.emit('result', {
10881
- results: formattedResponse,
10882
- state: state
11307
+ results: helper.lastResults,
11308
+ state: state,
10883
11309
  });
10884
11310
  });
10885
11311
  };
10886
11312
 
10887
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
11313
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
11314
+ queryId,
11315
+ error
11316
+ ) {
10888
11317
  if (queryId < this._lastQueryIdReceived) {
10889
11318
  // Outdated answer
10890
11319
  return;
@@ -10894,31 +11323,40 @@
10894
11323
  this._lastQueryIdReceived = queryId;
10895
11324
 
10896
11325
  this.emit('error', {
10897
- error: error
11326
+ error: error,
10898
11327
  });
10899
11328
 
10900
11329
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
10901
11330
  };
10902
11331
 
10903
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
10904
- return query ||
11332
+ AlgoliaSearchHelper.prototype.containsRefinement = function (
11333
+ query,
11334
+ facetFilters,
11335
+ numericFilters,
11336
+ tagFilters
11337
+ ) {
11338
+ return (
11339
+ query ||
10905
11340
  facetFilters.length !== 0 ||
10906
11341
  numericFilters.length !== 0 ||
10907
- tagFilters.length !== 0;
11342
+ tagFilters.length !== 0
11343
+ );
10908
11344
  };
10909
11345
 
10910
11346
  /**
10911
11347
  * Test if there are some disjunctive refinements on the facet
10912
11348
  * @private
10913
11349
  * @param {string} facet the attribute to test
10914
- * @return {boolean}
11350
+ * @return {boolean} true if there are refinements on this attribute
10915
11351
  */
10916
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
10917
- return this.state.disjunctiveRefinements[facet] &&
10918
- this.state.disjunctiveRefinements[facet].length > 0;
11352
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
11353
+ return (
11354
+ this.state.disjunctiveRefinements[facet] &&
11355
+ this.state.disjunctiveRefinements[facet].length > 0
11356
+ );
10919
11357
  };
10920
11358
 
10921
- AlgoliaSearchHelper.prototype._change = function(event) {
11359
+ AlgoliaSearchHelper.prototype._change = function (event) {
10922
11360
  var state = event.state;
10923
11361
  var isPageReset = event.isPageReset;
10924
11362
 
@@ -10928,17 +11366,17 @@
10928
11366
  this.emit('change', {
10929
11367
  state: this.state,
10930
11368
  results: this.lastResults,
10931
- isPageReset: isPageReset
11369
+ isPageReset: isPageReset,
10932
11370
  });
10933
11371
  }
10934
11372
  };
10935
11373
 
10936
11374
  /**
10937
11375
  * Clears the cache of the underlying Algolia client.
10938
- * @return {AlgoliaSearchHelper}
11376
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10939
11377
  */
10940
- AlgoliaSearchHelper.prototype.clearCache = function() {
10941
- this.client.clearCache && this.client.clearCache();
11378
+ AlgoliaSearchHelper.prototype.clearCache = function () {
11379
+ if (this.client.clearCache) this.client.clearCache();
10942
11380
  return this;
10943
11381
  };
10944
11382
 
@@ -10946,9 +11384,9 @@
10946
11384
  * Updates the internal client instance. If the reference of the clients
10947
11385
  * are equal then no update is actually done.
10948
11386
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
10949
- * @return {AlgoliaSearchHelper}
11387
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10950
11388
  */
10951
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
11389
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
10952
11390
  if (this.client === newClient) return this;
10953
11391
 
10954
11392
  if (typeof newClient.addAlgoliaAgent === 'function') {
@@ -10961,9 +11399,9 @@
10961
11399
 
10962
11400
  /**
10963
11401
  * Gets the instance of the currently used client.
10964
- * @return {AlgoliaSearch}
11402
+ * @return {AlgoliaSearch} the currently used client
10965
11403
  */
10966
- AlgoliaSearchHelper.prototype.getClient = function() {
11404
+ AlgoliaSearchHelper.prototype.getClient = function () {
10967
11405
  return this.client;
10968
11406
  };
10969
11407
 
@@ -10984,9 +11422,9 @@
10984
11422
  * and the SearchParameters that is returned by the call of the
10985
11423
  * parameter function.
10986
11424
  * @param {function} fn SearchParameters -> SearchParameters
10987
- * @return {DerivedHelper}
11425
+ * @return {DerivedHelper} a new DerivedHelper
10988
11426
  */
10989
- AlgoliaSearchHelper.prototype.derive = function(fn) {
11427
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
10990
11428
  var derivedHelper = new DerivedHelper_1(this, fn);
10991
11429
  this.derivedHelpers.push(derivedHelper);
10992
11430
  return derivedHelper;
@@ -10996,10 +11434,11 @@
10996
11434
  * This method detaches a derived Helper from the main one. Prefer using the one from the
10997
11435
  * derived helper itself, to remove the event listeners too.
10998
11436
  * @private
10999
- * @return {undefined}
11437
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
11438
+ * @return {undefined} nothing is returned
11000
11439
  * @throws Error
11001
11440
  */
11002
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
11441
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
11003
11442
  var pos = this.derivedHelpers.indexOf(derivedHelper);
11004
11443
  if (pos === -1) throw new Error('Derived helper already detached');
11005
11444
  this.derivedHelpers.splice(pos, 1);
@@ -11009,7 +11448,7 @@
11009
11448
  * This method returns true if there is currently at least one on-going search.
11010
11449
  * @return {boolean} true if there is a search pending
11011
11450
  */
11012
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
11451
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
11013
11452
  return this._currentNbQueries > 0;
11014
11453
  };
11015
11454
 
@@ -11060,7 +11499,7 @@
11060
11499
  * @param {AlgoliaSearch} client an AlgoliaSearch client
11061
11500
  * @param {string} index the name of the index to query
11062
11501
  * @param {SearchParameters|object} opts an object defining the initial config of the search. It doesn't have to be a {SearchParameters}, just an object containing the properties you need from it.
11063
- * @return {AlgoliaSearchHelper}
11502
+ * @return {AlgoliaSearchHelper} The helper instance
11064
11503
  */
11065
11504
  function algoliasearchHelper(client, index, opts) {
11066
11505
  return new algoliasearch_helper(client, index, opts);
@@ -14143,7 +14582,7 @@
14143
14582
  };
14144
14583
  }
14145
14584
 
14146
- var version$1 = '4.56.5';
14585
+ var version$1 = '4.56.7';
14147
14586
 
14148
14587
  var withUsage$r = createDocumentationMessageGenerator({
14149
14588
  name: 'instantsearch'