instantsearch.js 4.56.5 → 4.56.6

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.6 | © 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) :
@@ -5571,45 +5571,32 @@
5571
5571
  };
5572
5572
 
5573
5573
  function clone(value) {
5574
- if (typeof value === 'object' && value !== null) {
5574
+ if (_typeof(value) === 'object' && value !== null) {
5575
5575
  return _merge(Array.isArray(value) ? [] : {}, value);
5576
5576
  }
5577
5577
  return value;
5578
5578
  }
5579
-
5580
5579
  function isObjectOrArrayOrFunction(value) {
5581
- return (
5582
- typeof value === 'function' ||
5583
- Array.isArray(value) ||
5584
- Object.prototype.toString.call(value) === '[object Object]'
5585
- );
5580
+ return typeof value === 'function' || Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
5586
5581
  }
5587
-
5588
5582
  function _merge(target, source) {
5589
5583
  if (target === source) {
5590
5584
  return target;
5591
5585
  }
5592
5586
 
5587
+ // eslint-disable-next-line no-restricted-syntax
5593
5588
  for (var key in source) {
5594
- if (
5595
- !Object.prototype.hasOwnProperty.call(source, key) ||
5596
- key === '__proto__' ||
5597
- key === 'constructor'
5598
- ) {
5589
+ if (!Object.prototype.hasOwnProperty.call(source, key) || key === '__proto__' || key === 'constructor') {
5590
+ // eslint-disable-next-line no-continue
5599
5591
  continue;
5600
5592
  }
5601
-
5602
5593
  var sourceVal = source[key];
5603
5594
  var targetVal = target[key];
5604
-
5605
5595
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
5596
+ // eslint-disable-next-line no-continue
5606
5597
  continue;
5607
5598
  }
5608
-
5609
- if (
5610
- isObjectOrArrayOrFunction(targetVal) &&
5611
- isObjectOrArrayOrFunction(sourceVal)
5612
- ) {
5599
+ if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
5613
5600
  target[key] = _merge(targetVal, sourceVal);
5614
5601
  } else {
5615
5602
  target[key] = clone(sourceVal);
@@ -5629,35 +5616,34 @@
5629
5616
  * - treats sparse arrays as sparse
5630
5617
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
5631
5618
  *
5632
- * @param {Object} object The destination object.
5619
+ * @param {Object} target The destination object.
5633
5620
  * @param {...Object} [sources] The source objects.
5634
5621
  * @returns {Object} Returns `object`.
5635
5622
  */
5636
-
5637
5623
  function merge(target) {
5638
5624
  if (!isObjectOrArrayOrFunction(target)) {
5639
5625
  target = {};
5640
5626
  }
5641
-
5642
5627
  for (var i = 1, l = arguments.length; i < l; i++) {
5643
5628
  var source = arguments[i];
5644
-
5645
5629
  if (isObjectOrArrayOrFunction(source)) {
5646
5630
  _merge(target, source);
5647
5631
  }
5648
5632
  }
5649
5633
  return target;
5650
5634
  }
5635
+ module.exports = merge;
5651
5636
 
5652
- var merge_1 = merge;
5637
+ var merge$1 = /*#__PURE__*/Object.freeze({
5638
+ __proto__: null
5639
+ });
5653
5640
 
5654
5641
  // NOTE: this behaves like lodash/defaults, but doesn't mutate the target
5655
5642
  // it also preserve keys order
5656
5643
  var defaultsPure = function defaultsPure() {
5657
5644
  var sources = Array.prototype.slice.call(arguments);
5658
-
5659
- return sources.reduceRight(function(acc, source) {
5660
- Object.keys(Object(source)).forEach(function(key) {
5645
+ return sources.reduceRight(function (acc, source) {
5646
+ Object.keys(Object(source)).forEach(function (key) {
5661
5647
  if (source[key] === undefined) {
5662
5648
  return;
5663
5649
  }
@@ -5672,11 +5658,8 @@
5672
5658
  };
5673
5659
 
5674
5660
  function intersection(arr1, arr2) {
5675
- return arr1.filter(function(value, index) {
5676
- return (
5677
- arr2.indexOf(value) > -1 &&
5678
- arr1.indexOf(value) === index /* skips duplicates */
5679
- );
5661
+ return arr1.filter(function (value, index) {
5662
+ return arr2.indexOf(value) > -1 && arr1.indexOf(value) === index /* skips duplicates */;
5680
5663
  });
5681
5664
  }
5682
5665
 
@@ -5687,12 +5670,12 @@
5687
5670
  if (!Array.isArray(array)) {
5688
5671
  return undefined;
5689
5672
  }
5690
-
5691
5673
  for (var i = 0; i < array.length; i++) {
5692
5674
  if (comparator(array[i])) {
5693
5675
  return array[i];
5694
5676
  }
5695
5677
  }
5678
+ return undefined;
5696
5679
  };
5697
5680
 
5698
5681
  function valToNumber(v) {
@@ -5703,10 +5686,8 @@
5703
5686
  } else if (Array.isArray(v)) {
5704
5687
  return v.map(valToNumber);
5705
5688
  }
5706
-
5707
5689
  throw new Error('The value should be a number, a parsable string or an array of those.');
5708
5690
  }
5709
-
5710
5691
  var valToNumber_1 = valToNumber;
5711
5692
 
5712
5693
  // https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
@@ -5718,18 +5699,17 @@
5718
5699
  var i;
5719
5700
  for (i = 0; i < sourceKeys.length; i++) {
5720
5701
  key = sourceKeys[i];
5702
+ // eslint-disable-next-line no-continue
5721
5703
  if (excluded.indexOf(key) >= 0) continue;
5722
5704
  target[key] = source[key];
5723
5705
  }
5724
5706
  return target;
5725
5707
  }
5726
-
5727
5708
  var omit$1 = _objectWithoutPropertiesLoose$1;
5728
5709
 
5729
5710
  function objectHasKeys(obj) {
5730
5711
  return obj && Object.keys(obj).length > 0;
5731
5712
  }
5732
-
5733
5713
  var objectHasKeys_1 = objectHasKeys;
5734
5714
 
5735
5715
  var isValidUserToken = function isValidUserToken(userToken) {
@@ -5753,8 +5733,6 @@
5753
5733
 
5754
5734
 
5755
5735
 
5756
-
5757
-
5758
5736
  var lib = {
5759
5737
  /**
5760
5738
  * Adds a refinement to a RefinementList
@@ -5767,17 +5745,10 @@
5767
5745
  if (lib.isRefined(refinementList, attribute, value)) {
5768
5746
  return refinementList;
5769
5747
  }
5770
-
5771
5748
  var valueAsString = '' + value;
5772
-
5773
- var facetRefinement = !refinementList[attribute] ?
5774
- [valueAsString] :
5775
- refinementList[attribute].concat(valueAsString);
5776
-
5749
+ var facetRefinement = !refinementList[attribute] ? [valueAsString] : refinementList[attribute].concat(valueAsString);
5777
5750
  var mod = {};
5778
-
5779
5751
  mod[attribute] = facetRefinement;
5780
-
5781
5752
  return defaultsPure({}, mod, refinementList);
5782
5753
  },
5783
5754
  /**
@@ -5793,14 +5764,12 @@
5793
5764
  if (value === undefined) {
5794
5765
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
5795
5766
  // the form with a string will remove the attribute completely
5796
- return lib.clearRefinement(refinementList, function(v, f) {
5767
+ return lib.clearRefinement(refinementList, function (v, f) {
5797
5768
  return attribute === f;
5798
5769
  });
5799
5770
  }
5800
-
5801
5771
  var valueAsString = '' + value;
5802
-
5803
- return lib.clearRefinement(refinementList, function(v, f) {
5772
+ return lib.clearRefinement(refinementList, function (v, f) {
5804
5773
  return attribute === f && valueAsString === v;
5805
5774
  });
5806
5775
  },
@@ -5813,11 +5782,9 @@
5813
5782
  */
5814
5783
  toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
5815
5784
  if (value === undefined) throw new Error('toggleRefinement should be used with a value');
5816
-
5817
5785
  if (lib.isRefined(refinementList, attribute, value)) {
5818
5786
  return lib.removeRefinement(refinementList, attribute, value);
5819
5787
  }
5820
-
5821
5788
  return lib.addRefinement(refinementList, attribute, value);
5822
5789
  },
5823
5790
  /**
@@ -5833,6 +5800,8 @@
5833
5800
  */
5834
5801
  clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
5835
5802
  if (attribute === undefined) {
5803
+ // return the same object if the list is already empty
5804
+ // this is mainly for tests, as it doesn't have much impact on performance
5836
5805
  if (!objectHasKeys_1(refinementList)) {
5837
5806
  return refinementList;
5838
5807
  }
@@ -5841,24 +5810,24 @@
5841
5810
  return omit$1(refinementList, [attribute]);
5842
5811
  } else if (typeof attribute === 'function') {
5843
5812
  var hasChanged = false;
5844
-
5845
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
5813
+ var newRefinementList = Object.keys(refinementList).reduce(function (memo, key) {
5846
5814
  var values = refinementList[key] || [];
5847
- var facetList = values.filter(function(value) {
5815
+ var facetList = values.filter(function (value) {
5848
5816
  return !attribute(value, key, refinementType);
5849
5817
  });
5850
-
5851
5818
  if (facetList.length !== values.length) {
5852
5819
  hasChanged = true;
5853
5820
  }
5854
5821
  memo[key] = facetList;
5855
-
5856
5822
  return memo;
5857
5823
  }, {});
5858
-
5859
5824
  if (hasChanged) return newRefinementList;
5860
5825
  return refinementList;
5861
5826
  }
5827
+
5828
+ // We return nothing if the attribute is not undefined, a string or a function,
5829
+ // as it is not a valid value for a refinement
5830
+ return undefined;
5862
5831
  },
5863
5832
  /**
5864
5833
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -5867,22 +5836,17 @@
5867
5836
  * @param {RefinementList} refinementList the list of refinement
5868
5837
  * @param {string} attribute name of the attribute
5869
5838
  * @param {string} [refinementValue] value of the filter/refinement
5870
- * @return {boolean}
5839
+ * @return {boolean} true if the attribute is refined, false otherwise
5871
5840
  */
5872
5841
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
5873
- var containsRefinements = !!refinementList[attribute] &&
5874
- refinementList[attribute].length > 0;
5875
-
5842
+ var containsRefinements = Boolean(refinementList[attribute]) && refinementList[attribute].length > 0;
5876
5843
  if (refinementValue === undefined || !containsRefinements) {
5877
5844
  return containsRefinements;
5878
5845
  }
5879
-
5880
5846
  var refinementValueAsString = '' + refinementValue;
5881
-
5882
5847
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
5883
5848
  }
5884
5849
  };
5885
-
5886
5850
  var RefinementList = lib;
5887
5851
 
5888
5852
  /**
@@ -5891,15 +5855,15 @@
5891
5855
  * - [5]
5892
5856
  * - [[5]]
5893
5857
  * - [[5,5],[4]]
5858
+ * @param {any} a numeric refinement value
5859
+ * @param {any} b numeric refinement value
5860
+ * @return {boolean} true if the values are equal
5894
5861
  */
5895
5862
  function isEqualNumericRefinement(a, b) {
5896
5863
  if (Array.isArray(a) && Array.isArray(b)) {
5897
- return (
5898
- a.length === b.length &&
5899
- a.every(function(el, i) {
5900
- return isEqualNumericRefinement(b[i], el);
5901
- })
5902
- );
5864
+ return a.length === b.length && a.every(function (el, i) {
5865
+ return isEqualNumericRefinement(b[i], el);
5866
+ });
5903
5867
  }
5904
5868
  return a === b;
5905
5869
  }
@@ -5913,7 +5877,7 @@
5913
5877
  * @return {any} the searched value or undefined
5914
5878
  */
5915
5879
  function findArray(array, searchedValue) {
5916
- return find$1(array, function(currentValue) {
5880
+ return find$1(array, function (currentValue) {
5917
5881
  return isEqualNumericRefinement(currentValue, searchedValue);
5918
5882
  });
5919
5883
  }
@@ -5967,8 +5931,8 @@
5967
5931
  */
5968
5932
  function SearchParameters(newParameters) {
5969
5933
  var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
5970
-
5971
5934
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
5935
+ // eslint-disable-next-line no-console
5972
5936
  console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
5973
5937
  }
5974
5938
  /**
@@ -6071,11 +6035,11 @@
6071
6035
  */
6072
6036
  this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
6073
6037
 
6038
+ // eslint-disable-next-line consistent-this
6074
6039
  var self = this;
6075
- Object.keys(params).forEach(function(paramName) {
6040
+ Object.keys(params).forEach(function (paramName) {
6076
6041
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
6077
6042
  var isValueDefined = params[paramName] !== undefined;
6078
-
6079
6043
  if (!isKeyKnown && isValueDefined) {
6080
6044
  self[paramName] = params[paramName];
6081
6045
  }
@@ -6094,27 +6058,12 @@
6094
6058
  * @param {object} partialState full or part of a state
6095
6059
  * @return {object} a new object with the number keys as number
6096
6060
  */
6097
- SearchParameters._parseNumbers = function(partialState) {
6098
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
6061
+ SearchParameters._parseNumbers = function (partialState) {
6062
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
6099
6063
  if (partialState instanceof SearchParameters) return partialState;
6100
-
6101
6064
  var numbers = {};
6102
-
6103
- var numberKeys = [
6104
- 'aroundPrecision',
6105
- 'aroundRadius',
6106
- 'getRankingInfo',
6107
- 'minWordSizefor2Typos',
6108
- 'minWordSizefor1Typo',
6109
- 'page',
6110
- 'maxValuesPerFacet',
6111
- 'distinct',
6112
- 'minimumAroundRadius',
6113
- 'hitsPerPage',
6114
- 'minProximity'
6115
- ];
6116
-
6117
- numberKeys.forEach(function(k) {
6065
+ var numberKeys = ['aroundPrecision', 'aroundRadius', 'getRankingInfo', 'minWordSizefor2Typos', 'minWordSizefor1Typo', 'page', 'maxValuesPerFacet', 'distinct', 'minimumAroundRadius', 'hitsPerPage', 'minProximity'];
6066
+ numberKeys.forEach(function (k) {
6118
6067
  var value = partialState[k];
6119
6068
  if (typeof value === 'string') {
6120
6069
  var parsedValue = parseFloat(value);
@@ -6126,26 +6075,25 @@
6126
6075
  // there's two formats of insideBoundingBox, we need to parse
6127
6076
  // the one which is an array of float geo rectangles
6128
6077
  if (Array.isArray(partialState.insideBoundingBox)) {
6129
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
6078
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (geoRect) {
6130
6079
  if (Array.isArray(geoRect)) {
6131
- return geoRect.map(function(value) {
6080
+ return geoRect.map(function (value) {
6132
6081
  return parseFloat(value);
6133
6082
  });
6134
6083
  }
6135
6084
  return geoRect;
6136
6085
  });
6137
6086
  }
6138
-
6139
6087
  if (partialState.numericRefinements) {
6140
6088
  var numericRefinements = {};
6141
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
6089
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
6142
6090
  var operators = partialState.numericRefinements[attribute] || {};
6143
6091
  numericRefinements[attribute] = {};
6144
- Object.keys(operators).forEach(function(operator) {
6092
+ Object.keys(operators).forEach(function (operator) {
6145
6093
  var values = operators[operator];
6146
- var parsedValues = values.map(function(v) {
6094
+ var parsedValues = values.map(function (v) {
6147
6095
  if (Array.isArray(v)) {
6148
- return v.map(function(vPrime) {
6096
+ return v.map(function (vPrime) {
6149
6097
  if (typeof vPrime === 'string') {
6150
6098
  return parseFloat(vPrime);
6151
6099
  }
@@ -6161,8 +6109,7 @@
6161
6109
  });
6162
6110
  numbers.numericRefinements = numericRefinements;
6163
6111
  }
6164
-
6165
- return merge_1({}, partialState, numbers);
6112
+ return merge$1({}, partialState, numbers);
6166
6113
  };
6167
6114
 
6168
6115
  /**
@@ -6173,12 +6120,10 @@
6173
6120
  */
6174
6121
  SearchParameters.make = function makeSearchParameters(newParameters) {
6175
6122
  var instance = new SearchParameters(newParameters);
6176
-
6177
6123
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
6178
- hierarchicalFacets.forEach(function(facet) {
6124
+ hierarchicalFacets.forEach(function (facet) {
6179
6125
  if (facet.rootPath) {
6180
6126
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
6181
-
6182
6127
  if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
6183
6128
  instance = instance.clearRefinements(facet.name);
6184
6129
  }
@@ -6190,7 +6135,6 @@
6190
6135
  }
6191
6136
  }
6192
6137
  });
6193
-
6194
6138
  return instance;
6195
6139
  };
6196
6140
 
@@ -6200,46 +6144,24 @@
6200
6144
  * @param {object|SearchParameters} parameters the new parameters to set
6201
6145
  * @return {Error|null} Error if the modification is invalid, null otherwise
6202
6146
  */
6203
- SearchParameters.validate = function(currentState, parameters) {
6147
+ SearchParameters.validate = function (currentState, parameters) {
6204
6148
  var params = parameters || {};
6205
-
6206
6149
  if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
6207
- return new Error(
6208
- '[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.');
6150
+ return new Error('[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' + 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
6210
6151
  }
6211
-
6212
6152
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
6213
- return new Error(
6214
- '[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.');
6153
+ return new Error('[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' + 'an error, if it is not, you should first clear the tags with clearTags method.');
6216
6154
  }
6217
-
6218
- if (
6219
- currentState.numericFilters &&
6220
- params.numericRefinements &&
6221
- objectHasKeys_1(params.numericRefinements)
6222
- ) {
6223
- return new Error(
6224
- "[Numeric filters] Can't switch from the advanced to the managed API. It" +
6225
- ' is probably an error, if this is really what you want, you have to first' +
6226
- ' clear the numeric filters.'
6227
- );
6155
+ if (currentState.numericFilters && params.numericRefinements && objectHasKeys_1(params.numericRefinements)) {
6156
+ return new Error("[Numeric filters] Can't switch from the advanced to the managed API. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
6228
6157
  }
6229
-
6230
6158
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
6231
- return new Error(
6232
- "[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.');
6159
+ return new Error("[Numeric filters] Can't switch from the managed API to the advanced. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
6235
6160
  }
6236
-
6237
6161
  return null;
6238
6162
  };
6239
-
6240
6163
  SearchParameters.prototype = {
6241
6164
  constructor: SearchParameters,
6242
-
6243
6165
  /**
6244
6166
  * Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
6245
6167
  * @method
@@ -6247,39 +6169,17 @@
6247
6169
  * - If not given, means to clear all the filters.
6248
6170
  * - If `string`, means to clear all refinements for the `attribute` named filter.
6249
6171
  * - If `function`, means to clear all the refinements that return truthy values.
6250
- * @return {SearchParameters}
6172
+ * @return {SearchParameters} new instance with filters cleared
6251
6173
  */
6252
6174
  clearRefinements: function clearRefinements(attribute) {
6253
6175
  var patch = {
6254
6176
  numericRefinements: this._clearNumericRefinements(attribute),
6255
- facetsRefinements: RefinementList.clearRefinement(
6256
- this.facetsRefinements,
6257
- attribute,
6258
- 'conjunctiveFacet'
6259
- ),
6260
- facetsExcludes: RefinementList.clearRefinement(
6261
- this.facetsExcludes,
6262
- attribute,
6263
- 'exclude'
6264
- ),
6265
- disjunctiveFacetsRefinements: RefinementList.clearRefinement(
6266
- this.disjunctiveFacetsRefinements,
6267
- attribute,
6268
- 'disjunctiveFacet'
6269
- ),
6270
- hierarchicalFacetsRefinements: RefinementList.clearRefinement(
6271
- this.hierarchicalFacetsRefinements,
6272
- attribute,
6273
- 'hierarchicalFacet'
6274
- )
6177
+ facetsRefinements: RefinementList.clearRefinement(this.facetsRefinements, attribute, 'conjunctiveFacet'),
6178
+ facetsExcludes: RefinementList.clearRefinement(this.facetsExcludes, attribute, 'exclude'),
6179
+ disjunctiveFacetsRefinements: RefinementList.clearRefinement(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
6180
+ hierarchicalFacetsRefinements: RefinementList.clearRefinement(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
6275
6181
  };
6276
- if (
6277
- patch.numericRefinements === this.numericRefinements &&
6278
- patch.facetsRefinements === this.facetsRefinements &&
6279
- patch.facetsExcludes === this.facetsExcludes &&
6280
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
6281
- patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
6282
- ) {
6182
+ if (patch.numericRefinements === this.numericRefinements && patch.facetsRefinements === this.facetsRefinements && patch.facetsExcludes === this.facetsExcludes && patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements && patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
6283
6183
  return this;
6284
6184
  }
6285
6185
  return this.setQueryParameters(patch);
@@ -6287,11 +6187,10 @@
6287
6187
  /**
6288
6188
  * Remove all the refined tags from the SearchParameters
6289
6189
  * @method
6290
- * @return {SearchParameters}
6190
+ * @return {SearchParameters} new instance with tags cleared
6291
6191
  */
6292
6192
  clearTags: function clearTags() {
6293
6193
  if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
6294
-
6295
6194
  return this.setQueryParameters({
6296
6195
  tagFilters: undefined,
6297
6196
  tagRefinements: []
@@ -6301,11 +6200,10 @@
6301
6200
  * Set the index.
6302
6201
  * @method
6303
6202
  * @param {string} index the index name
6304
- * @return {SearchParameters}
6203
+ * @return {SearchParameters} new instance
6305
6204
  */
6306
6205
  setIndex: function setIndex(index) {
6307
6206
  if (index === this.index) return this;
6308
-
6309
6207
  return this.setQueryParameters({
6310
6208
  index: index
6311
6209
  });
@@ -6314,11 +6212,10 @@
6314
6212
  * Query setter
6315
6213
  * @method
6316
6214
  * @param {string} newQuery value for the new query
6317
- * @return {SearchParameters}
6215
+ * @return {SearchParameters} new instance
6318
6216
  */
6319
6217
  setQuery: function setQuery(newQuery) {
6320
6218
  if (newQuery === this.query) return this;
6321
-
6322
6219
  return this.setQueryParameters({
6323
6220
  query: newQuery
6324
6221
  });
@@ -6327,11 +6224,10 @@
6327
6224
  * Page setter
6328
6225
  * @method
6329
6226
  * @param {number} newPage new page number
6330
- * @return {SearchParameters}
6227
+ * @return {SearchParameters} new instance
6331
6228
  */
6332
6229
  setPage: function setPage(newPage) {
6333
6230
  if (newPage === this.page) return this;
6334
-
6335
6231
  return this.setQueryParameters({
6336
6232
  page: newPage
6337
6233
  });
@@ -6341,7 +6237,7 @@
6341
6237
  * The facets are the simple facets, used for conjunctive (and) faceting.
6342
6238
  * @method
6343
6239
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
6344
- * @return {SearchParameters}
6240
+ * @return {SearchParameters} new instance
6345
6241
  */
6346
6242
  setFacets: function setFacets(facets) {
6347
6243
  return this.setQueryParameters({
@@ -6353,7 +6249,7 @@
6353
6249
  * Change the list of disjunctive (or) facets the helper chan handle.
6354
6250
  * @method
6355
6251
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
6356
- * @return {SearchParameters}
6252
+ * @return {SearchParameters} new instance
6357
6253
  */
6358
6254
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
6359
6255
  return this.setQueryParameters({
@@ -6365,11 +6261,10 @@
6365
6261
  * Hits per page represents the number of hits retrieved for this query
6366
6262
  * @method
6367
6263
  * @param {number} n number of hits retrieved per page of results
6368
- * @return {SearchParameters}
6264
+ * @return {SearchParameters} new instance
6369
6265
  */
6370
6266
  setHitsPerPage: function setHitsPerPage(n) {
6371
6267
  if (this.hitsPerPage === n) return this;
6372
-
6373
6268
  return this.setQueryParameters({
6374
6269
  hitsPerPage: n
6375
6270
  });
@@ -6379,11 +6274,10 @@
6379
6274
  * Set the value of typoTolerance
6380
6275
  * @method
6381
6276
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
6382
- * @return {SearchParameters}
6277
+ * @return {SearchParameters} new instance
6383
6278
  */
6384
6279
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
6385
6280
  if (this.typoTolerance === typoTolerance) return this;
6386
-
6387
6281
  return this.setQueryParameters({
6388
6282
  typoTolerance: typoTolerance
6389
6283
  });
@@ -6396,33 +6290,28 @@
6396
6290
  * @param {string} attribute attribute to set the filter on
6397
6291
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
6398
6292
  * @param {number | number[]} value value of the filter
6399
- * @return {SearchParameters}
6293
+ * @return {SearchParameters} new instance
6400
6294
  * @example
6401
6295
  * // for price = 50 or 40
6402
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
6296
+ * state.addNumericRefinement('price', '=', [50, 40]);
6403
6297
  * @example
6404
6298
  * // for size = 38 and 40
6405
- * searchparameter.addNumericRefinement('size', '=', 38);
6406
- * searchparameter.addNumericRefinement('size', '=', 40);
6299
+ * state.addNumericRefinement('size', '=', 38);
6300
+ * state.addNumericRefinement('size', '=', 40);
6407
6301
  */
6408
- addNumericRefinement: function(attribute, operator, v) {
6409
- var value = valToNumber_1(v);
6410
-
6411
- if (this.isNumericRefined(attribute, operator, value)) return this;
6412
-
6413
- var mod = merge_1({}, this.numericRefinements);
6414
-
6415
- mod[attribute] = merge_1({}, mod[attribute]);
6416
-
6302
+ addNumericRefinement: function addNumericRefinement(attribute, operator, value) {
6303
+ var val = valToNumber_1(value);
6304
+ if (this.isNumericRefined(attribute, operator, val)) return this;
6305
+ var mod = merge$1({}, this.numericRefinements);
6306
+ mod[attribute] = merge$1({}, mod[attribute]);
6417
6307
  if (mod[attribute][operator]) {
6418
6308
  // Array copy
6419
6309
  mod[attribute][operator] = mod[attribute][operator].slice();
6420
6310
  // Add the element. Concat can't be used here because value can be an array.
6421
- mod[attribute][operator].push(value);
6311
+ mod[attribute][operator].push(val);
6422
6312
  } else {
6423
- mod[attribute][operator] = [value];
6313
+ mod[attribute][operator] = [val];
6424
6314
  }
6425
-
6426
6315
  return this.setQueryParameters({
6427
6316
  numericRefinements: mod
6428
6317
  });
@@ -6432,7 +6321,7 @@
6432
6321
  * @param {string} facetName name of the attribute used for faceting
6433
6322
  * @return {string[]} list of refinements
6434
6323
  */
6435
- getConjunctiveRefinements: function(facetName) {
6324
+ getConjunctiveRefinements: function getConjunctiveRefinements(facetName) {
6436
6325
  if (!this.isConjunctiveFacet(facetName)) {
6437
6326
  return [];
6438
6327
  }
@@ -6443,7 +6332,7 @@
6443
6332
  * @param {string} facetName name of the attribute used for faceting
6444
6333
  * @return {string[]} list of refinements
6445
6334
  */
6446
- getDisjunctiveRefinements: function(facetName) {
6335
+ getDisjunctiveRefinements: function getDisjunctiveRefinements(facetName) {
6447
6336
  if (!this.isDisjunctiveFacet(facetName)) {
6448
6337
  return [];
6449
6338
  }
@@ -6454,7 +6343,7 @@
6454
6343
  * @param {string} facetName name of the attribute used for faceting
6455
6344
  * @return {string[]} list of refinements
6456
6345
  */
6457
- getHierarchicalRefinement: function(facetName) {
6346
+ getHierarchicalRefinement: function getHierarchicalRefinement(facetName) {
6458
6347
  // we send an array but we currently do not support multiple
6459
6348
  // hierarchicalRefinements for a hierarchicalFacet
6460
6349
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -6464,47 +6353,42 @@
6464
6353
  * @param {string} facetName name of the attribute used for faceting
6465
6354
  * @return {string[]} list of refinements
6466
6355
  */
6467
- getExcludeRefinements: function(facetName) {
6356
+ getExcludeRefinements: function getExcludeRefinements(facetName) {
6468
6357
  if (!this.isConjunctiveFacet(facetName)) {
6469
6358
  return [];
6470
6359
  }
6471
6360
  return this.facetsExcludes[facetName] || [];
6472
6361
  },
6473
-
6474
6362
  /**
6475
6363
  * Remove all the numeric filter for a given (attribute, operator)
6476
6364
  * @method
6477
6365
  * @param {string} attribute attribute to set the filter on
6478
6366
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
6479
6367
  * @param {number} [number] the value to be removed
6480
- * @return {SearchParameters}
6368
+ * @return {SearchParameters} new instance
6481
6369
  */
6482
- removeNumericRefinement: function(attribute, operator, paramValue) {
6370
+ removeNumericRefinement: function removeNumericRefinement(attribute, operator, number) {
6371
+ var paramValue = number;
6483
6372
  if (paramValue !== undefined) {
6484
6373
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
6485
6374
  return this;
6486
6375
  }
6487
6376
  return this.setQueryParameters({
6488
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6489
- return (
6490
- key === attribute &&
6491
- value.op === operator &&
6492
- isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
6493
- );
6377
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
6378
+ return key === attribute && value.op === operator && isEqualNumericRefinement(value.val, valToNumber_1(paramValue));
6494
6379
  })
6495
6380
  });
6496
6381
  } else if (operator !== undefined) {
6497
6382
  if (!this.isNumericRefined(attribute, operator)) return this;
6498
6383
  return this.setQueryParameters({
6499
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6384
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
6500
6385
  return key === attribute && value.op === operator;
6501
6386
  })
6502
6387
  });
6503
6388
  }
6504
-
6505
6389
  if (!this.isNumericRefined(attribute)) return this;
6506
6390
  return this.setQueryParameters({
6507
- numericRefinements: this._clearNumericRefinements(function(value, key) {
6391
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
6508
6392
  return key === attribute;
6509
6393
  })
6510
6394
  });
@@ -6514,7 +6398,7 @@
6514
6398
  * @param {string} facetName name of the attribute used for faceting
6515
6399
  * @return {SearchParameters.OperatorList} list of refinements
6516
6400
  */
6517
- getNumericRefinements: function(facetName) {
6401
+ getNumericRefinements: function getNumericRefinements(facetName) {
6518
6402
  return this.numericRefinements[facetName] || {};
6519
6403
  },
6520
6404
  /**
@@ -6523,7 +6407,7 @@
6523
6407
  * @param {string} operator operator applied on the refined values
6524
6408
  * @return {Array.<number|number[]>} refined values
6525
6409
  */
6526
- getNumericRefinement: function(attribute, operator) {
6410
+ getNumericRefinement: function getNumericRefinement(attribute, operator) {
6527
6411
  return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
6528
6412
  },
6529
6413
  /**
@@ -6534,7 +6418,7 @@
6534
6418
  * - If not given, means to clear all the filters.
6535
6419
  * - If `string`, means to clear all refinements for the `attribute` named filter.
6536
6420
  * - If `function`, means to clear all the refinements that return truthy values.
6537
- * @return {Object.<string, OperatorList>}
6421
+ * @return {Object.<string, OperatorList>} new numeric refinements
6538
6422
  */
6539
6423
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
6540
6424
  if (attribute === undefined) {
@@ -6547,16 +6431,18 @@
6547
6431
  } else if (typeof attribute === 'function') {
6548
6432
  var hasChanged = false;
6549
6433
  var numericRefinements = this.numericRefinements;
6550
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
6434
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(function (memo, key) {
6551
6435
  var operators = numericRefinements[key];
6552
6436
  var operatorList = {};
6553
-
6554
6437
  operators = operators || {};
6555
- Object.keys(operators).forEach(function(operator) {
6438
+ Object.keys(operators).forEach(function (operator) {
6556
6439
  var values = operators[operator] || [];
6557
6440
  var outValues = [];
6558
- values.forEach(function(value) {
6559
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
6441
+ values.forEach(function (value) {
6442
+ var predicateResult = attribute({
6443
+ val: value,
6444
+ op: operator
6445
+ }, key, 'numeric');
6560
6446
  if (!predicateResult) outValues.push(value);
6561
6447
  });
6562
6448
  if (outValues.length !== values.length) {
@@ -6564,28 +6450,28 @@
6564
6450
  }
6565
6451
  operatorList[operator] = outValues;
6566
6452
  });
6567
-
6568
6453
  memo[key] = operatorList;
6569
-
6570
6454
  return memo;
6571
6455
  }, {});
6572
-
6573
6456
  if (hasChanged) return newNumericRefinements;
6574
6457
  return this.numericRefinements;
6575
6458
  }
6459
+
6460
+ // We return nothing if the attribute is not undefined, a string or a function,
6461
+ // as it is not a valid value for a refinement
6462
+ return undefined;
6576
6463
  },
6577
6464
  /**
6578
6465
  * Add a facet to the facets attribute of the helper configuration, if it
6579
6466
  * isn't already present.
6580
6467
  * @method
6581
6468
  * @param {string} facet facet name to add
6582
- * @return {SearchParameters}
6469
+ * @return {SearchParameters} new instance
6583
6470
  */
6584
6471
  addFacet: function addFacet(facet) {
6585
6472
  if (this.isConjunctiveFacet(facet)) {
6586
6473
  return this;
6587
6474
  }
6588
-
6589
6475
  return this.setQueryParameters({
6590
6476
  facets: this.facets.concat([facet])
6591
6477
  });
@@ -6595,13 +6481,12 @@
6595
6481
  * configuration, if it isn't already present.
6596
6482
  * @method
6597
6483
  * @param {string} facet disjunctive facet name to add
6598
- * @return {SearchParameters}
6484
+ * @return {SearchParameters} new instance
6599
6485
  */
6600
6486
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
6601
6487
  if (this.isDisjunctiveFacet(facet)) {
6602
6488
  return this;
6603
6489
  }
6604
-
6605
6490
  return this.setQueryParameters({
6606
6491
  disjunctiveFacets: this.disjunctiveFacets.concat([facet])
6607
6492
  });
@@ -6611,15 +6496,13 @@
6611
6496
  * configuration.
6612
6497
  * @method
6613
6498
  * @param {object} hierarchicalFacet hierarchical facet to add
6614
- * @return {SearchParameters}
6499
+ * @return {SearchParameters} new instance
6615
6500
  * @throws will throw an error if a hierarchical facet with the same name was already declared
6616
6501
  */
6617
6502
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
6618
6503
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
6619
- throw new Error(
6620
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
6504
+ throw new Error('Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
6621
6505
  }
6622
-
6623
6506
  return this.setQueryParameters({
6624
6507
  hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
6625
6508
  });
@@ -6629,14 +6512,13 @@
6629
6512
  * @method
6630
6513
  * @param {string} facet attribute to apply the faceting on
6631
6514
  * @param {string} value value of the attribute (will be converted to string)
6632
- * @return {SearchParameters}
6515
+ * @return {SearchParameters} new instance
6633
6516
  */
6634
6517
  addFacetRefinement: function addFacetRefinement(facet, value) {
6635
6518
  if (!this.isConjunctiveFacet(facet)) {
6636
6519
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6637
6520
  }
6638
6521
  if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6639
-
6640
6522
  return this.setQueryParameters({
6641
6523
  facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
6642
6524
  });
@@ -6646,14 +6528,13 @@
6646
6528
  * @method
6647
6529
  * @param {string} facet attribute to apply the exclusion on
6648
6530
  * @param {string} value value of the attribute (will be converted to string)
6649
- * @return {SearchParameters}
6531
+ * @return {SearchParameters} new instance
6650
6532
  */
6651
6533
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
6652
6534
  if (!this.isConjunctiveFacet(facet)) {
6653
6535
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6654
6536
  }
6655
6537
  if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6656
-
6657
6538
  return this.setQueryParameters({
6658
6539
  facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
6659
6540
  });
@@ -6663,33 +6544,27 @@
6663
6544
  * @method
6664
6545
  * @param {string} facet attribute to apply the faceting on
6665
6546
  * @param {string} value value of the attribute (will be converted to string)
6666
- * @return {SearchParameters}
6547
+ * @return {SearchParameters} new instance
6667
6548
  */
6668
6549
  addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
6669
6550
  if (!this.isDisjunctiveFacet(facet)) {
6670
- throw new Error(
6671
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6551
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6672
6552
  }
6673
-
6674
6553
  if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6675
-
6676
6554
  return this.setQueryParameters({
6677
- disjunctiveFacetsRefinements: RefinementList.addRefinement(
6678
- this.disjunctiveFacetsRefinements, facet, value)
6555
+ disjunctiveFacetsRefinements: RefinementList.addRefinement(this.disjunctiveFacetsRefinements, facet, value)
6679
6556
  });
6680
6557
  },
6681
6558
  /**
6682
6559
  * addTagRefinement adds a tag to the list used to filter the results
6683
6560
  * @param {string} tag tag to be added
6684
- * @return {SearchParameters}
6561
+ * @return {SearchParameters} new instance
6685
6562
  */
6686
6563
  addTagRefinement: function addTagRefinement(tag) {
6687
6564
  if (this.isTagRefined(tag)) return this;
6688
-
6689
6565
  var modification = {
6690
6566
  tagRefinements: this.tagRefinements.concat(tag)
6691
6567
  };
6692
-
6693
6568
  return this.setQueryParameters(modification);
6694
6569
  },
6695
6570
  /**
@@ -6697,15 +6572,14 @@
6697
6572
  * is present.
6698
6573
  * @method
6699
6574
  * @param {string} facet facet name to remove
6700
- * @return {SearchParameters}
6575
+ * @return {SearchParameters} new instance
6701
6576
  */
6702
6577
  removeFacet: function removeFacet(facet) {
6703
6578
  if (!this.isConjunctiveFacet(facet)) {
6704
6579
  return this;
6705
6580
  }
6706
-
6707
6581
  return this.clearRefinements(facet).setQueryParameters({
6708
- facets: this.facets.filter(function(f) {
6582
+ facets: this.facets.filter(function (f) {
6709
6583
  return f !== facet;
6710
6584
  })
6711
6585
  });
@@ -6715,15 +6589,14 @@
6715
6589
  * helper configuration, if it is present.
6716
6590
  * @method
6717
6591
  * @param {string} facet disjunctive facet name to remove
6718
- * @return {SearchParameters}
6592
+ * @return {SearchParameters} new instance
6719
6593
  */
6720
6594
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
6721
6595
  if (!this.isDisjunctiveFacet(facet)) {
6722
6596
  return this;
6723
6597
  }
6724
-
6725
6598
  return this.clearRefinements(facet).setQueryParameters({
6726
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
6599
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
6727
6600
  return f !== facet;
6728
6601
  })
6729
6602
  });
@@ -6733,15 +6606,14 @@
6733
6606
  * helper configuration, if it is present.
6734
6607
  * @method
6735
6608
  * @param {string} facet hierarchical facet name to remove
6736
- * @return {SearchParameters}
6609
+ * @return {SearchParameters} new instance
6737
6610
  */
6738
6611
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
6739
6612
  if (!this.isHierarchicalFacet(facet)) {
6740
6613
  return this;
6741
6614
  }
6742
-
6743
6615
  return this.clearRefinements(facet).setQueryParameters({
6744
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
6616
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
6745
6617
  return f.name !== facet;
6746
6618
  })
6747
6619
  });
@@ -6753,14 +6625,13 @@
6753
6625
  * @method
6754
6626
  * @param {string} facet name of the attribute used for faceting
6755
6627
  * @param {string} [value] value used to filter
6756
- * @return {SearchParameters}
6628
+ * @return {SearchParameters} new instance
6757
6629
  */
6758
6630
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
6759
6631
  if (!this.isConjunctiveFacet(facet)) {
6760
6632
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6761
6633
  }
6762
6634
  if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
6763
-
6764
6635
  return this.setQueryParameters({
6765
6636
  facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
6766
6637
  });
@@ -6770,14 +6641,13 @@
6770
6641
  * @method
6771
6642
  * @param {string} facet name of the attribute used for faceting
6772
6643
  * @param {string} value value used to filter
6773
- * @return {SearchParameters}
6644
+ * @return {SearchParameters} new instance
6774
6645
  */
6775
6646
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
6776
6647
  if (!this.isConjunctiveFacet(facet)) {
6777
6648
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6778
6649
  }
6779
6650
  if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
6780
-
6781
6651
  return this.setQueryParameters({
6782
6652
  facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
6783
6653
  });
@@ -6787,35 +6657,30 @@
6787
6657
  * @method
6788
6658
  * @param {string} facet name of the attribute used for faceting
6789
6659
  * @param {string} value value used to filter
6790
- * @return {SearchParameters}
6660
+ * @return {SearchParameters} new instance
6791
6661
  */
6792
6662
  removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
6793
6663
  if (!this.isDisjunctiveFacet(facet)) {
6794
- throw new Error(
6795
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6664
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6796
6665
  }
6797
6666
  if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
6798
-
6799
6667
  return this.setQueryParameters({
6800
- disjunctiveFacetsRefinements: RefinementList.removeRefinement(
6801
- this.disjunctiveFacetsRefinements, facet, value)
6668
+ disjunctiveFacetsRefinements: RefinementList.removeRefinement(this.disjunctiveFacetsRefinements, facet, value)
6802
6669
  });
6803
6670
  },
6804
6671
  /**
6805
6672
  * Remove a tag from the list of tag refinements
6806
6673
  * @method
6807
6674
  * @param {string} tag the tag to remove
6808
- * @return {SearchParameters}
6675
+ * @return {SearchParameters} new instance
6809
6676
  */
6810
6677
  removeTagRefinement: function removeTagRefinement(tag) {
6811
6678
  if (!this.isTagRefined(tag)) return this;
6812
-
6813
6679
  var modification = {
6814
- tagRefinements: this.tagRefinements.filter(function(t) {
6680
+ tagRefinements: this.tagRefinements.filter(function (t) {
6815
6681
  return t !== tag;
6816
6682
  })
6817
6683
  };
6818
-
6819
6684
  return this.setQueryParameters(modification);
6820
6685
  },
6821
6686
  /**
@@ -6823,7 +6688,7 @@
6823
6688
  * and hierarchical facets
6824
6689
  * @param {string} facet the facet to refine
6825
6690
  * @param {string} value the associated value
6826
- * @return {SearchParameters}
6691
+ * @return {SearchParameters} new instance
6827
6692
  * @throws will throw an error if the facet is not declared in the settings of the helper
6828
6693
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
6829
6694
  */
@@ -6835,7 +6700,7 @@
6835
6700
  * and hierarchical facets
6836
6701
  * @param {string} facet the facet to refine
6837
6702
  * @param {string} value the associated value
6838
- * @return {SearchParameters}
6703
+ * @return {SearchParameters} new instance
6839
6704
  * @throws will throw an error if the facet is not declared in the settings of the helper
6840
6705
  */
6841
6706
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -6846,22 +6711,19 @@
6846
6711
  } else if (this.isDisjunctiveFacet(facet)) {
6847
6712
  return this.toggleDisjunctiveFacetRefinement(facet, value);
6848
6713
  }
6849
-
6850
- throw new Error('Cannot refine the undeclared facet ' + facet +
6851
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
6714
+ throw new Error('Cannot refine the undeclared facet ' + facet + '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
6852
6715
  },
6853
6716
  /**
6854
6717
  * Switch the refinement applied over a facet/value
6855
6718
  * @method
6856
6719
  * @param {string} facet name of the attribute used for faceting
6857
6720
  * @param {value} value value used for filtering
6858
- * @return {SearchParameters}
6721
+ * @return {SearchParameters} new instance
6859
6722
  */
6860
6723
  toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
6861
6724
  if (!this.isConjunctiveFacet(facet)) {
6862
6725
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6863
6726
  }
6864
-
6865
6727
  return this.setQueryParameters({
6866
6728
  facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
6867
6729
  });
@@ -6871,13 +6733,12 @@
6871
6733
  * @method
6872
6734
  * @param {string} facet name of the attribute used for faceting
6873
6735
  * @param {value} value value used for filtering
6874
- * @return {SearchParameters}
6736
+ * @return {SearchParameters} new instance
6875
6737
  */
6876
6738
  toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
6877
6739
  if (!this.isConjunctiveFacet(facet)) {
6878
6740
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
6879
6741
  }
6880
-
6881
6742
  return this.setQueryParameters({
6882
6743
  facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
6883
6744
  });
@@ -6887,17 +6748,14 @@
6887
6748
  * @method
6888
6749
  * @param {string} facet name of the attribute used for faceting
6889
6750
  * @param {value} value value used for filtering
6890
- * @return {SearchParameters}
6751
+ * @return {SearchParameters} new instance
6891
6752
  */
6892
6753
  toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
6893
6754
  if (!this.isDisjunctiveFacet(facet)) {
6894
- throw new Error(
6895
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6755
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
6896
6756
  }
6897
-
6898
6757
  return this.setQueryParameters({
6899
- disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
6900
- this.disjunctiveFacetsRefinements, facet, value)
6758
+ disjunctiveFacetsRefinements: RefinementList.toggleRefinement(this.disjunctiveFacetsRefinements, facet, value)
6901
6759
  });
6902
6760
  },
6903
6761
  /**
@@ -6905,30 +6763,23 @@
6905
6763
  * @method
6906
6764
  * @param {string} facet name of the attribute used for faceting
6907
6765
  * @param {value} value value used for filtering
6908
- * @return {SearchParameters}
6766
+ * @return {SearchParameters} new instance
6909
6767
  */
6910
6768
  toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
6911
6769
  if (!this.isHierarchicalFacet(facet)) {
6912
- throw new Error(
6913
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
6770
+ throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
6914
6771
  }
6915
-
6916
6772
  var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
6917
-
6918
6773
  var mod = {};
6919
-
6920
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
6921
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
6922
- // remove current refinement:
6923
- // 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
- );
6931
-
6774
+ var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && (
6775
+ // remove current refinement:
6776
+ // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
6777
+ this.hierarchicalFacetsRefinements[facet][0] === value ||
6778
+ // remove a parent refinement of the current refinement:
6779
+ // - refinement was 'beer > IPA > Flying dog'
6780
+ // - call is toggleRefine('beer > IPA')
6781
+ // - refinement should be `beer`
6782
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0);
6932
6783
  if (upOneOrMultipleLevel) {
6933
6784
  if (value.indexOf(separator) === -1) {
6934
6785
  // go back to root level
@@ -6939,12 +6790,10 @@
6939
6790
  } else {
6940
6791
  mod[facet] = [value];
6941
6792
  }
6942
-
6943
6793
  return this.setQueryParameters({
6944
6794
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
6945
6795
  });
6946
6796
  },
6947
-
6948
6797
  /**
6949
6798
  * Adds a refinement on a hierarchical facet.
6950
6799
  * @param {string} facet the facet name
@@ -6952,7 +6801,7 @@
6952
6801
  * @return {SearchParameter} the new state
6953
6802
  * @throws Error if the facet is not defined or if the facet is refined
6954
6803
  */
6955
- addHierarchicalFacetRefinement: function(facet, path) {
6804
+ addHierarchicalFacetRefinement: function addHierarchicalFacetRefinement(facet, path) {
6956
6805
  if (this.isHierarchicalFacetRefined(facet)) {
6957
6806
  throw new Error(facet + ' is already refined.');
6958
6807
  }
@@ -6965,14 +6814,13 @@
6965
6814
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
6966
6815
  });
6967
6816
  },
6968
-
6969
6817
  /**
6970
6818
  * Removes the refinement set on a hierarchical facet.
6971
6819
  * @param {string} facet the facet name
6972
6820
  * @return {SearchParameter} the new state
6973
6821
  * @throws Error if the facet is not defined or if the facet is not refined
6974
6822
  */
6975
- removeHierarchicalFacetRefinement: function(facet) {
6823
+ removeHierarchicalFacetRefinement: function removeHierarchicalFacetRefinement(facet) {
6976
6824
  if (!this.isHierarchicalFacetRefined(facet)) {
6977
6825
  return this;
6978
6826
  }
@@ -6986,40 +6834,39 @@
6986
6834
  * Switch the tag refinement
6987
6835
  * @method
6988
6836
  * @param {string} tag the tag to remove or add
6989
- * @return {SearchParameters}
6837
+ * @return {SearchParameters} new instance
6990
6838
  */
6991
6839
  toggleTagRefinement: function toggleTagRefinement(tag) {
6992
6840
  if (this.isTagRefined(tag)) {
6993
6841
  return this.removeTagRefinement(tag);
6994
6842
  }
6995
-
6996
6843
  return this.addTagRefinement(tag);
6997
6844
  },
6998
6845
  /**
6999
6846
  * Test if the facet name is from one of the disjunctive facets
7000
6847
  * @method
7001
6848
  * @param {string} facet facet name to test
7002
- * @return {boolean}
6849
+ * @return {boolean} true if facet is a disjunctive facet
7003
6850
  */
7004
- isDisjunctiveFacet: function(facet) {
6851
+ isDisjunctiveFacet: function isDisjunctiveFacet(facet) {
7005
6852
  return this.disjunctiveFacets.indexOf(facet) > -1;
7006
6853
  },
7007
6854
  /**
7008
6855
  * Test if the facet name is from one of the hierarchical facets
7009
6856
  * @method
7010
6857
  * @param {string} facetName facet name to test
7011
- * @return {boolean}
6858
+ * @return {boolean} true if facetName is a hierarchical facet
7012
6859
  */
7013
- isHierarchicalFacet: function(facetName) {
6860
+ isHierarchicalFacet: function isHierarchicalFacet(facetName) {
7014
6861
  return this.getHierarchicalFacetByName(facetName) !== undefined;
7015
6862
  },
7016
6863
  /**
7017
6864
  * Test if the facet name is from one of the conjunctive/normal facets
7018
6865
  * @method
7019
6866
  * @param {string} facet facet name to test
7020
- * @return {boolean}
6867
+ * @return {boolean} true if facet is a conjunctive facet
7021
6868
  */
7022
- isConjunctiveFacet: function(facet) {
6869
+ isConjunctiveFacet: function isConjunctiveFacet(facet) {
7023
6870
  return this.facets.indexOf(facet) > -1;
7024
6871
  },
7025
6872
  /**
@@ -7060,7 +6907,7 @@
7060
6907
  * @param {string} facet name of the attribute for used for faceting
7061
6908
  * @param {string} value optional, will test if the value is used for refinement
7062
6909
  * if there is one, otherwise will test if the facet contains any refinement
7063
- * @return {boolean}
6910
+ * @return {boolean} true if the facet is refined
7064
6911
  */
7065
6912
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
7066
6913
  if (!this.isDisjunctiveFacet(facet)) {
@@ -7075,19 +6922,16 @@
7075
6922
  * @param {string} facet name of the attribute for used for faceting
7076
6923
  * @param {string} value optional, will test if the value is used for refinement
7077
6924
  * if there is one, otherwise will test if the facet contains any refinement
7078
- * @return {boolean}
6925
+ * @return {boolean} true if the facet is refined
7079
6926
  */
7080
6927
  isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
7081
6928
  if (!this.isHierarchicalFacet(facet)) {
7082
6929
  return false;
7083
6930
  }
7084
-
7085
6931
  var refinements = this.getHierarchicalRefinement(facet);
7086
-
7087
6932
  if (!value) {
7088
6933
  return refinements.length > 0;
7089
6934
  }
7090
-
7091
6935
  return refinements.indexOf(value) !== -1;
7092
6936
  },
7093
6937
  /**
@@ -7102,29 +6946,21 @@
7102
6946
  */
7103
6947
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
7104
6948
  if (value === undefined && operator === undefined) {
7105
- return !!this.numericRefinements[attribute];
6949
+ return Boolean(this.numericRefinements[attribute]);
7106
6950
  }
7107
-
7108
- var isOperatorDefined =
7109
- this.numericRefinements[attribute] &&
7110
- this.numericRefinements[attribute][operator] !== undefined;
7111
-
6951
+ var isOperatorDefined = this.numericRefinements[attribute] && this.numericRefinements[attribute][operator] !== undefined;
7112
6952
  if (value === undefined || !isOperatorDefined) {
7113
6953
  return isOperatorDefined;
7114
6954
  }
7115
-
7116
6955
  var parsedValue = valToNumber_1(value);
7117
- var isAttributeValueDefined =
7118
- findArray(this.numericRefinements[attribute][operator], parsedValue) !==
7119
- undefined;
7120
-
6956
+ var isAttributeValueDefined = findArray(this.numericRefinements[attribute][operator], parsedValue) !== undefined;
7121
6957
  return isOperatorDefined && isAttributeValueDefined;
7122
6958
  },
7123
6959
  /**
7124
6960
  * Returns true if the tag refined, false otherwise
7125
6961
  * @method
7126
6962
  * @param {string} tag the tag to check
7127
- * @return {boolean}
6963
+ * @return {boolean} true if tag is refined
7128
6964
  */
7129
6965
  isTagRefined: function isTagRefined(tag) {
7130
6966
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -7134,83 +6970,63 @@
7134
6970
  * @method
7135
6971
  * @param {string} facet name of the attribute used for faceting
7136
6972
  * @param {value} value value used for filtering
7137
- * @return {string[]}
6973
+ * @return {string[]} returns the list of refinements
7138
6974
  */
7139
6975
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
6976
+ // eslint-disable-next-line consistent-this
7140
6977
  var self = this;
7141
6978
 
7142
6979
  // attributes used for numeric filter can also be disjunctive
7143
- var disjunctiveNumericRefinedFacets = intersection_1(
7144
- Object.keys(this.numericRefinements).filter(function(facet) {
7145
- return Object.keys(self.numericRefinements[facet]).length > 0;
7146
- }),
7147
- this.disjunctiveFacets
7148
- );
7149
-
7150
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
6980
+ var disjunctiveNumericRefinedFacets = intersection_1(Object.keys(this.numericRefinements).filter(function (facet) {
6981
+ return Object.keys(self.numericRefinements[facet]).length > 0;
6982
+ }), this.disjunctiveFacets);
6983
+ return Object.keys(this.disjunctiveFacetsRefinements).filter(function (facet) {
7151
6984
  return self.disjunctiveFacetsRefinements[facet].length > 0;
7152
- })
7153
- .concat(disjunctiveNumericRefinedFacets)
7154
- .concat(this.getRefinedHierarchicalFacets());
6985
+ }).concat(disjunctiveNumericRefinedFacets).concat(this.getRefinedHierarchicalFacets());
7155
6986
  },
7156
6987
  /**
7157
6988
  * Returns the list of all disjunctive facets refined
7158
6989
  * @method
7159
6990
  * @param {string} facet name of the attribute used for faceting
7160
6991
  * @param {value} value value used for filtering
7161
- * @return {string[]}
6992
+ * @return {string[]} returns the list of refinements
7162
6993
  */
7163
6994
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
6995
+ // eslint-disable-next-line consistent-this
7164
6996
  var self = this;
7165
6997
  return intersection_1(
7166
- // enforce the order between the two arrays,
7167
- // 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) {
7170
- return self.hierarchicalFacetsRefinements[facet].length > 0;
7171
- })
7172
- );
6998
+ // enforce the order between the two arrays,
6999
+ // so that refinement name index === hierarchical facet index
7000
+ this.hierarchicalFacets.map(function (facet) {
7001
+ return facet.name;
7002
+ }), Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
7003
+ return self.hierarchicalFacetsRefinements[facet].length > 0;
7004
+ }));
7173
7005
  },
7174
7006
  /**
7175
7007
  * Returned the list of all disjunctive facets not refined
7176
7008
  * @method
7177
- * @return {string[]}
7009
+ * @return {string[]} returns the list of facets that are not refined
7178
7010
  */
7179
- getUnrefinedDisjunctiveFacets: function() {
7011
+ getUnrefinedDisjunctiveFacets: function getUnrefinedDisjunctiveFacets() {
7180
7012
  var refinedFacets = this.getRefinedDisjunctiveFacets();
7181
-
7182
- return this.disjunctiveFacets.filter(function(f) {
7013
+ return this.disjunctiveFacets.filter(function (f) {
7183
7014
  return refinedFacets.indexOf(f) === -1;
7184
7015
  });
7185
7016
  },
7186
-
7187
- managedParameters: [
7188
- 'index',
7189
-
7190
- 'facets',
7191
- 'disjunctiveFacets',
7192
- 'facetsRefinements',
7193
- 'hierarchicalFacets',
7194
- 'facetsExcludes',
7195
-
7196
- 'disjunctiveFacetsRefinements',
7197
- 'numericRefinements',
7198
- 'tagRefinements',
7199
- 'hierarchicalFacetsRefinements'
7200
- ],
7017
+ managedParameters: ['index', 'facets', 'disjunctiveFacets', 'facetsRefinements', 'hierarchicalFacets', 'facetsExcludes', 'disjunctiveFacetsRefinements', 'numericRefinements', 'tagRefinements', 'hierarchicalFacetsRefinements'],
7201
7018
  getQueryParams: function getQueryParams() {
7202
7019
  var managedParameters = this.managedParameters;
7203
-
7204
7020
  var queryParams = {};
7205
7021
 
7022
+ // eslint-disable-next-line consistent-this
7206
7023
  var self = this;
7207
- Object.keys(this).forEach(function(paramName) {
7024
+ Object.keys(this).forEach(function (paramName) {
7208
7025
  var paramValue = self[paramName];
7209
7026
  if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
7210
7027
  queryParams[paramName] = paramValue;
7211
7028
  }
7212
7029
  });
7213
-
7214
7030
  return queryParams;
7215
7031
  },
7216
7032
  /**
@@ -7225,11 +7041,8 @@
7225
7041
  */
7226
7042
  setQueryParameter: function setParameter(parameter, value) {
7227
7043
  if (this[parameter] === value) return this;
7228
-
7229
7044
  var modification = {};
7230
-
7231
7045
  modification[parameter] = value;
7232
-
7233
7046
  return this.setQueryParameters(modification);
7234
7047
  },
7235
7048
  /**
@@ -7240,134 +7053,109 @@
7240
7053
  */
7241
7054
  setQueryParameters: function setQueryParameters(params) {
7242
7055
  if (!params) return this;
7243
-
7244
7056
  var error = SearchParameters.validate(this, params);
7245
-
7246
7057
  if (error) {
7247
7058
  throw error;
7248
7059
  }
7249
7060
 
7061
+ // eslint-disable-next-line consistent-this
7250
7062
  var self = this;
7251
7063
  var nextWithNumbers = SearchParameters._parseNumbers(params);
7252
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
7064
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
7253
7065
  acc[key] = self[key];
7254
7066
  return acc;
7255
7067
  }, {});
7256
-
7257
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
7258
- function(previous, key) {
7259
- var isPreviousValueDefined = previous[key] !== undefined;
7260
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
7261
-
7262
- if (isPreviousValueDefined && !isNextValueDefined) {
7263
- return omit$1(previous, [key]);
7264
- }
7265
-
7266
- if (isNextValueDefined) {
7267
- previous[key] = nextWithNumbers[key];
7268
- }
7269
-
7270
- return previous;
7271
- },
7272
- previousPlainObject
7273
- );
7274
-
7068
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (previous, key) {
7069
+ var isPreviousValueDefined = previous[key] !== undefined;
7070
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
7071
+ if (isPreviousValueDefined && !isNextValueDefined) {
7072
+ return omit$1(previous, [key]);
7073
+ }
7074
+ if (isNextValueDefined) {
7075
+ previous[key] = nextWithNumbers[key];
7076
+ }
7077
+ return previous;
7078
+ }, previousPlainObject);
7275
7079
  return new this.constructor(nextPlainObject);
7276
7080
  },
7277
-
7278
7081
  /**
7279
7082
  * Returns a new instance with the page reset. Two scenarios possible:
7280
7083
  * the page is omitted -> return the given instance
7281
7084
  * the page is set -> return a new instance with a page of 0
7282
7085
  * @return {SearchParameters} a new updated instance
7283
7086
  */
7284
- resetPage: function() {
7087
+ resetPage: function resetPage() {
7285
7088
  if (this.page === undefined) {
7286
7089
  return this;
7287
7090
  }
7288
-
7289
7091
  return this.setPage(0);
7290
7092
  },
7291
-
7292
7093
  /**
7293
7094
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7294
- * @param {object} hierarchicalFacet
7095
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7295
7096
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7296
7097
  */
7297
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
7098
+ _getHierarchicalFacetSortBy: function _getHierarchicalFacetSortBy(hierarchicalFacet) {
7298
7099
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
7299
7100
  },
7300
-
7301
7101
  /**
7302
7102
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
7303
7103
  * @private
7304
- * @param {object} hierarchicalFacet
7104
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7305
7105
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
7306
7106
  */
7307
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
7107
+ _getHierarchicalFacetSeparator: function _getHierarchicalFacetSeparator(hierarchicalFacet) {
7308
7108
  return hierarchicalFacet.separator || ' > ';
7309
7109
  },
7310
-
7311
7110
  /**
7312
7111
  * Helper function to get the hierarchicalFacet prefix path or null
7313
7112
  * @private
7314
- * @param {object} hierarchicalFacet
7113
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7315
7114
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
7316
7115
  */
7317
- _getHierarchicalRootPath: function(hierarchicalFacet) {
7116
+ _getHierarchicalRootPath: function _getHierarchicalRootPath(hierarchicalFacet) {
7318
7117
  return hierarchicalFacet.rootPath || null;
7319
7118
  },
7320
-
7321
7119
  /**
7322
7120
  * Helper function to check if we show the parent level of the hierarchicalFacet
7323
7121
  * @private
7324
- * @param {object} hierarchicalFacet
7122
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
7325
7123
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
7326
7124
  */
7327
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
7125
+ _getHierarchicalShowParentLevel: function _getHierarchicalShowParentLevel(hierarchicalFacet) {
7328
7126
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
7329
7127
  return hierarchicalFacet.showParentLevel;
7330
7128
  }
7331
7129
  return true;
7332
7130
  },
7333
-
7334
7131
  /**
7335
7132
  * Helper function to get the hierarchicalFacet by it's name
7336
- * @param {string} hierarchicalFacetName
7133
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
7337
7134
  * @return {object} a hierarchicalFacet
7338
7135
  */
7339
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
7340
- return find$1(
7341
- this.hierarchicalFacets,
7342
- function(f) {
7343
- return f.name === hierarchicalFacetName;
7344
- }
7345
- );
7136
+ getHierarchicalFacetByName: function getHierarchicalFacetByName(hierarchicalFacetName) {
7137
+ return find$1(this.hierarchicalFacets, function (f) {
7138
+ return f.name === hierarchicalFacetName;
7139
+ });
7346
7140
  },
7347
-
7348
7141
  /**
7349
7142
  * Get the current breadcrumb for a hierarchical facet, as an array
7350
7143
  * @param {string} facetName Hierarchical facet name
7351
7144
  * @return {array.<string>} the path as an array of string
7352
7145
  */
7353
- getHierarchicalFacetBreadcrumb: function(facetName) {
7146
+ getHierarchicalFacetBreadcrumb: function getHierarchicalFacetBreadcrumb(facetName) {
7354
7147
  if (!this.isHierarchicalFacet(facetName)) {
7355
7148
  return [];
7356
7149
  }
7357
-
7358
7150
  var refinement = this.getHierarchicalRefinement(facetName)[0];
7359
7151
  if (!refinement) return [];
7360
-
7361
- var separator = this._getHierarchicalFacetSeparator(
7362
- this.getHierarchicalFacetByName(facetName)
7363
- );
7152
+ var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facetName));
7364
7153
  var path = refinement.split(separator);
7365
- return path.map(function(part) {
7154
+ return path.map(function (part) {
7366
7155
  return part.trim();
7367
7156
  });
7368
7157
  },
7369
-
7370
- toString: function() {
7158
+ toString: function toString() {
7371
7159
  return JSON.stringify(this, null, 2);
7372
7160
  }
7373
7161
  };
@@ -7387,22 +7175,12 @@
7387
7175
  if (value !== other) {
7388
7176
  var valIsDefined = value !== undefined;
7389
7177
  var valIsNull = value === null;
7390
-
7391
7178
  var othIsDefined = other !== undefined;
7392
7179
  var othIsNull = other === null;
7393
-
7394
- if (
7395
- (!othIsNull && value > other) ||
7396
- (valIsNull && othIsDefined) ||
7397
- !valIsDefined
7398
- ) {
7180
+ if (!othIsNull && value > other || valIsNull && othIsDefined || !valIsDefined) {
7399
7181
  return 1;
7400
7182
  }
7401
- if (
7402
- (!valIsNull && value < other) ||
7403
- (othIsNull && valIsDefined) ||
7404
- !othIsDefined
7405
- ) {
7183
+ if (!valIsNull && value < other || othIsNull && valIsDefined || !othIsDefined) {
7406
7184
  return -1;
7407
7185
  }
7408
7186
  }
@@ -7413,29 +7191,26 @@
7413
7191
  * @param {Array<object>} collection object with keys in attributes
7414
7192
  * @param {Array<string>} iteratees attributes
7415
7193
  * @param {Array<string>} orders asc | desc
7194
+ * @return {Array<object>} sorted collection
7416
7195
  */
7417
7196
  function orderBy(collection, iteratees, orders) {
7418
7197
  if (!Array.isArray(collection)) {
7419
7198
  return [];
7420
7199
  }
7421
-
7422
7200
  if (!Array.isArray(orders)) {
7423
7201
  orders = [];
7424
7202
  }
7425
-
7426
- var result = collection.map(function(value, index) {
7203
+ var result = collection.map(function (value, index) {
7427
7204
  return {
7428
- criteria: iteratees.map(function(iteratee) {
7205
+ criteria: iteratees.map(function (iteratee) {
7429
7206
  return value[iteratee];
7430
7207
  }),
7431
7208
  index: index,
7432
7209
  value: value
7433
7210
  };
7434
7211
  });
7435
-
7436
7212
  result.sort(function comparer(object, other) {
7437
7213
  var index = -1;
7438
-
7439
7214
  while (++index < object.criteria.length) {
7440
7215
  var res = compareAscending(object.criteria[index], other.criteria[index]);
7441
7216
  if (res) {
@@ -7453,19 +7228,16 @@
7453
7228
  // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
7454
7229
  return object.index - other.index;
7455
7230
  });
7456
-
7457
- return result.map(function(res) {
7231
+ return result.map(function (res) {
7458
7232
  return res.value;
7459
7233
  });
7460
7234
  }
7461
-
7462
7235
  var orderBy_1 = orderBy;
7463
7236
 
7464
7237
  var compact = function compact(array) {
7465
7238
  if (!Array.isArray(array)) {
7466
7239
  return [];
7467
7240
  }
7468
-
7469
7241
  return array.filter(Boolean);
7470
7242
  };
7471
7243
 
@@ -7474,7 +7246,6 @@
7474
7246
  if (!Array.isArray(array)) {
7475
7247
  return -1;
7476
7248
  }
7477
-
7478
7249
  for (var i = 0; i < array.length; i++) {
7479
7250
  if (comparator(array[i])) {
7480
7251
  return i;
@@ -7490,43 +7261,33 @@
7490
7261
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
7491
7262
  */
7492
7263
  var formatSort = function formatSort(sortBy, defaults) {
7493
- var defaultInstructions = (defaults || []).map(function(sort) {
7264
+ var defaultInstructions = (defaults || []).map(function (sort) {
7494
7265
  return sort.split(':');
7495
7266
  });
7496
-
7497
- return sortBy.reduce(
7498
- function preparePredicate(out, sort) {
7499
- var sortInstruction = sort.split(':');
7500
-
7501
- var matchingDefault = find$1(defaultInstructions, function(
7502
- defaultInstruction
7503
- ) {
7504
- return defaultInstruction[0] === sortInstruction[0];
7505
- });
7506
-
7507
- if (sortInstruction.length > 1 || !matchingDefault) {
7508
- out[0].push(sortInstruction[0]);
7509
- out[1].push(sortInstruction[1]);
7510
- return out;
7511
- }
7512
-
7513
- out[0].push(matchingDefault[0]);
7514
- out[1].push(matchingDefault[1]);
7267
+ return sortBy.reduce(function preparePredicate(out, sort) {
7268
+ var sortInstruction = sort.split(':');
7269
+ var matchingDefault = find$1(defaultInstructions, function (defaultInstruction) {
7270
+ return defaultInstruction[0] === sortInstruction[0];
7271
+ });
7272
+ if (sortInstruction.length > 1 || !matchingDefault) {
7273
+ out[0].push(sortInstruction[0]);
7274
+ out[1].push(sortInstruction[1]);
7515
7275
  return out;
7516
- },
7517
- [[], []]
7518
- );
7276
+ }
7277
+ out[0].push(matchingDefault[0]);
7278
+ out[1].push(matchingDefault[1]);
7279
+ return out;
7280
+ }, [[], []]);
7519
7281
  };
7520
7282
 
7521
7283
  /**
7522
7284
  * Replaces a leading - with \-
7523
7285
  * @private
7524
7286
  * @param {any} value the facet value to replace
7525
- * @returns any
7287
+ * @returns {any} the escaped facet value or the value if it was not a string
7526
7288
  */
7527
7289
  function escapeFacetValue$1(value) {
7528
7290
  if (typeof value !== 'string') return value;
7529
-
7530
7291
  return String(value).replace(/^-/, '\\-');
7531
7292
  }
7532
7293
 
@@ -7534,14 +7295,12 @@
7534
7295
  * Replaces a leading \- with -
7535
7296
  * @private
7536
7297
  * @param {any} value the escaped facet value
7537
- * @returns any
7298
+ * @returns {any} the unescaped facet value or the value if it was not a string
7538
7299
  */
7539
7300
  function unescapeFacetValue$1(value) {
7540
7301
  if (typeof value !== 'string') return value;
7541
-
7542
7302
  return value.replace(/^\\-/, '-');
7543
7303
  }
7544
-
7545
7304
  var escapeFacetValue_1 = {
7546
7305
  escapeFacetValue: escapeFacetValue$1,
7547
7306
  unescapeFacetValue: unescapeFacetValue$1
@@ -7552,87 +7311,50 @@
7552
7311
 
7553
7312
 
7554
7313
 
7555
-
7556
7314
  var escapeFacetValue$2 = escapeFacetValue_1.escapeFacetValue;
7557
7315
  var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
7558
-
7559
7316
  function generateTrees(state) {
7560
7317
  return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
7561
7318
  var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
7562
- var hierarchicalFacetRefinement =
7563
- (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
7564
- state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
7565
- '';
7566
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
7567
- hierarchicalFacet
7568
- );
7569
- var hierarchicalRootPath = state._getHierarchicalRootPath(
7570
- hierarchicalFacet
7571
- );
7572
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
7573
- hierarchicalFacet
7574
- );
7575
- var sortBy = formatSort(
7576
- state._getHierarchicalFacetSortBy(hierarchicalFacet)
7577
- );
7578
-
7579
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
7319
+ var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] && state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
7320
+ var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
7321
+ var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
7322
+ var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
7323
+ var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
7324
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
7580
7325
  return facetResult.exhaustive;
7581
7326
  });
7582
-
7583
- var generateTreeFn = generateHierarchicalTree(
7584
- sortBy,
7585
- hierarchicalSeparator,
7586
- hierarchicalRootPath,
7587
- hierarchicalShowParentLevel,
7588
- hierarchicalFacetRefinement
7589
- );
7590
-
7327
+ var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, hierarchicalFacetRefinement);
7591
7328
  var results = hierarchicalFacetResult;
7592
-
7593
7329
  if (hierarchicalRootPath) {
7594
- results = hierarchicalFacetResult.slice(
7595
- hierarchicalRootPath.split(hierarchicalSeparator).length
7596
- );
7330
+ results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
7597
7331
  }
7598
-
7599
7332
  return results.reduce(generateTreeFn, {
7600
7333
  name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
7601
- count: null, // root level, no count
7602
- isRefined: true, // root level, always refined
7603
- path: null, // root level, no path
7334
+ count: null,
7335
+ // root level, no count
7336
+ isRefined: true,
7337
+ // root level, always refined
7338
+ path: null,
7339
+ // root level, no path
7604
7340
  escapedValue: null,
7605
7341
  exhaustive: rootExhaustive,
7606
7342
  data: null
7607
7343
  });
7608
7344
  };
7609
7345
  }
7610
-
7611
- function generateHierarchicalTree(
7612
- sortBy,
7613
- hierarchicalSeparator,
7614
- hierarchicalRootPath,
7615
- hierarchicalShowParentLevel,
7616
- currentRefinement
7617
- ) {
7618
- return function generateTree(
7619
- hierarchicalTree,
7620
- hierarchicalFacetResult,
7621
- currentHierarchicalLevel
7622
- ) {
7346
+ function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, currentRefinement) {
7347
+ return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
7623
7348
  var parent = hierarchicalTree;
7624
-
7625
7349
  if (currentHierarchicalLevel > 0) {
7626
7350
  var level = 0;
7627
-
7628
7351
  parent = hierarchicalTree;
7629
-
7630
7352
  while (level < currentHierarchicalLevel) {
7631
7353
  /**
7632
7354
  * @type {object[]]} hierarchical data
7633
7355
  */
7634
7356
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
7635
- parent = find$1(data, function(subtree) {
7357
+ parent = find$1(data, function (subtree) {
7636
7358
  return subtree.isRefined;
7637
7359
  });
7638
7360
  level++;
@@ -7652,99 +7374,49 @@
7652
7374
  // If parent refinement is `beers`, then we do not want to have `bières > Belges`
7653
7375
  // showing up
7654
7376
 
7655
- var picked = Object.keys(hierarchicalFacetResult.data)
7656
- .map(function(facetValue) {
7657
- return [facetValue, hierarchicalFacetResult.data[facetValue]];
7658
- })
7659
- .filter(function(tuple) {
7660
- var facetValue = tuple[0];
7661
- return onlyMatchingTree(
7662
- facetValue,
7663
- parent.path || hierarchicalRootPath,
7664
- currentRefinement,
7665
- hierarchicalSeparator,
7666
- hierarchicalRootPath,
7667
- hierarchicalShowParentLevel
7668
- );
7669
- });
7670
-
7671
- parent.data = orderBy_1(
7672
- picked.map(function(tuple) {
7673
- var facetValue = tuple[0];
7674
- var facetCount = tuple[1];
7675
-
7676
- return format(
7677
- facetCount,
7678
- facetValue,
7679
- hierarchicalSeparator,
7680
- unescapeFacetValue$2(currentRefinement),
7681
- hierarchicalFacetResult.exhaustive
7682
- );
7683
- }),
7684
- sortBy[0],
7685
- sortBy[1]
7686
- );
7377
+ var picked = Object.keys(hierarchicalFacetResult.data).map(function (facetValue) {
7378
+ return [facetValue, hierarchicalFacetResult.data[facetValue]];
7379
+ }).filter(function (tuple) {
7380
+ var facetValue = tuple[0];
7381
+ return onlyMatchingTree(facetValue, parent.path || hierarchicalRootPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
7382
+ });
7383
+ parent.data = orderBy_1(picked.map(function (tuple) {
7384
+ var facetValue = tuple[0];
7385
+ var facetCount = tuple[1];
7386
+ return format(facetCount, facetValue, hierarchicalSeparator, unescapeFacetValue$2(currentRefinement), hierarchicalFacetResult.exhaustive);
7387
+ }), sortBy[0], sortBy[1]);
7687
7388
  }
7688
-
7689
7389
  return hierarchicalTree;
7690
7390
  };
7691
7391
  }
7692
7392
 
7693
- function onlyMatchingTree(
7694
- facetValue,
7695
- parentPath,
7696
- currentRefinement,
7697
- hierarchicalSeparator,
7698
- hierarchicalRootPath,
7699
- hierarchicalShowParentLevel
7700
- ) {
7393
+ // eslint-disable-next-line max-params
7394
+ function onlyMatchingTree(facetValue, parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel) {
7701
7395
  // we want the facetValue is a child of hierarchicalRootPath
7702
- if (
7703
- hierarchicalRootPath &&
7704
- (facetValue.indexOf(hierarchicalRootPath) !== 0 ||
7705
- hierarchicalRootPath === facetValue)
7706
- ) {
7396
+ if (hierarchicalRootPath && (facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
7707
7397
  return false;
7708
7398
  }
7709
7399
 
7710
7400
  // we always want root levels (only when there is no prefix path)
7711
- return (
7712
- (!hierarchicalRootPath &&
7713
- facetValue.indexOf(hierarchicalSeparator) === -1) ||
7714
- // if there is a rootPath, being root level mean 1 level under rootPath
7715
- (hierarchicalRootPath &&
7716
- facetValue.split(hierarchicalSeparator).length -
7717
- hierarchicalRootPath.split(hierarchicalSeparator).length ===
7718
- 1) ||
7719
- // if current refinement is a root level and current facetValue is a root level,
7720
- // keep the facetValue
7721
- (facetValue.indexOf(hierarchicalSeparator) === -1 &&
7722
- currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
7723
- // currentRefinement is a child of the facet value
7724
- currentRefinement.indexOf(facetValue) === 0 ||
7725
- // facetValue is a child of the current parent, add it
7726
- (facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
7727
- (hierarchicalShowParentLevel ||
7728
- facetValue.indexOf(currentRefinement) === 0))
7729
- );
7401
+ return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
7402
+ // if there is a rootPath, being root level mean 1 level under rootPath
7403
+ hierarchicalRootPath && facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
7404
+ // if current refinement is a root level and current facetValue is a root level,
7405
+ // keep the facetValue
7406
+ facetValue.indexOf(hierarchicalSeparator) === -1 && currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
7407
+ // currentRefinement is a child of the facet value
7408
+ currentRefinement.indexOf(facetValue) === 0 ||
7409
+ // facetValue is a child of the current parent, add it
7410
+ facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 && (hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
7730
7411
  }
7731
-
7732
- function format(
7733
- facetCount,
7734
- facetValue,
7735
- hierarchicalSeparator,
7736
- currentRefinement,
7737
- exhaustive
7738
- ) {
7412
+ function format(facetCount, facetValue, hierarchicalSeparator, currentRefinement, exhaustive) {
7739
7413
  var parts = facetValue.split(hierarchicalSeparator);
7740
7414
  return {
7741
7415
  name: parts[parts.length - 1].trim(),
7742
7416
  path: facetValue,
7743
7417
  escapedValue: escapeFacetValue$2(facetValue),
7744
7418
  count: facetCount,
7745
- isRefined:
7746
- currentRefinement === facetValue ||
7747
- currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
7419
+ isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
7748
7420
  exhaustive: exhaustive,
7749
7421
  data: null
7750
7422
  };
@@ -7754,7 +7426,6 @@
7754
7426
  var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
7755
7427
 
7756
7428
 
7757
-
7758
7429
  /**
7759
7430
  * @typedef SearchResults.Facet
7760
7431
  * @type {object}
@@ -7797,18 +7468,17 @@
7797
7468
  */
7798
7469
 
7799
7470
  /**
7800
- * @param {string[]} attributes
7471
+ * Turn an array of attributes in an object of attributes with their position in the array as value
7472
+ * @param {string[]} attributes the list of attributes in the record
7473
+ * @return {object} the list of attributes indexed by attribute name
7801
7474
  */
7802
7475
  function getIndices(attributes) {
7803
7476
  var indices = {};
7804
-
7805
- attributes.forEach(function(val, idx) {
7477
+ attributes.forEach(function (val, idx) {
7806
7478
  indices[val] = idx;
7807
7479
  });
7808
-
7809
7480
  return indices;
7810
7481
  }
7811
-
7812
7482
  function assignFacetStats(dest, facetStats, key) {
7813
7483
  if (facetStats && facetStats[key]) {
7814
7484
  dest.stats = facetStats[key];
@@ -7822,22 +7492,18 @@
7822
7492
  */
7823
7493
 
7824
7494
  /**
7825
- * @param {HierarchicalFacet[]} hierarchicalFacets
7826
- * @param {string} hierarchicalAttributeName
7495
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
7496
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
7497
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
7827
7498
  */
7828
- function findMatchingHierarchicalFacetFromAttributeName(
7829
- hierarchicalFacets,
7830
- hierarchicalAttributeName
7831
- ) {
7832
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
7833
- hierarchicalFacet
7834
- ) {
7499
+ function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
7500
+ return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(hierarchicalFacet) {
7835
7501
  var facetNames = hierarchicalFacet.attributes || [];
7836
7502
  return facetNames.indexOf(hierarchicalAttributeName) > -1;
7837
7503
  });
7838
7504
  }
7839
7505
 
7840
- /*eslint-disable */
7506
+ // eslint-disable-next-line valid-jsdoc
7841
7507
  /**
7842
7508
  * Constructor for SearchResults
7843
7509
  * @class
@@ -7968,21 +7634,20 @@
7968
7634
  "index": "bestbuy"
7969
7635
  }
7970
7636
  **/
7971
- /*eslint-enable */
7972
7637
  function SearchResults(state, results, options) {
7973
7638
  var mainSubResponse = results[0];
7974
-
7975
7639
  this._rawResults = results;
7976
7640
 
7641
+ // eslint-disable-next-line consistent-this
7977
7642
  var self = this;
7978
7643
 
7979
7644
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
7980
- Object.keys(mainSubResponse).forEach(function(key) {
7645
+ Object.keys(mainSubResponse).forEach(function (key) {
7981
7646
  self[key] = mainSubResponse[key];
7982
7647
  });
7983
7648
 
7984
7649
  // Make every key of the result options reachable from the instance
7985
- Object.keys(options || {}).forEach(function(key) {
7650
+ Object.keys(options || {}).forEach(function (key) {
7986
7651
  self[key] = options[key];
7987
7652
  });
7988
7653
 
@@ -8004,8 +7669,8 @@
8004
7669
  * all the records that match the search parameters. Each record is
8005
7670
  * augmented with a new attribute `_highlightResult`
8006
7671
  * 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
7672
+ * - `value` : the value of the facet highlighted (html)
7673
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
8009
7674
  * @name hits
8010
7675
  * @member {object[]}
8011
7676
  * @memberof SearchResults
@@ -8126,10 +7791,8 @@
8126
7791
  * @memberof SearchResults
8127
7792
  * @instance
8128
7793
  */
8129
- this.processingTimeMS = results.reduce(function(sum, result) {
8130
- return result.processingTimeMS === undefined
8131
- ? sum
8132
- : sum + result.processingTimeMS;
7794
+ this.processingTimeMS = results.reduce(function (sum, result) {
7795
+ return result.processingTimeMS === undefined ? sum : sum + result.processingTimeMS;
8133
7796
  }, 0);
8134
7797
 
8135
7798
  /**
@@ -8149,9 +7812,7 @@
8149
7812
  * @member {SearchResults.Facet[]}
8150
7813
  */
8151
7814
  this.facets = [];
8152
-
8153
7815
  var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
8154
-
8155
7816
  var facetsIndices = getIndices(state.facets);
8156
7817
  var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
8157
7818
  var nextDisjunctiveResult = 1;
@@ -8160,20 +7821,14 @@
8160
7821
  // we get the facets information from the first, general, response.
8161
7822
 
8162
7823
  var mainFacets = mainSubResponse.facets || {};
8163
-
8164
- Object.keys(mainFacets).forEach(function(facetKey) {
7824
+ Object.keys(mainFacets).forEach(function (facetKey) {
8165
7825
  var facetValueObject = mainFacets[facetKey];
8166
-
8167
- var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
8168
- state.hierarchicalFacets,
8169
- facetKey
8170
- );
8171
-
7826
+ var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(state.hierarchicalFacets, facetKey);
8172
7827
  if (hierarchicalFacet) {
8173
7828
  // Place the hierarchicalFacet data at the correct index depending on
8174
7829
  // the attributes order that was defined at the helper initialization
8175
7830
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
8176
- var idxAttributeName = findIndex$1(state.hierarchicalFacets, function(f) {
7831
+ var idxAttributeName = findIndex$1(state.hierarchicalFacets, function (f) {
8177
7832
  return f.name === hierarchicalFacet.name;
8178
7833
  });
8179
7834
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
@@ -8185,7 +7840,6 @@
8185
7840
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
8186
7841
  var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
8187
7842
  var position;
8188
-
8189
7843
  if (isFacetDisjunctive) {
8190
7844
  position = disjunctiveFacetsIndices[facetKey];
8191
7845
  self.disjunctiveFacets[position] = {
@@ -8211,22 +7865,20 @@
8211
7865
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
8212
7866
 
8213
7867
  // aggregate the refined disjunctive facets
8214
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
7868
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
8215
7869
  var result = results[nextDisjunctiveResult];
8216
7870
  var facets = result && result.facets ? result.facets : {};
8217
7871
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
8218
7872
 
8219
7873
  // There should be only item in facets.
8220
- Object.keys(facets).forEach(function(dfacet) {
7874
+ Object.keys(facets).forEach(function (dfacet) {
8221
7875
  var facetResults = facets[dfacet];
8222
-
8223
7876
  var position;
8224
-
8225
7877
  if (hierarchicalFacet) {
8226
- position = findIndex$1(state.hierarchicalFacets, function(f) {
7878
+ position = findIndex$1(state.hierarchicalFacets, function (f) {
8227
7879
  return f.name === hierarchicalFacet.name;
8228
7880
  });
8229
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
7881
+ var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
8230
7882
  return f.attribute === dfacet;
8231
7883
  });
8232
7884
 
@@ -8234,29 +7886,20 @@
8234
7886
  if (attributeIndex === -1) {
8235
7887
  return;
8236
7888
  }
8237
-
8238
- self.hierarchicalFacets[position][attributeIndex].data = merge_1(
8239
- {},
8240
- self.hierarchicalFacets[position][attributeIndex].data,
8241
- facetResults
8242
- );
7889
+ self.hierarchicalFacets[position][attributeIndex].data = merge$1({}, self.hierarchicalFacets[position][attributeIndex].data, facetResults);
8243
7890
  } else {
8244
7891
  position = disjunctiveFacetsIndices[dfacet];
8245
-
8246
7892
  var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
8247
-
8248
7893
  self.disjunctiveFacets[position] = {
8249
7894
  name: dfacet,
8250
7895
  data: defaultsPure({}, facetResults, dataFromMainRequest),
8251
7896
  exhaustive: result.exhaustiveFacetsCount
8252
7897
  };
8253
7898
  assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
8254
-
8255
7899
  if (state.disjunctiveFacetsRefinements[dfacet]) {
8256
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
7900
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (refinementValue) {
8257
7901
  // 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) {
7902
+ if (!self.disjunctiveFacets[position].data[refinementValue] && state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
8260
7903
  self.disjunctiveFacets[position].data[refinementValue] = 0;
8261
7904
  }
8262
7905
  });
@@ -8267,28 +7910,23 @@
8267
7910
  });
8268
7911
 
8269
7912
  // if we have some parent level values for hierarchical facets, merge them
8270
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
7913
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
8271
7914
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
8272
7915
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
8273
-
8274
7916
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
8275
7917
  // if we are already at a root refinement (or no refinement at all), there is no
8276
7918
  // root level values request
8277
7919
  if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
8278
7920
  return;
8279
7921
  }
8280
-
8281
- results.slice(nextDisjunctiveResult).forEach(function(result) {
8282
- var facets = result && result.facets
8283
- ? result.facets
8284
- : {};
8285
-
8286
- Object.keys(facets).forEach(function(dfacet) {
7922
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
7923
+ var facets = result && result.facets ? result.facets : {};
7924
+ Object.keys(facets).forEach(function (dfacet) {
8287
7925
  var facetResults = facets[dfacet];
8288
- var position = findIndex$1(state.hierarchicalFacets, function(f) {
7926
+ var position = findIndex$1(state.hierarchicalFacets, function (f) {
8289
7927
  return f.name === hierarchicalFacet.name;
8290
7928
  });
8291
- var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function(f) {
7929
+ var attributeIndex = findIndex$1(self.hierarchicalFacets[position], function (f) {
8292
7930
  return f.attribute === dfacet;
8293
7931
  });
8294
7932
 
@@ -8306,35 +7944,29 @@
8306
7944
  // | beers (5)
8307
7945
  // > IPA (5)
8308
7946
  var defaultData = {};
8309
-
8310
7947
  if (currentRefinement.length > 0) {
8311
7948
  var root = currentRefinement[0].split(separator)[0];
8312
7949
  defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
8313
7950
  }
8314
-
8315
- self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
8316
- defaultData,
8317
- facetResults,
8318
- self.hierarchicalFacets[position][attributeIndex].data
8319
- );
7951
+ self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data);
8320
7952
  });
8321
-
8322
7953
  nextDisjunctiveResult++;
8323
7954
  });
8324
7955
  });
8325
7956
 
8326
7957
  // add the excludes
8327
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
7958
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
8328
7959
  var excludes = state.facetsExcludes[facetName];
8329
7960
  var position = facetsIndices[facetName];
8330
-
8331
7961
  self.facets[position] = {
8332
7962
  name: facetName,
8333
7963
  data: mainFacets[facetName],
8334
7964
  exhaustive: mainSubResponse.exhaustiveFacetsCount
8335
7965
  };
8336
- excludes.forEach(function(facetValue) {
8337
- self.facets[position] = self.facets[position] || {name: facetName};
7966
+ excludes.forEach(function (facetValue) {
7967
+ self.facets[position] = self.facets[position] || {
7968
+ name: facetName
7969
+ };
8338
7970
  self.facets[position].data = self.facets[position].data || {};
8339
7971
  self.facets[position].data[facetValue] = 0;
8340
7972
  });
@@ -8353,7 +7985,6 @@
8353
7985
  * @type {Array}
8354
7986
  */
8355
7987
  this.disjunctiveFacets = compact(this.disjunctiveFacets);
8356
-
8357
7988
  this._state = state;
8358
7989
  }
8359
7990
 
@@ -8363,14 +7994,11 @@
8363
7994
  * @param {string} name name of the faceted attribute
8364
7995
  * @return {SearchResults.Facet} the facet object
8365
7996
  */
8366
- SearchResults.prototype.getFacetByName = function(name) {
7997
+ SearchResults.prototype.getFacetByName = function (name) {
8367
7998
  function predicate(facet) {
8368
7999
  return facet.name === name;
8369
8000
  }
8370
-
8371
- return find$1(this.facets, predicate) ||
8372
- find$1(this.disjunctiveFacets, predicate) ||
8373
- find$1(this.hierarchicalFacets, predicate);
8001
+ return find$1(this.facets, predicate) || find$1(this.disjunctiveFacets, predicate) || find$1(this.hierarchicalFacets, predicate);
8374
8002
  };
8375
8003
 
8376
8004
  /**
@@ -8384,12 +8012,10 @@
8384
8012
  function predicate(facet) {
8385
8013
  return facet.name === attribute;
8386
8014
  }
8387
-
8388
8015
  if (results._state.isConjunctiveFacet(attribute)) {
8389
8016
  var facet = find$1(results.facets, predicate);
8390
8017
  if (!facet) return [];
8391
-
8392
- return Object.keys(facet.data).map(function(name) {
8018
+ return Object.keys(facet.data).map(function (name) {
8393
8019
  var value = escapeFacetValue$3(name);
8394
8020
  return {
8395
8021
  name: name,
@@ -8402,8 +8028,7 @@
8402
8028
  } else if (results._state.isDisjunctiveFacet(attribute)) {
8403
8029
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
8404
8030
  if (!disjunctiveFacet) return [];
8405
-
8406
- return Object.keys(disjunctiveFacet.data).map(function(name) {
8031
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
8407
8032
  var value = escapeFacetValue$3(name);
8408
8033
  return {
8409
8034
  name: name,
@@ -8415,29 +8040,31 @@
8415
8040
  } else if (results._state.isHierarchicalFacet(attribute)) {
8416
8041
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
8417
8042
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
8418
-
8419
8043
  var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
8420
- var currentRefinementSplit = unescapeFacetValue$3(
8421
- results._state.getHierarchicalRefinement(attribute)[0] || ''
8422
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
8044
+ var separator = results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
8045
+ var currentRefinement = unescapeFacetValue$3(results._state.getHierarchicalRefinement(attribute)[0] || '');
8046
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
8047
+ currentRefinement = currentRefinement.replace(hierarchicalFacet.rootPath + separator, '');
8048
+ }
8049
+ var currentRefinementSplit = currentRefinement.split(separator);
8423
8050
  currentRefinementSplit.unshift(attribute);
8424
-
8425
8051
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
8426
-
8427
8052
  return hierarchicalFacetValues;
8428
8053
  }
8054
+ return undefined;
8429
8055
  }
8430
8056
 
8431
8057
  /**
8432
8058
  * Set the isRefined of a hierarchical facet result based on the current state.
8433
8059
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
8434
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
8060
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
8435
8061
  * @param {number} depth recursion depth in the currentRefinement
8062
+ * @return {undefined} function mutates the item
8436
8063
  */
8437
8064
  function setIsRefined(item, currentRefinement, depth) {
8438
8065
  item.isRefined = item.name === currentRefinement[depth];
8439
8066
  if (item.data) {
8440
- item.data.forEach(function(child) {
8067
+ item.data.forEach(function (child) {
8441
8068
  setIsRefined(child, currentRefinement, depth + 1);
8442
8069
  });
8443
8070
  }
@@ -8446,32 +8073,30 @@
8446
8073
  /**
8447
8074
  * Sort nodes of a hierarchical or disjunctive facet results
8448
8075
  * @private
8449
- * @param {function} sortFn
8076
+ * @param {function} sortFn sort function to apply
8450
8077
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
8451
8078
  * @param {string[]} names attribute names
8452
8079
  * @param {number} [level=0] current index in the names array
8080
+ * @return {HierarchicalFacet|Array} sorted node
8453
8081
  */
8454
8082
  function recSort(sortFn, node, names, level) {
8455
8083
  level = level || 0;
8456
-
8457
8084
  if (Array.isArray(node)) {
8458
8085
  return sortFn(node, names[level]);
8459
8086
  }
8460
-
8461
8087
  if (!node.data || node.data.length === 0) {
8462
8088
  return node;
8463
8089
  }
8464
-
8465
- var children = node.data.map(function(childNode) {
8090
+ var children = node.data.map(function (childNode) {
8466
8091
  return recSort(sortFn, childNode, names, level + 1);
8467
8092
  });
8468
8093
  var sortedChildren = sortFn(children, names[level]);
8469
- var newNode = defaultsPure({data: sortedChildren}, node);
8094
+ var newNode = defaultsPure({
8095
+ data: sortedChildren
8096
+ }, node);
8470
8097
  return newNode;
8471
8098
  }
8472
-
8473
8099
  SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
8474
-
8475
8100
  function vanillaSortFn(order, data) {
8476
8101
  return data.sort(order);
8477
8102
  }
@@ -8487,23 +8112,21 @@
8487
8112
  * Sorts facet arrays via their facet ordering
8488
8113
  * @param {Array} facetValues the values
8489
8114
  * @param {FacetOrdering} facetOrdering the ordering
8490
- * @returns {Array}
8115
+ * @returns {Array} the sorted facet values
8491
8116
  */
8492
8117
  function sortViaFacetOrdering(facetValues, facetOrdering) {
8493
8118
  var orderedFacets = [];
8494
8119
  var remainingFacets = [];
8495
-
8496
8120
  var order = facetOrdering.order || [];
8497
8121
  /**
8498
8122
  * an object with the keys being the values in order, the values their index:
8499
8123
  * ['one', 'two'] -> { one: 0, two: 1 }
8500
8124
  */
8501
- var reverseOrder = order.reduce(function(acc, name, i) {
8125
+ var reverseOrder = order.reduce(function (acc, name, i) {
8502
8126
  acc[name] = i;
8503
8127
  return acc;
8504
8128
  }, {});
8505
-
8506
- facetValues.forEach(function(item) {
8129
+ facetValues.forEach(function (item) {
8507
8130
  // hierarchical facets get sorted using their raw name
8508
8131
  var name = item.path || item.name;
8509
8132
  if (reverseOrder[name] !== undefined) {
@@ -8512,11 +8135,9 @@
8512
8135
  remainingFacets.push(item);
8513
8136
  }
8514
8137
  });
8515
-
8516
- orderedFacets = orderedFacets.filter(function(facet) {
8138
+ orderedFacets = orderedFacets.filter(function (facet) {
8517
8139
  return facet;
8518
8140
  });
8519
-
8520
8141
  var sortRemainingBy = facetOrdering.sortRemainingBy;
8521
8142
  var ordering;
8522
8143
  if (sortRemainingBy === 'hidden') {
@@ -8526,24 +8147,16 @@
8526
8147
  } else {
8527
8148
  ordering = [['count'], ['desc']];
8528
8149
  }
8529
-
8530
- return orderedFacets.concat(
8531
- orderBy_1(remainingFacets, ordering[0], ordering[1])
8532
- );
8150
+ return orderedFacets.concat(orderBy_1(remainingFacets, ordering[0], ordering[1]));
8533
8151
  }
8534
8152
 
8535
8153
  /**
8536
8154
  * @param {SearchResults} results the search results class
8537
8155
  * @param {string} attribute the attribute to retrieve ordering of
8538
- * @returns {FacetOrdering=}
8156
+ * @returns {FacetOrdering | undefined} the facet ordering
8539
8157
  */
8540
8158
  function getFacetOrdering(results, attribute) {
8541
- return (
8542
- results.renderingContent &&
8543
- results.renderingContent.facetOrdering &&
8544
- results.renderingContent.facetOrdering.values &&
8545
- results.renderingContent.facetOrdering.values[attribute]
8546
- );
8159
+ return results.renderingContent && results.renderingContent.facetOrdering && results.renderingContent.facetOrdering.values && results.renderingContent.facetOrdering.values[attribute];
8547
8160
  }
8548
8161
 
8549
8162
  /**
@@ -8594,12 +8207,11 @@
8594
8207
  * });
8595
8208
  * });
8596
8209
  */
8597
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
8210
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
8598
8211
  var facetValues = extractNormalizedFacetValues(this, attribute);
8599
8212
  if (!facetValues) {
8600
8213
  return undefined;
8601
8214
  }
8602
-
8603
8215
  var options = defaultsPure({}, opts, {
8604
8216
  sortBy: SearchResults.DEFAULT_SORT,
8605
8217
  // if no sortBy is given, attempt to sort based on facetOrdering
@@ -8607,6 +8219,7 @@
8607
8219
  facetOrdering: !(opts && opts.sortBy)
8608
8220
  });
8609
8221
 
8222
+ // eslint-disable-next-line consistent-this
8610
8223
  var results = this;
8611
8224
  var attributes;
8612
8225
  if (Array.isArray(facetValues)) {
@@ -8615,25 +8228,20 @@
8615
8228
  var config = results._state.getHierarchicalFacetByName(facetValues.name);
8616
8229
  attributes = config.attributes;
8617
8230
  }
8618
-
8619
- return recSort(function(data, facetName) {
8231
+ return recSort(function (data, facetName) {
8620
8232
  if (options.facetOrdering) {
8621
8233
  var facetOrdering = getFacetOrdering(results, facetName);
8622
- if (Boolean(facetOrdering)) {
8234
+ if (facetOrdering) {
8623
8235
  return sortViaFacetOrdering(data, facetOrdering);
8624
8236
  }
8625
8237
  }
8626
-
8627
8238
  if (Array.isArray(options.sortBy)) {
8628
8239
  var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
8629
8240
  return orderBy_1(data, order[0], order[1]);
8630
8241
  } else if (typeof options.sortBy === 'function') {
8631
8242
  return vanillaSortFn(options.sortBy, data);
8632
8243
  }
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
- );
8244
+ throw new Error('options.sortBy is optional but if defined it must be ' + 'either an array of string (predicates) or a sorting function');
8637
8245
  }, facetValues, attributes);
8638
8246
  };
8639
8247
 
@@ -8643,13 +8251,12 @@
8643
8251
  * @param {string} attribute name of the faceted attribute
8644
8252
  * @return {object} The stats of the facet
8645
8253
  */
8646
- SearchResults.prototype.getFacetStats = function(attribute) {
8254
+ SearchResults.prototype.getFacetStats = function (attribute) {
8647
8255
  if (this._state.isConjunctiveFacet(attribute)) {
8648
8256
  return getFacetStatsIfAvailable(this.facets, attribute);
8649
8257
  } else if (this._state.isDisjunctiveFacet(attribute)) {
8650
8258
  return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
8651
8259
  }
8652
-
8653
8260
  return undefined;
8654
8261
  };
8655
8262
 
@@ -8660,10 +8267,11 @@
8660
8267
 
8661
8268
  /**
8662
8269
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
8663
- * @param {string} facetName
8270
+ * @param {string} facetName The attribute to look for
8271
+ * @return {object|undefined} The stats of the facet
8664
8272
  */
8665
8273
  function getFacetStatsIfAvailable(facetList, facetName) {
8666
- var data = find$1(facetList, function(facet) {
8274
+ var data = find$1(facetList, function (facet) {
8667
8275
  return facet.name === facetName;
8668
8276
  });
8669
8277
  return data && data.stats;
@@ -8681,40 +8289,35 @@
8681
8289
  *
8682
8290
  * @return {Array.<Refinement>} all the refinements
8683
8291
  */
8684
- SearchResults.prototype.getRefinements = function() {
8292
+ SearchResults.prototype.getRefinements = function () {
8685
8293
  var state = this._state;
8294
+ // eslint-disable-next-line consistent-this
8686
8295
  var results = this;
8687
8296
  var res = [];
8688
-
8689
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
8690
- state.facetsRefinements[attributeName].forEach(function(name) {
8297
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
8298
+ state.facetsRefinements[attributeName].forEach(function (name) {
8691
8299
  res.push(getRefinement$1(state, 'facet', attributeName, name, results.facets));
8692
8300
  });
8693
8301
  });
8694
-
8695
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
8696
- state.facetsExcludes[attributeName].forEach(function(name) {
8302
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
8303
+ state.facetsExcludes[attributeName].forEach(function (name) {
8697
8304
  res.push(getRefinement$1(state, 'exclude', attributeName, name, results.facets));
8698
8305
  });
8699
8306
  });
8700
-
8701
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
8702
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
8307
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (attributeName) {
8308
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
8703
8309
  res.push(getRefinement$1(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
8704
8310
  });
8705
8311
  });
8706
-
8707
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
8708
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
8312
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (attributeName) {
8313
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
8709
8314
  res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
8710
8315
  });
8711
8316
  });
8712
-
8713
-
8714
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
8317
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
8715
8318
  var operators = state.numericRefinements[attributeName];
8716
- Object.keys(operators).forEach(function(operator) {
8717
- operators[operator].forEach(function(value) {
8319
+ Object.keys(operators).forEach(function (operator) {
8320
+ operators[operator].forEach(function (value) {
8718
8321
  res.push({
8719
8322
  type: 'numeric',
8720
8323
  attributeName: attributeName,
@@ -8725,11 +8328,13 @@
8725
8328
  });
8726
8329
  });
8727
8330
  });
8728
-
8729
- state.tagRefinements.forEach(function(name) {
8730
- res.push({type: 'tag', attributeName: '_tags', name: name});
8331
+ state.tagRefinements.forEach(function (name) {
8332
+ res.push({
8333
+ type: 'tag',
8334
+ attributeName: '_tags',
8335
+ name: name
8336
+ });
8731
8337
  });
8732
-
8733
8338
  return res;
8734
8339
  };
8735
8340
 
@@ -8741,19 +8346,19 @@
8741
8346
  */
8742
8347
 
8743
8348
  /**
8744
- * @param {*} state
8745
- * @param {*} type
8746
- * @param {string} attributeName
8747
- * @param {*} name
8748
- * @param {Facet[]} resultsFacets
8349
+ * @param {SearchParameters} state the current state
8350
+ * @param {string} type the type of the refinement
8351
+ * @param {string} attributeName The attribute of the facet
8352
+ * @param {*} name The name of the facet
8353
+ * @param {Facet[]} resultsFacets facets from the results
8354
+ * @return {Refinement} the refinement
8749
8355
  */
8750
8356
  function getRefinement$1(state, type, attributeName, name, resultsFacets) {
8751
- var facet = find$1(resultsFacets, function(f) {
8357
+ var facet = find$1(resultsFacets, function (f) {
8752
8358
  return f.name === attributeName;
8753
8359
  });
8754
8360
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
8755
- var exhaustive = (facet && facet.exhaustive) || false;
8756
-
8361
+ var exhaustive = facet && facet.exhaustive || false;
8757
8362
  return {
8758
8363
  type: type,
8759
8364
  attributeName: attributeName,
@@ -8764,31 +8369,28 @@
8764
8369
  }
8765
8370
 
8766
8371
  /**
8767
- * @param {*} state
8768
- * @param {string} attributeName
8769
- * @param {*} name
8770
- * @param {Facet[]} resultsFacets
8372
+ * @param {SearchParameters} state the current state
8373
+ * @param {string} attributeName the attribute of the hierarchical facet
8374
+ * @param {string} name the name of the facet
8375
+ * @param {Facet[]} resultsFacets facets from the results
8376
+ * @return {HierarchicalFacet} the hierarchical facet
8771
8377
  */
8772
8378
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
8773
8379
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
8774
8380
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
8775
8381
  var split = name.split(separator);
8776
- var rootFacet = find$1(resultsFacets, function(facet) {
8382
+ var rootFacet = find$1(resultsFacets, function (facet) {
8777
8383
  return facet.name === attributeName;
8778
8384
  });
8779
-
8780
- var facet = split.reduce(function(intermediateFacet, part) {
8781
- var newFacet =
8782
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
8783
- return f.name === part;
8784
- });
8385
+ var facet = split.reduce(function (intermediateFacet, part) {
8386
+ var newFacet = intermediateFacet && find$1(intermediateFacet.data, function (f) {
8387
+ return f.name === part;
8388
+ });
8785
8389
  return newFacet !== undefined ? newFacet : intermediateFacet;
8786
8390
  }, rootFacet);
8787
-
8788
- var count = (facet && facet.count) || 0;
8789
- var exhaustive = (facet && facet.exhaustive) || false;
8790
- var path = (facet && facet.path) || '';
8791
-
8391
+ var count = facet && facet.count || 0;
8392
+ var exhaustive = facet && facet.exhaustive || false;
8393
+ var path = facet && facet.path || '';
8792
8394
  return {
8793
8395
  type: 'hierarchical',
8794
8396
  attributeName: attributeName,
@@ -8797,7 +8399,6 @@
8797
8399
  exhaustive: exhaustive
8798
8400
  };
8799
8401
  }
8800
-
8801
8402
  var SearchResults_1 = SearchResults;
8802
8403
 
8803
8404
  // Copyright Joyent, Inc. and other Node contributors.
@@ -9113,7 +8714,6 @@
9113
8714
  }
9114
8715
  });
9115
8716
  }
9116
-
9117
8717
  var inherits_1 = inherits;
9118
8718
 
9119
8719
  /**
@@ -9125,13 +8725,14 @@
9125
8725
  * - result: when the response is retrieved from Algolia and is processed.
9126
8726
  * This event contains a {@link SearchResults} object and the
9127
8727
  * {@link SearchParameters} corresponding to this answer.
8728
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
8729
+ * @param {function} fn the function to create the derived state
9128
8730
  */
9129
8731
  function DerivedHelper(mainHelper, fn) {
9130
8732
  this.main = mainHelper;
9131
8733
  this.fn = fn;
9132
8734
  this.lastResults = null;
9133
8735
  }
9134
-
9135
8736
  inherits_1(DerivedHelper, events);
9136
8737
 
9137
8738
  /**
@@ -9139,33 +8740,30 @@
9139
8740
  * @return {undefined}
9140
8741
  * @throws Error if the derived helper is already detached
9141
8742
  */
9142
- DerivedHelper.prototype.detach = function() {
8743
+ DerivedHelper.prototype.detach = function () {
9143
8744
  this.removeAllListeners();
9144
8745
  this.main.detachDerivedHelper(this);
9145
8746
  };
9146
-
9147
- DerivedHelper.prototype.getModifiedState = function(parameters) {
8747
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
9148
8748
  return this.fn(parameters);
9149
8749
  };
9150
-
9151
8750
  var DerivedHelper_1 = DerivedHelper;
9152
8751
 
9153
8752
  function sortObject(obj) {
9154
- return Object.keys(obj)
9155
- .sort(function(a, b) {
9156
- return a.localeCompare(b);
9157
- })
9158
- .reduce(function(acc, curr) {
9159
- acc[curr] = obj[curr];
9160
- return acc;
9161
- }, {});
8753
+ return Object.keys(obj).sort(function (a, b) {
8754
+ return a.localeCompare(b);
8755
+ }).reduce(function (acc, curr) {
8756
+ acc[curr] = obj[curr];
8757
+ return acc;
8758
+ }, {});
9162
8759
  }
9163
-
9164
8760
  var requestBuilder = {
9165
8761
  /**
9166
8762
  * Get all the queries to send to the client, those queries can used directly
9167
8763
  * with the Algolia client.
9168
8764
  * @private
8765
+ * @param {string} index The name of the index
8766
+ * @param {SearchParameters} state The state from which to get the queries
9169
8767
  * @return {object[]} The queries
9170
8768
  */
9171
8769
  _getQueries: function getQueries(index, state) {
@@ -9178,7 +8776,7 @@
9178
8776
  });
9179
8777
 
9180
8778
  // One for each disjunctive facets
9181
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
8779
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
9182
8780
  queries.push({
9183
8781
  indexName: index,
9184
8782
  params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
@@ -9186,7 +8784,7 @@
9186
8784
  });
9187
8785
 
9188
8786
  // More to get the parent levels of the hierarchical facets when refined
9189
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
8787
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
9190
8788
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
9191
8789
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
9192
8790
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
@@ -9195,75 +8793,58 @@
9195
8793
  // we want to get all parent values
9196
8794
  if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
9197
8795
  // 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) {
9200
- return map.concat({
9201
- attribute: hierarchicalFacet.attributes[level],
9202
- value: level === 0
9203
- ? segment
9204
- : [map[map.length - 1].value, segment].join(separator)
9205
- });
9206
- }
9207
- , []);
9208
-
9209
- filtersMap.forEach(function(filter, level) {
9210
- var params = requestBuilder._getDisjunctiveFacetSearchParams(
9211
- state,
9212
- filter.attribute,
9213
- level === 0
9214
- );
8796
+ var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(function createFiltersMap(map, segment, level) {
8797
+ return map.concat({
8798
+ attribute: hierarchicalFacet.attributes[level],
8799
+ value: level === 0 ? segment : [map[map.length - 1].value, segment].join(separator)
8800
+ });
8801
+ }, []);
8802
+ filtersMap.forEach(function (filter, level) {
8803
+ var params = requestBuilder._getDisjunctiveFacetSearchParams(state, filter.attribute, level === 0);
9215
8804
 
9216
8805
  // Keep facet filters unrelated to current hierarchical attributes
9217
8806
  function hasHierarchicalFacetFilter(value) {
9218
- return hierarchicalFacet.attributes.some(function(attribute) {
8807
+ return hierarchicalFacet.attributes.some(function (attribute) {
9219
8808
  return attribute === value.split(':')[0];
9220
8809
  });
9221
8810
  }
9222
-
9223
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
8811
+ var filteredFacetFilters = (params.facetFilters || []).reduce(function (acc, facetFilter) {
9224
8812
  if (Array.isArray(facetFilter)) {
9225
- var filtered = facetFilter.filter(function(filterValue) {
8813
+ var filtered = facetFilter.filter(function (filterValue) {
9226
8814
  return !hasHierarchicalFacetFilter(filterValue);
9227
8815
  });
9228
-
9229
8816
  if (filtered.length > 0) {
9230
8817
  acc.push(filtered);
9231
8818
  }
9232
8819
  }
9233
-
9234
8820
  if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
9235
8821
  acc.push(facetFilter);
9236
8822
  }
9237
-
9238
8823
  return acc;
9239
8824
  }, []);
9240
-
9241
8825
  var parent = filtersMap[level - 1];
9242
8826
  if (level > 0) {
9243
8827
  params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
9244
8828
  } else {
9245
8829
  params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
9246
8830
  }
9247
-
9248
- queries.push({indexName: index, params: params});
8831
+ queries.push({
8832
+ indexName: index,
8833
+ params: params
8834
+ });
9249
8835
  });
9250
8836
  }
9251
8837
  });
9252
-
9253
8838
  return queries;
9254
8839
  },
9255
-
9256
8840
  /**
9257
8841
  * Build search parameters used to fetch hits
9258
8842
  * @private
9259
- * @return {object.<string, any>}
8843
+ * @param {SearchParameters} state The state from which to get the queries
8844
+ * @return {object.<string, any>} The search parameters for hits
9260
8845
  */
9261
- _getHitsSearchParams: function(state) {
9262
- var facets = state.facets
9263
- .concat(state.disjunctiveFacets)
9264
- .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
9265
-
9266
-
8846
+ _getHitsSearchParams: function _getHitsSearchParams(state) {
8847
+ var facets = state.facets.concat(state.disjunctiveFacets).concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
9267
8848
  var facetFilters = requestBuilder._getFacetFilters(state);
9268
8849
  var numericFilters = requestBuilder._getNumericFilters(state);
9269
8850
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -9271,26 +8852,23 @@
9271
8852
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
9272
8853
  tagFilters: tagFilters
9273
8854
  };
9274
-
9275
8855
  if (facetFilters.length > 0) {
9276
8856
  additionalParams.facetFilters = facetFilters;
9277
8857
  }
9278
-
9279
8858
  if (numericFilters.length > 0) {
9280
8859
  additionalParams.numericFilters = numericFilters;
9281
8860
  }
9282
-
9283
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
8861
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
9284
8862
  },
9285
-
9286
8863
  /**
9287
8864
  * Build search parameters used to fetch a disjunctive facet
9288
8865
  * @private
8866
+ * @param {SearchParameters} state The state from which to get the queries
9289
8867
  * @param {string} facet the associated facet name
9290
8868
  * @param {boolean} hierarchicalRootLevel ?? FIXME
9291
- * @return {object}
8869
+ * @return {object} The search parameters for a disjunctive facet
9292
8870
  */
9293
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
8871
+ _getDisjunctiveFacetSearchParams: function _getDisjunctiveFacetSearchParams(state, facet, hierarchicalRootLevel) {
9294
8872
  var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
9295
8873
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
9296
8874
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -9300,55 +8878,43 @@
9300
8878
  analytics: false,
9301
8879
  clickAnalytics: false
9302
8880
  };
9303
-
9304
8881
  if (tagFilters.length > 0) {
9305
8882
  additionalParams.tagFilters = tagFilters;
9306
8883
  }
9307
-
9308
8884
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
9309
-
9310
8885
  if (hierarchicalFacet) {
9311
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
9312
- state,
9313
- hierarchicalFacet,
9314
- hierarchicalRootLevel
9315
- );
8886
+ additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, hierarchicalRootLevel);
9316
8887
  } else {
9317
8888
  additionalParams.facets = facet;
9318
8889
  }
9319
-
9320
8890
  if (numericFilters.length > 0) {
9321
8891
  additionalParams.numericFilters = numericFilters;
9322
8892
  }
9323
-
9324
8893
  if (facetFilters.length > 0) {
9325
8894
  additionalParams.facetFilters = facetFilters;
9326
8895
  }
9327
-
9328
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
8896
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
9329
8897
  },
9330
-
9331
8898
  /**
9332
8899
  * Return the numeric filters in an algolia request fashion
9333
8900
  * @private
8901
+ * @param {SearchParameters} state the state from which to get the filters
9334
8902
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
9335
8903
  * @return {string[]} the numeric filters in the algolia format
9336
8904
  */
9337
- _getNumericFilters: function(state, facetName) {
8905
+ _getNumericFilters: function _getNumericFilters(state, facetName) {
9338
8906
  if (state.numericFilters) {
9339
8907
  return state.numericFilters;
9340
8908
  }
9341
-
9342
8909
  var numericFilters = [];
9343
-
9344
- Object.keys(state.numericRefinements).forEach(function(attribute) {
8910
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
9345
8911
  var operators = state.numericRefinements[attribute] || {};
9346
- Object.keys(operators).forEach(function(operator) {
8912
+ Object.keys(operators).forEach(function (operator) {
9347
8913
  var values = operators[operator] || [];
9348
8914
  if (facetName !== attribute) {
9349
- values.forEach(function(value) {
8915
+ values.forEach(function (value) {
9350
8916
  if (Array.isArray(value)) {
9351
- var vs = value.map(function(v) {
8917
+ var vs = value.map(function (v) {
9352
8918
  return attribute + operator + v;
9353
8919
  });
9354
8920
  numericFilters.push(vs);
@@ -9359,74 +8925,64 @@
9359
8925
  }
9360
8926
  });
9361
8927
  });
9362
-
9363
8928
  return numericFilters;
9364
8929
  },
9365
-
9366
8930
  /**
9367
- * Return the tags filters depending
8931
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
9368
8932
  * @private
9369
- * @return {string}
8933
+ * @param {SearchParameters} state the state from which to get the filters
8934
+ * @return {string} Tag filters in a single string
9370
8935
  */
9371
- _getTagFilters: function(state) {
8936
+ _getTagFilters: function _getTagFilters(state) {
9372
8937
  if (state.tagFilters) {
9373
8938
  return state.tagFilters;
9374
8939
  }
9375
-
9376
8940
  return state.tagRefinements.join(',');
9377
8941
  },
9378
-
9379
-
9380
8942
  /**
9381
8943
  * Build facetFilters parameter based on current refinements. The array returned
9382
8944
  * contains strings representing the facet filters in the algolia format.
9383
8945
  * @private
8946
+ * @param {SearchParameters} state The state from which to get the queries
9384
8947
  * @param {string} [facet] if set, the current disjunctive facet
9385
- * @return {array.<string>}
8948
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
8949
+ * @return {array.<string>} The facet filters in the algolia format
9386
8950
  */
9387
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
8951
+ _getFacetFilters: function _getFacetFilters(state, facet, hierarchicalRootLevel) {
9388
8952
  var facetFilters = [];
9389
-
9390
8953
  var facetsRefinements = state.facetsRefinements || {};
9391
- Object.keys(facetsRefinements).forEach(function(facetName) {
8954
+ Object.keys(facetsRefinements).forEach(function (facetName) {
9392
8955
  var facetValues = facetsRefinements[facetName] || [];
9393
- facetValues.forEach(function(facetValue) {
8956
+ facetValues.forEach(function (facetValue) {
9394
8957
  facetFilters.push(facetName + ':' + facetValue);
9395
8958
  });
9396
8959
  });
9397
-
9398
8960
  var facetsExcludes = state.facetsExcludes || {};
9399
- Object.keys(facetsExcludes).forEach(function(facetName) {
8961
+ Object.keys(facetsExcludes).forEach(function (facetName) {
9400
8962
  var facetValues = facetsExcludes[facetName] || [];
9401
- facetValues.forEach(function(facetValue) {
8963
+ facetValues.forEach(function (facetValue) {
9402
8964
  facetFilters.push(facetName + ':-' + facetValue);
9403
8965
  });
9404
8966
  });
9405
-
9406
8967
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
9407
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
8968
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
9408
8969
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
9409
8970
  if (facetName === facet || !facetValues || facetValues.length === 0) {
9410
8971
  return;
9411
8972
  }
9412
8973
  var orFilters = [];
9413
-
9414
- facetValues.forEach(function(facetValue) {
8974
+ facetValues.forEach(function (facetValue) {
9415
8975
  orFilters.push(facetName + ':' + facetValue);
9416
8976
  });
9417
-
9418
8977
  facetFilters.push(orFilters);
9419
8978
  });
9420
-
9421
8979
  var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
9422
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
8980
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
9423
8981
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
9424
8982
  var facetValue = facetValues[0];
9425
-
9426
8983
  if (facetValue === undefined) {
9427
8984
  return;
9428
8985
  }
9429
-
9430
8986
  var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
9431
8987
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9432
8988
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -9437,11 +8993,9 @@
9437
8993
  if (facet === facetName) {
9438
8994
  // if we are at the root level already, no need to ask for facet values, we get them from
9439
8995
  // the hits query
9440
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
9441
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
8996
+ if (facetValue.indexOf(separator) === -1 || !rootPath && hierarchicalRootLevel === true || rootPath && rootPath.split(separator).length === facetValue.split(separator).length) {
9442
8997
  return;
9443
8998
  }
9444
-
9445
8999
  if (!rootPath) {
9446
9000
  attributesIndex = facetValue.split(separator).length - 2;
9447
9001
  facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
@@ -9449,56 +9003,45 @@
9449
9003
  attributesIndex = rootPath.split(separator).length - 1;
9450
9004
  facetValue = rootPath;
9451
9005
  }
9452
-
9453
9006
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
9454
9007
  } else {
9455
9008
  attributesIndex = facetValue.split(separator).length - 1;
9456
-
9457
9009
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
9458
9010
  }
9459
-
9460
9011
  if (attributeToRefine) {
9461
9012
  facetFilters.push([attributeToRefine + ':' + facetValue]);
9462
9013
  }
9463
9014
  });
9464
-
9465
9015
  return facetFilters;
9466
9016
  },
9467
-
9468
- _getHitsHierarchicalFacetsAttributes: function(state) {
9017
+ _getHitsHierarchicalFacetsAttributes: function _getHitsHierarchicalFacetsAttributes(state) {
9469
9018
  var out = [];
9470
-
9471
9019
  return state.hierarchicalFacets.reduce(
9472
- // ask for as much levels as there's hierarchical refinements
9473
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
9474
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
9475
-
9476
- // if no refinement, ask for root level
9477
- if (!hierarchicalRefinement) {
9478
- allAttributes.push(hierarchicalFacet.attributes[0]);
9479
- return allAttributes;
9480
- }
9481
-
9482
- var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9483
- var level = hierarchicalRefinement.split(separator).length;
9484
- var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
9485
-
9486
- return allAttributes.concat(newAttributes);
9487
- }, out);
9020
+ // ask for as much levels as there's hierarchical refinements
9021
+ function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
9022
+ var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
9023
+
9024
+ // if no refinement, ask for root level
9025
+ if (!hierarchicalRefinement) {
9026
+ allAttributes.push(hierarchicalFacet.attributes[0]);
9027
+ return allAttributes;
9028
+ }
9029
+ var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9030
+ var level = hierarchicalRefinement.split(separator).length;
9031
+ var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
9032
+ return allAttributes.concat(newAttributes);
9033
+ }, out);
9488
9034
  },
9489
-
9490
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
9035
+ _getDisjunctiveHierarchicalFacetAttribute: function _getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, rootLevel) {
9491
9036
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
9492
9037
  if (rootLevel === true) {
9493
9038
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
9494
9039
  var attributeIndex = 0;
9495
-
9496
9040
  if (rootPath) {
9497
9041
  attributeIndex = rootPath.split(separator).length;
9498
9042
  }
9499
9043
  return [hierarchicalFacet.attributes[attributeIndex]];
9500
9044
  }
9501
-
9502
9045
  var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
9503
9046
  // if refinement is 'beers > IPA > Flying dog',
9504
9047
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
@@ -9506,11 +9049,8 @@
9506
9049
  var parentLevel = hierarchicalRefinement.split(separator).length - 1;
9507
9050
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
9508
9051
  },
9509
-
9510
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
9511
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
9512
- state.clearRefinements(facetName) :
9513
- state;
9052
+ getSearchForFacetQuery: function getSearchForFacetQuery(facetName, query, maxFacetHits, state) {
9053
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ? state.clearRefinements(facetName) : state;
9514
9054
  var searchForFacetSearchParameters = {
9515
9055
  facetQuery: query,
9516
9056
  facetName: facetName
@@ -9518,17 +9058,12 @@
9518
9058
  if (typeof maxFacetHits === 'number') {
9519
9059
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
9520
9060
  }
9521
- return sortObject(merge_1(
9522
- {},
9523
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
9524
- searchForFacetSearchParameters
9525
- ));
9061
+ return sortObject(merge$1({}, requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters));
9526
9062
  }
9527
9063
  };
9528
-
9529
9064
  var requestBuilder_1 = requestBuilder;
9530
9065
 
9531
- var version = '3.13.2';
9066
+ var version = '3.13.3';
9532
9067
 
9533
9068
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
9534
9069
 
@@ -9639,7 +9174,6 @@
9639
9174
  if (typeof client.addAlgoliaAgent === 'function') {
9640
9175
  client.addAlgoliaAgent('JS Helper (' + version + ')');
9641
9176
  }
9642
-
9643
9177
  this.setClient(client);
9644
9178
  var opts = options || {};
9645
9179
  opts.index = index;
@@ -9650,7 +9184,6 @@
9650
9184
  this.derivedHelpers = [];
9651
9185
  this._currentNbQueries = 0;
9652
9186
  }
9653
-
9654
9187
  inherits_1(AlgoliaSearchHelper, events);
9655
9188
 
9656
9189
  /**
@@ -9658,19 +9191,22 @@
9658
9191
  * method is called, it triggers a `search` event. The results will
9659
9192
  * be available through the `result` event. If an error occurs, an
9660
9193
  * `error` will be fired instead.
9661
- * @return {AlgoliaSearchHelper}
9194
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9662
9195
  * @fires search
9663
9196
  * @fires result
9664
9197
  * @fires error
9665
9198
  * @chainable
9666
9199
  */
9667
- AlgoliaSearchHelper.prototype.search = function() {
9668
- this._search({onlyWithDerivedHelpers: false});
9200
+ AlgoliaSearchHelper.prototype.search = function () {
9201
+ this._search({
9202
+ onlyWithDerivedHelpers: false
9203
+ });
9669
9204
  return this;
9670
9205
  };
9671
-
9672
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
9673
- this._search({onlyWithDerivedHelpers: true});
9206
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
9207
+ this._search({
9208
+ onlyWithDerivedHelpers: true
9209
+ });
9674
9210
  return this;
9675
9211
  };
9676
9212
 
@@ -9679,7 +9215,7 @@
9679
9215
  * for the hits
9680
9216
  * @return {object} Query Parameters
9681
9217
  */
9682
- AlgoliaSearchHelper.prototype.getQuery = function() {
9218
+ AlgoliaSearchHelper.prototype.getQuery = function () {
9683
9219
  var state = this.state;
9684
9220
  return requestBuilder_1._getHitsSearchParams(state);
9685
9221
  };
@@ -9691,7 +9227,7 @@
9691
9227
  * same as a search call before calling searchOnce.
9692
9228
  * @param {object} options can contain all the parameters that can be set to SearchParameters
9693
9229
  * plus the index
9694
- * @param {function} [callback] optional callback executed when the response from the
9230
+ * @param {function} [cb] optional callback executed when the response from the
9695
9231
  * server is back.
9696
9232
  * @return {promise|undefined} if a callback is passed the method returns undefined
9697
9233
  * otherwise it returns a promise containing an object with two keys :
@@ -9720,41 +9256,32 @@
9720
9256
  * // }
9721
9257
  * }
9722
9258
  */
9723
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
9259
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
9724
9260
  var tempState = !options ? this.state : this.state.setQueryParameters(options);
9725
9261
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
9262
+ // eslint-disable-next-line consistent-this
9726
9263
  var self = this;
9727
-
9728
9264
  this._currentNbQueries++;
9729
-
9730
9265
  this.emit('searchOnce', {
9731
9266
  state: tempState
9732
9267
  });
9733
-
9734
9268
  if (cb) {
9735
- this.client
9736
- .search(queries)
9737
- .then(function(content) {
9738
- self._currentNbQueries--;
9739
- if (self._currentNbQueries === 0) {
9740
- self.emit('searchQueueEmpty');
9741
- }
9742
-
9743
- cb(null, new SearchResults_1(tempState, content.results), tempState);
9744
- })
9745
- .catch(function(err) {
9746
- self._currentNbQueries--;
9747
- if (self._currentNbQueries === 0) {
9748
- self.emit('searchQueueEmpty');
9749
- }
9750
-
9751
- cb(err, null, tempState);
9752
- });
9753
-
9269
+ this.client.search(queries).then(function (content) {
9270
+ self._currentNbQueries--;
9271
+ if (self._currentNbQueries === 0) {
9272
+ self.emit('searchQueueEmpty');
9273
+ }
9274
+ cb(null, new SearchResults_1(tempState, content.results), tempState);
9275
+ }).catch(function (err) {
9276
+ self._currentNbQueries--;
9277
+ if (self._currentNbQueries === 0) {
9278
+ self.emit('searchQueueEmpty');
9279
+ }
9280
+ cb(err, null, tempState);
9281
+ });
9754
9282
  return undefined;
9755
9283
  }
9756
-
9757
- return this.client.search(queries).then(function(content) {
9284
+ return this.client.search(queries).then(function (content) {
9758
9285
  self._currentNbQueries--;
9759
9286
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9760
9287
  return {
@@ -9762,14 +9289,14 @@
9762
9289
  state: tempState,
9763
9290
  _originalResponse: content
9764
9291
  };
9765
- }, function(e) {
9292
+ }, function (e) {
9766
9293
  self._currentNbQueries--;
9767
9294
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9768
9295
  throw e;
9769
9296
  });
9770
9297
  };
9771
9298
 
9772
- /**
9299
+ /**
9773
9300
  * Start the search for answers with the parameters set in the state.
9774
9301
  * This method returns a promise.
9775
9302
  * @param {Object} options - the options for answers API call
@@ -9780,7 +9307,8 @@
9780
9307
  * @return {promise} the answer results
9781
9308
  * @deprecated answers is deprecated and will be replaced with new initiatives
9782
9309
  */
9783
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
9310
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
9311
+ // eslint-disable-next-line no-console
9784
9312
  console.warn('[algoliasearch-helper] answers is no longer supported');
9785
9313
  var state = this.state;
9786
9314
  var derivedHelper = this.derivedHelpers[0];
@@ -9788,21 +9316,12 @@
9788
9316
  return Promise.resolve([]);
9789
9317
  }
9790
9318
  var derivedState = derivedHelper.getModifiedState(state);
9791
- var data = merge_1(
9792
- {
9793
- attributesForPrediction: options.attributesForPrediction,
9794
- nbHits: options.nbHits
9795
- },
9796
- {
9797
- params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
9798
- 'attributesToSnippet',
9799
- 'hitsPerPage',
9800
- 'restrictSearchableAttributes',
9801
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
9802
- ])
9803
- }
9804
- );
9805
-
9319
+ var data = merge$1({
9320
+ attributesForPrediction: options.attributesForPrediction,
9321
+ nbHits: options.nbHits
9322
+ }, {
9323
+ params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), ['attributesToSnippet', 'hitsPerPage', 'restrictSearchableAttributes', 'snippetEllipsisText'])
9324
+ });
9806
9325
  var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
9807
9326
  if (typeof this.client.initIndex !== 'function') {
9808
9327
  throw new Error(errorMessage);
@@ -9848,75 +9367,56 @@
9848
9367
  * it in the generated query.
9849
9368
  * @return {promise.<FacetSearchResult>} the results of the search
9850
9369
  */
9851
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
9370
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (facet, query, maxFacetHits, userState) {
9852
9371
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
9853
9372
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
9854
- if (
9855
- !clientHasSFFV &&
9856
- !clientHasInitIndex &&
9857
- typeof this.client.search !== 'function'
9858
- ) {
9859
- throw new Error(
9860
- 'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
9861
- );
9373
+ if (!clientHasSFFV && !clientHasInitIndex && typeof this.client.search !== 'function') {
9374
+ throw new Error('search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues');
9862
9375
  }
9863
-
9864
9376
  var state = this.state.setQueryParameters(userState || {});
9865
9377
  var isDisjunctive = state.isDisjunctiveFacet(facet);
9866
9378
  var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
9867
-
9868
9379
  this._currentNbQueries++;
9380
+ // eslint-disable-next-line consistent-this
9869
9381
  var self = this;
9870
9382
  var searchForFacetValuesPromise;
9871
9383
  // newer algoliasearch ^3.27.1 - ~4.0.0
9872
9384
  if (clientHasSFFV) {
9873
- searchForFacetValuesPromise = this.client.searchForFacetValues([
9874
- {indexName: state.index, params: algoliaQuery}
9875
- ]);
9385
+ searchForFacetValuesPromise = this.client.searchForFacetValues([{
9386
+ indexName: state.index,
9387
+ params: algoliaQuery
9388
+ }]);
9876
9389
  // algoliasearch < 3.27.1
9877
9390
  } else if (clientHasInitIndex) {
9878
- searchForFacetValuesPromise = this.client
9879
- .initIndex(state.index)
9880
- .searchForFacetValues(algoliaQuery);
9391
+ searchForFacetValuesPromise = this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
9881
9392
  // algoliasearch ~5.0.0
9882
9393
  } else {
9883
9394
  // @MAJOR only use client.search
9884
9395
  delete algoliaQuery.facetName;
9885
- searchForFacetValuesPromise = this.client
9886
- .search([
9887
- {
9888
- type: 'facet',
9889
- facet: facet,
9890
- indexName: state.index,
9891
- params: algoliaQuery
9892
- }
9893
- ])
9894
- .then(function processResponse(response) {
9895
- return response.results[0];
9896
- });
9396
+ searchForFacetValuesPromise = this.client.search([{
9397
+ type: 'facet',
9398
+ facet: facet,
9399
+ indexName: state.index,
9400
+ params: algoliaQuery
9401
+ }]).then(function processResponse(response) {
9402
+ return response.results[0];
9403
+ });
9897
9404
  }
9898
-
9899
9405
  this.emit('searchForFacetValues', {
9900
9406
  state: state,
9901
9407
  facet: facet,
9902
9408
  query: query
9903
9409
  });
9904
-
9905
9410
  return searchForFacetValuesPromise.then(function addIsRefined(content) {
9906
9411
  self._currentNbQueries--;
9907
9412
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9908
-
9909
9413
  content = Array.isArray(content) ? content[0] : content;
9910
-
9911
- content.facetHits.forEach(function(f) {
9414
+ content.facetHits.forEach(function (f) {
9912
9415
  f.escapedValue = escapeFacetValue$4(f.value);
9913
- f.isRefined = isDisjunctive
9914
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
9915
- : state.isFacetRefined(facet, f.escapedValue);
9416
+ f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
9916
9417
  });
9917
-
9918
9418
  return content;
9919
- }, function(e) {
9419
+ }, function (e) {
9920
9420
  self._currentNbQueries--;
9921
9421
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
9922
9422
  throw e;
@@ -9928,16 +9428,15 @@
9928
9428
  *
9929
9429
  * This method resets the current page to 0.
9930
9430
  * @param {string} q the user query
9931
- * @return {AlgoliaSearchHelper}
9431
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9932
9432
  * @fires change
9933
9433
  * @chainable
9934
9434
  */
9935
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
9435
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
9936
9436
  this._change({
9937
9437
  state: this.state.resetPage().setQuery(q),
9938
9438
  isPageReset: true
9939
9439
  });
9940
-
9941
9440
  return this;
9942
9441
  };
9943
9442
 
@@ -9949,7 +9448,7 @@
9949
9448
  *
9950
9449
  * This method resets the current page to 0.
9951
9450
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
9952
- * @return {AlgoliaSearchHelper}
9451
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9953
9452
  * @fires change
9954
9453
  * @chainable
9955
9454
  * @example
@@ -9964,12 +9463,11 @@
9964
9463
  * return type === 'exclude' && attribute === 'category';
9965
9464
  * }).search();
9966
9465
  */
9967
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
9466
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
9968
9467
  this._change({
9969
9468
  state: this.state.resetPage().clearRefinements(name),
9970
9469
  isPageReset: true
9971
9470
  });
9972
-
9973
9471
  return this;
9974
9472
  };
9975
9473
 
@@ -9977,16 +9475,15 @@
9977
9475
  * Remove all the tag filters.
9978
9476
  *
9979
9477
  * This method resets the current page to 0.
9980
- * @return {AlgoliaSearchHelper}
9478
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9981
9479
  * @fires change
9982
9480
  * @chainable
9983
9481
  */
9984
- AlgoliaSearchHelper.prototype.clearTags = function() {
9482
+ AlgoliaSearchHelper.prototype.clearTags = function () {
9985
9483
  this._change({
9986
9484
  state: this.state.resetPage().clearTags(),
9987
9485
  isPageReset: true
9988
9486
  });
9989
-
9990
9487
  return this;
9991
9488
  };
9992
9489
 
@@ -9997,23 +9494,23 @@
9997
9494
  * This method resets the current page to 0.
9998
9495
  * @param {string} facet the facet to refine
9999
9496
  * @param {string} value the associated value (will be converted to string)
10000
- * @return {AlgoliaSearchHelper}
9497
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10001
9498
  * @fires change
10002
9499
  * @chainable
10003
9500
  */
10004
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
9501
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (facet, value) {
10005
9502
  this._change({
10006
9503
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
10007
9504
  isPageReset: true
10008
9505
  });
10009
-
10010
9506
  return this;
10011
9507
  };
10012
9508
 
9509
+ // eslint-disable-next-line valid-jsdoc
10013
9510
  /**
10014
9511
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
10015
9512
  */
10016
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
9513
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
10017
9514
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
10018
9515
  };
10019
9516
 
@@ -10025,17 +9522,16 @@
10025
9522
  * This method resets the current page to 0.
10026
9523
  * @param {string} facet the facet name
10027
9524
  * @param {string} path the hierarchical facet path
10028
- * @return {AlgoliaSearchHelper}
9525
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10029
9526
  * @throws Error if the facet is not defined or if the facet is refined
10030
9527
  * @chainable
10031
9528
  * @fires change
10032
9529
  */
10033
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
9530
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (facet, path) {
10034
9531
  this._change({
10035
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
9532
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
10036
9533
  isPageReset: true
10037
9534
  });
10038
-
10039
9535
  return this;
10040
9536
  };
10041
9537
 
@@ -10047,16 +9543,15 @@
10047
9543
  * @param {string} attribute the attribute on which the numeric filter applies
10048
9544
  * @param {string} operator the operator of the filter
10049
9545
  * @param {number} value the value of the filter
10050
- * @return {AlgoliaSearchHelper}
9546
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10051
9547
  * @fires change
10052
9548
  * @chainable
10053
9549
  */
10054
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
9550
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (attribute, operator, value) {
10055
9551
  this._change({
10056
9552
  state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
10057
9553
  isPageReset: true
10058
9554
  });
10059
-
10060
9555
  return this;
10061
9556
  };
10062
9557
 
@@ -10067,27 +9562,26 @@
10067
9562
  * This method resets the current page to 0.
10068
9563
  * @param {string} facet the facet to refine
10069
9564
  * @param {string} value the associated value (will be converted to string)
10070
- * @return {AlgoliaSearchHelper}
9565
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10071
9566
  * @fires change
10072
9567
  * @chainable
10073
9568
  */
10074
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
9569
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
10075
9570
  this._change({
10076
9571
  state: this.state.resetPage().addFacetRefinement(facet, value),
10077
9572
  isPageReset: true
10078
9573
  });
10079
-
10080
9574
  return this;
10081
9575
  };
10082
9576
 
9577
+ // eslint-disable-next-line valid-jsdoc
10083
9578
  /**
10084
9579
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
10085
9580
  */
10086
- AlgoliaSearchHelper.prototype.addRefine = function() {
9581
+ AlgoliaSearchHelper.prototype.addRefine = function () {
10087
9582
  return this.addFacetRefinement.apply(this, arguments);
10088
9583
  };
10089
9584
 
10090
-
10091
9585
  /**
10092
9586
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
10093
9587
  * filter is already set, it doesn't change the filters.
@@ -10095,23 +9589,23 @@
10095
9589
  * This method resets the current page to 0.
10096
9590
  * @param {string} facet the facet to refine
10097
9591
  * @param {string} value the associated value (will be converted to string)
10098
- * @return {AlgoliaSearchHelper}
9592
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10099
9593
  * @fires change
10100
9594
  * @chainable
10101
9595
  */
10102
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
9596
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
10103
9597
  this._change({
10104
9598
  state: this.state.resetPage().addExcludeRefinement(facet, value),
10105
9599
  isPageReset: true
10106
9600
  });
10107
-
10108
9601
  return this;
10109
9602
  };
10110
9603
 
9604
+ // eslint-disable-next-line valid-jsdoc
10111
9605
  /**
10112
9606
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
10113
9607
  */
10114
- AlgoliaSearchHelper.prototype.addExclude = function() {
9608
+ AlgoliaSearchHelper.prototype.addExclude = function () {
10115
9609
  return this.addFacetExclusion.apply(this, arguments);
10116
9610
  };
10117
9611
 
@@ -10121,16 +9615,15 @@
10121
9615
  *
10122
9616
  * This method resets the current page to 0.
10123
9617
  * @param {string} tag the tag to add to the filter
10124
- * @return {AlgoliaSearchHelper}
9618
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10125
9619
  * @fires change
10126
9620
  * @chainable
10127
9621
  */
10128
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
9622
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
10129
9623
  this._change({
10130
9624
  state: this.state.resetPage().addTagRefinement(tag),
10131
9625
  isPageReset: true
10132
9626
  });
10133
-
10134
9627
  return this;
10135
9628
  };
10136
9629
 
@@ -10148,16 +9641,15 @@
10148
9641
  * @param {string} attribute the attribute on which the numeric filter applies
10149
9642
  * @param {string} [operator] the operator of the filter
10150
9643
  * @param {number} [value] the value of the filter
10151
- * @return {AlgoliaSearchHelper}
9644
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10152
9645
  * @fires change
10153
9646
  * @chainable
10154
9647
  */
10155
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
9648
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (attribute, operator, value) {
10156
9649
  this._change({
10157
9650
  state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
10158
9651
  isPageReset: true
10159
9652
  });
10160
-
10161
9653
  return this;
10162
9654
  };
10163
9655
 
@@ -10171,40 +9663,39 @@
10171
9663
  * This method resets the current page to 0.
10172
9664
  * @param {string} facet the facet to refine
10173
9665
  * @param {string} [value] the associated value
10174
- * @return {AlgoliaSearchHelper}
9666
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10175
9667
  * @fires change
10176
9668
  * @chainable
10177
9669
  */
10178
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
9670
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (facet, value) {
10179
9671
  this._change({
10180
9672
  state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
10181
9673
  isPageReset: true
10182
9674
  });
10183
-
10184
9675
  return this;
10185
9676
  };
10186
9677
 
9678
+ // eslint-disable-next-line valid-jsdoc
10187
9679
  /**
10188
9680
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
10189
9681
  */
10190
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
9682
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
10191
9683
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
10192
9684
  };
10193
9685
 
10194
9686
  /**
10195
9687
  * Removes the refinement set on a hierarchical facet.
10196
9688
  * @param {string} facet the facet name
10197
- * @return {AlgoliaSearchHelper}
9689
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10198
9690
  * @throws Error if the facet is not defined or if the facet is not refined
10199
9691
  * @fires change
10200
9692
  * @chainable
10201
9693
  */
10202
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
9694
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (facet) {
10203
9695
  this._change({
10204
9696
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
10205
9697
  isPageReset: true
10206
9698
  });
10207
-
10208
9699
  return this;
10209
9700
  };
10210
9701
 
@@ -10218,23 +9709,23 @@
10218
9709
  * This method resets the current page to 0.
10219
9710
  * @param {string} facet the facet to refine
10220
9711
  * @param {string} [value] the associated value
10221
- * @return {AlgoliaSearchHelper}
9712
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10222
9713
  * @fires change
10223
9714
  * @chainable
10224
9715
  */
10225
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
9716
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
10226
9717
  this._change({
10227
9718
  state: this.state.resetPage().removeFacetRefinement(facet, value),
10228
9719
  isPageReset: true
10229
9720
  });
10230
-
10231
9721
  return this;
10232
9722
  };
10233
9723
 
9724
+ // eslint-disable-next-line valid-jsdoc
10234
9725
  /**
10235
9726
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
10236
9727
  */
10237
- AlgoliaSearchHelper.prototype.removeRefine = function() {
9728
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
10238
9729
  return this.removeFacetRefinement.apply(this, arguments);
10239
9730
  };
10240
9731
 
@@ -10248,23 +9739,23 @@
10248
9739
  * This method resets the current page to 0.
10249
9740
  * @param {string} facet the facet to refine
10250
9741
  * @param {string} [value] the associated value
10251
- * @return {AlgoliaSearchHelper}
9742
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10252
9743
  * @fires change
10253
9744
  * @chainable
10254
9745
  */
10255
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
9746
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
10256
9747
  this._change({
10257
9748
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
10258
9749
  isPageReset: true
10259
9750
  });
10260
-
10261
9751
  return this;
10262
9752
  };
10263
9753
 
9754
+ // eslint-disable-next-line valid-jsdoc
10264
9755
  /**
10265
9756
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
10266
9757
  */
10267
- AlgoliaSearchHelper.prototype.removeExclude = function() {
9758
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
10268
9759
  return this.removeFacetExclusion.apply(this, arguments);
10269
9760
  };
10270
9761
 
@@ -10274,16 +9765,15 @@
10274
9765
  *
10275
9766
  * This method resets the current page to 0.
10276
9767
  * @param {string} tag tag to remove from the filter
10277
- * @return {AlgoliaSearchHelper}
9768
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10278
9769
  * @fires change
10279
9770
  * @chainable
10280
9771
  */
10281
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
9772
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
10282
9773
  this._change({
10283
9774
  state: this.state.resetPage().removeTagRefinement(tag),
10284
9775
  isPageReset: true
10285
9776
  });
10286
-
10287
9777
  return this;
10288
9778
  };
10289
9779
 
@@ -10294,23 +9784,23 @@
10294
9784
  * This method resets the current page to 0.
10295
9785
  * @param {string} facet the facet to refine
10296
9786
  * @param {string} value the associated value
10297
- * @return {AlgoliaSearchHelper}
9787
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10298
9788
  * @fires change
10299
9789
  * @chainable
10300
9790
  */
10301
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
9791
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
10302
9792
  this._change({
10303
9793
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
10304
9794
  isPageReset: true
10305
9795
  });
10306
-
10307
9796
  return this;
10308
9797
  };
10309
9798
 
9799
+ // eslint-disable-next-line valid-jsdoc
10310
9800
  /**
10311
9801
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
10312
9802
  */
10313
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
9803
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
10314
9804
  return this.toggleFacetExclusion.apply(this, arguments);
10315
9805
  };
10316
9806
 
@@ -10323,13 +9813,13 @@
10323
9813
  * This method resets the current page to 0.
10324
9814
  * @param {string} facet the facet to refine
10325
9815
  * @param {string} value the associated value
10326
- * @return {AlgoliaSearchHelper}
9816
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10327
9817
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
10328
9818
  * @fires change
10329
9819
  * @chainable
10330
9820
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
10331
9821
  */
10332
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
9822
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
10333
9823
  return this.toggleFacetRefinement(facet, value);
10334
9824
  };
10335
9825
 
@@ -10342,24 +9832,24 @@
10342
9832
  * This method resets the current page to 0.
10343
9833
  * @param {string} facet the facet to refine
10344
9834
  * @param {string} value the associated value
10345
- * @return {AlgoliaSearchHelper}
9835
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10346
9836
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
10347
9837
  * @fires change
10348
9838
  * @chainable
10349
9839
  */
10350
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
9840
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
10351
9841
  this._change({
10352
9842
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
10353
9843
  isPageReset: true
10354
9844
  });
10355
-
10356
9845
  return this;
10357
9846
  };
10358
9847
 
9848
+ // eslint-disable-next-line valid-jsdoc
10359
9849
  /**
10360
9850
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
10361
9851
  */
10362
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
9852
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
10363
9853
  return this.toggleFacetRefinement.apply(this, arguments);
10364
9854
  };
10365
9855
 
@@ -10369,29 +9859,28 @@
10369
9859
  *
10370
9860
  * This method resets the current page to 0.
10371
9861
  * @param {string} tag tag to remove or add
10372
- * @return {AlgoliaSearchHelper}
9862
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10373
9863
  * @fires change
10374
9864
  * @chainable
10375
9865
  */
10376
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
9866
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
10377
9867
  this._change({
10378
9868
  state: this.state.resetPage().toggleTagRefinement(tag),
10379
9869
  isPageReset: true
10380
9870
  });
10381
-
10382
9871
  return this;
10383
9872
  };
10384
9873
 
10385
9874
  /**
10386
9875
  * Increments the page number by one.
10387
- * @return {AlgoliaSearchHelper}
9876
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10388
9877
  * @fires change
10389
9878
  * @chainable
10390
9879
  * @example
10391
9880
  * helper.setPage(0).nextPage().getPage();
10392
9881
  * // returns 1
10393
9882
  */
10394
- AlgoliaSearchHelper.prototype.nextPage = function() {
9883
+ AlgoliaSearchHelper.prototype.nextPage = function () {
10395
9884
  var page = this.state.page || 0;
10396
9885
  return this.setPage(page + 1);
10397
9886
  };
@@ -10399,28 +9888,30 @@
10399
9888
  /**
10400
9889
  * Decrements the page number by one.
10401
9890
  * @fires change
10402
- * @return {AlgoliaSearchHelper}
9891
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10403
9892
  * @chainable
10404
9893
  * @example
10405
9894
  * helper.setPage(1).previousPage().getPage();
10406
9895
  * // returns 0
10407
9896
  */
10408
- AlgoliaSearchHelper.prototype.previousPage = function() {
9897
+ AlgoliaSearchHelper.prototype.previousPage = function () {
10409
9898
  var page = this.state.page || 0;
10410
9899
  return this.setPage(page - 1);
10411
9900
  };
10412
9901
 
10413
9902
  /**
10414
9903
  * @private
9904
+ * @param {number} page The page number
9905
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
9906
+ * @chainable
9907
+ * @fires change
10415
9908
  */
10416
9909
  function setCurrentPage(page) {
10417
9910
  if (page < 0) throw new Error('Page requested below 0.');
10418
-
10419
9911
  this._change({
10420
9912
  state: this.state.setPage(page),
10421
9913
  isPageReset: false
10422
9914
  });
10423
-
10424
9915
  return this;
10425
9916
  }
10426
9917
 
@@ -10428,7 +9919,7 @@
10428
9919
  * Change the current page
10429
9920
  * @deprecated
10430
9921
  * @param {number} page The page number
10431
- * @return {AlgoliaSearchHelper}
9922
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10432
9923
  * @fires change
10433
9924
  * @chainable
10434
9925
  */
@@ -10438,7 +9929,7 @@
10438
9929
  * Updates the current page.
10439
9930
  * @function
10440
9931
  * @param {number} page The page number
10441
- * @return {AlgoliaSearchHelper}
9932
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10442
9933
  * @fires change
10443
9934
  * @chainable
10444
9935
  */
@@ -10449,16 +9940,15 @@
10449
9940
  *
10450
9941
  * This method resets the current page to 0.
10451
9942
  * @param {string} name the index name
10452
- * @return {AlgoliaSearchHelper}
9943
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10453
9944
  * @fires change
10454
9945
  * @chainable
10455
9946
  */
10456
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
9947
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
10457
9948
  this._change({
10458
9949
  state: this.state.resetPage().setIndex(name),
10459
9950
  isPageReset: true
10460
9951
  });
10461
-
10462
9952
  return this;
10463
9953
  };
10464
9954
 
@@ -10473,34 +9963,32 @@
10473
9963
  * This method resets the current page to 0.
10474
9964
  * @param {string} parameter name of the parameter to update
10475
9965
  * @param {any} value new value of the parameter
10476
- * @return {AlgoliaSearchHelper}
9966
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10477
9967
  * @fires change
10478
9968
  * @chainable
10479
9969
  * @example
10480
9970
  * helper.setQueryParameter('hitsPerPage', 20).search();
10481
9971
  */
10482
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
9972
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
10483
9973
  this._change({
10484
9974
  state: this.state.resetPage().setQueryParameter(parameter, value),
10485
9975
  isPageReset: true
10486
9976
  });
10487
-
10488
9977
  return this;
10489
9978
  };
10490
9979
 
10491
9980
  /**
10492
9981
  * Set the whole state (warning: will erase previous state)
10493
9982
  * @param {SearchParameters} newState the whole new state
10494
- * @return {AlgoliaSearchHelper}
9983
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10495
9984
  * @fires change
10496
9985
  * @chainable
10497
9986
  */
10498
- AlgoliaSearchHelper.prototype.setState = function(newState) {
9987
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
10499
9988
  this._change({
10500
9989
  state: SearchParameters_1.make(newState),
10501
9990
  isPageReset: false
10502
9991
  });
10503
-
10504
9992
  return this;
10505
9993
  };
10506
9994
 
@@ -10509,7 +9997,7 @@
10509
9997
  * Do not use this method unless you know what you are doing. (see the example
10510
9998
  * for a legit use case)
10511
9999
  * @param {SearchParameters} newState the whole new state
10512
- * @return {AlgoliaSearchHelper}
10000
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10513
10001
  * @example
10514
10002
  * helper.on('change', function(state){
10515
10003
  * // In this function you might want to find a way to store the state in the url/history
@@ -10521,7 +10009,7 @@
10521
10009
  * }
10522
10010
  * @chainable
10523
10011
  */
10524
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
10012
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function (newState) {
10525
10013
  this.state = new SearchParameters_1(newState);
10526
10014
  return this;
10527
10015
  };
@@ -10549,7 +10037,7 @@
10549
10037
  * helper.hasRefinements('categories'); // true
10550
10038
  *
10551
10039
  */
10552
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
10040
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
10553
10041
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
10554
10042
  return true;
10555
10043
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -10574,7 +10062,7 @@
10574
10062
  *
10575
10063
  * @param {string} facet name of the attribute for used for faceting
10576
10064
  * @param {string} [value] optional value. If passed will test that this value
10577
- * is filtering the given facet.
10065
+ * is filtering the given facet.
10578
10066
  * @return {boolean} true if refined
10579
10067
  * @example
10580
10068
  * helper.isExcludeRefined('color'); // false
@@ -10587,45 +10075,45 @@
10587
10075
  * helper.isExcludeRefined('color', 'blue') // false
10588
10076
  * helper.isExcludeRefined('color', 'red') // true
10589
10077
  */
10590
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
10078
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
10591
10079
  return this.state.isExcludeRefined(facet, value);
10592
10080
  };
10593
10081
 
10082
+ // eslint-disable-next-line valid-jsdoc
10594
10083
  /**
10595
10084
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
10596
10085
  */
10597
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
10086
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
10598
10087
  return this.state.isDisjunctiveFacetRefined(facet, value);
10599
10088
  };
10600
10089
 
10601
10090
  /**
10602
10091
  * Check if the string is a currently filtering tag.
10603
10092
  * @param {string} tag tag to check
10604
- * @return {boolean}
10093
+ * @return {boolean} true if the tag is currently refined
10605
10094
  */
10606
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
10095
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
10607
10096
  return this.state.isTagRefined(tag);
10608
10097
  };
10609
10098
 
10099
+ // eslint-disable-next-line valid-jsdoc
10610
10100
  /**
10611
10101
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
10612
10102
  */
10613
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
10103
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
10614
10104
  return this.hasTagRefinements.apply(this, arguments);
10615
10105
  };
10616
10106
 
10617
-
10618
10107
  /**
10619
10108
  * Get the name of the currently used index.
10620
- * @return {string}
10109
+ * @return {string} name of the index
10621
10110
  * @example
10622
10111
  * helper.setIndex('highestPrice_products').getIndex();
10623
10112
  * // returns 'highestPrice_products'
10624
10113
  */
10625
- AlgoliaSearchHelper.prototype.getIndex = function() {
10114
+ AlgoliaSearchHelper.prototype.getIndex = function () {
10626
10115
  return this.state.index;
10627
10116
  };
10628
-
10629
10117
  function getCurrentPage() {
10630
10118
  return this.state.page;
10631
10119
  }
@@ -10648,7 +10136,7 @@
10648
10136
  *
10649
10137
  * @return {string[]} The list of tags currently set.
10650
10138
  */
10651
- AlgoliaSearchHelper.prototype.getTags = function() {
10139
+ AlgoliaSearchHelper.prototype.getTags = function () {
10652
10140
  return this.state.tagRefinements;
10653
10141
  };
10654
10142
 
@@ -10696,50 +10184,41 @@
10696
10184
  * // }
10697
10185
  * // ]
10698
10186
  */
10699
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
10187
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
10700
10188
  var refinements = [];
10701
-
10702
10189
  if (this.state.isConjunctiveFacet(facetName)) {
10703
10190
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
10704
-
10705
- conjRefinements.forEach(function(r) {
10191
+ conjRefinements.forEach(function (r) {
10706
10192
  refinements.push({
10707
10193
  value: r,
10708
10194
  type: 'conjunctive'
10709
10195
  });
10710
10196
  });
10711
-
10712
10197
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
10713
-
10714
- excludeRefinements.forEach(function(r) {
10198
+ excludeRefinements.forEach(function (r) {
10715
10199
  refinements.push({
10716
10200
  value: r,
10717
10201
  type: 'exclude'
10718
10202
  });
10719
10203
  });
10720
10204
  } else if (this.state.isDisjunctiveFacet(facetName)) {
10721
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
10722
-
10723
- disjRefinements.forEach(function(r) {
10205
+ var disjunctiveRefinements = this.state.getDisjunctiveRefinements(facetName);
10206
+ disjunctiveRefinements.forEach(function (r) {
10724
10207
  refinements.push({
10725
10208
  value: r,
10726
10209
  type: 'disjunctive'
10727
10210
  });
10728
10211
  });
10729
10212
  }
10730
-
10731
10213
  var numericRefinements = this.state.getNumericRefinements(facetName);
10732
-
10733
- Object.keys(numericRefinements).forEach(function(operator) {
10214
+ Object.keys(numericRefinements).forEach(function (operator) {
10734
10215
  var value = numericRefinements[operator];
10735
-
10736
10216
  refinements.push({
10737
10217
  value: value,
10738
10218
  operator: operator,
10739
10219
  type: 'numeric'
10740
10220
  });
10741
10221
  });
10742
-
10743
10222
  return refinements;
10744
10223
  };
10745
10224
 
@@ -10749,7 +10228,7 @@
10749
10228
  * @param {string} operator operator applied on the refined values
10750
10229
  * @return {Array.<number|number[]>} refined values
10751
10230
  */
10752
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
10231
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (attribute, operator) {
10753
10232
  return this.state.getNumericRefinement(attribute, operator);
10754
10233
  };
10755
10234
 
@@ -10758,7 +10237,7 @@
10758
10237
  * @param {string} facetName Hierarchical facet name
10759
10238
  * @return {array.<string>} the path as an array of string
10760
10239
  */
10761
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
10240
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (facetName) {
10762
10241
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
10763
10242
  };
10764
10243
 
@@ -10767,72 +10246,60 @@
10767
10246
  /**
10768
10247
  * Perform the underlying queries
10769
10248
  * @private
10770
- * @return {undefined}
10249
+ * @param {object} options options for the query
10250
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
10251
+ * @return {undefined} does not return anything
10771
10252
  * @fires search
10772
10253
  * @fires result
10773
10254
  * @fires error
10774
10255
  */
10775
- AlgoliaSearchHelper.prototype._search = function(options) {
10256
+ AlgoliaSearchHelper.prototype._search = function (options) {
10776
10257
  var state = this.state;
10777
10258
  var states = [];
10778
10259
  var mainQueries = [];
10779
-
10780
10260
  if (!options.onlyWithDerivedHelpers) {
10781
10261
  mainQueries = requestBuilder_1._getQueries(state.index, state);
10782
-
10783
10262
  states.push({
10784
10263
  state: state,
10785
10264
  queriesCount: mainQueries.length,
10786
10265
  helper: this
10787
10266
  });
10788
-
10789
10267
  this.emit('search', {
10790
10268
  state: state,
10791
10269
  results: this.lastResults
10792
10270
  });
10793
10271
  }
10794
-
10795
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
10272
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
10796
10273
  var derivedState = derivedHelper.getModifiedState(state);
10797
- var derivedStateQueries = derivedState.index
10798
- ? requestBuilder_1._getQueries(derivedState.index, derivedState)
10799
- : [];
10800
-
10274
+ var derivedStateQueries = derivedState.index ? requestBuilder_1._getQueries(derivedState.index, derivedState) : [];
10801
10275
  states.push({
10802
10276
  state: derivedState,
10803
10277
  queriesCount: derivedStateQueries.length,
10804
10278
  helper: derivedHelper
10805
10279
  });
10806
-
10807
10280
  derivedHelper.emit('search', {
10808
10281
  state: derivedState,
10809
10282
  results: derivedHelper.lastResults
10810
10283
  });
10811
-
10812
10284
  return derivedStateQueries;
10813
10285
  });
10814
-
10815
10286
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
10816
-
10817
10287
  var queryId = this._queryId++;
10818
10288
  this._currentNbQueries++;
10819
-
10820
10289
  if (!queries.length) {
10821
- return Promise.resolve({results: []}).then(
10822
- this._dispatchAlgoliaResponse.bind(this, states, queryId)
10823
- );
10290
+ return Promise.resolve({
10291
+ results: []
10292
+ }).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
10824
10293
  }
10825
-
10826
10294
  try {
10827
- this.client.search(queries)
10828
- .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
10829
- .catch(this._dispatchAlgoliaError.bind(this, queryId));
10295
+ this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
10830
10296
  } catch (error) {
10831
10297
  // If we reach this part, we're in an internal error state
10832
10298
  this.emit('error', {
10833
10299
  error: error
10834
10300
  });
10835
10301
  }
10302
+ return undefined;
10836
10303
  };
10837
10304
 
10838
10305
  /**
@@ -10840,33 +10307,27 @@
10840
10307
  * usable object that merge the results of all the batch requests. It will dispatch
10841
10308
  * over the different helper + derived helpers (when there are some).
10842
10309
  * @private
10843
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
10844
- * state state used for to generate the request
10310
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
10845
10311
  * @param {number} queryId id of the current request
10846
10312
  * @param {object} content content of the response
10847
10313
  * @return {undefined}
10848
10314
  */
10849
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
10850
- // FIXME remove the number of outdated queries discarded instead of just one
10315
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (states, queryId, content) {
10316
+ // @TODO remove the number of outdated queries discarded instead of just one
10851
10317
 
10852
10318
  if (queryId < this._lastQueryIdReceived) {
10853
10319
  // Outdated answer
10854
10320
  return;
10855
10321
  }
10856
-
10857
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
10322
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
10858
10323
  this._lastQueryIdReceived = queryId;
10859
-
10860
10324
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
10861
-
10862
10325
  var results = content.results.slice();
10863
-
10864
- states.forEach(function(s) {
10326
+ states.forEach(function (s) {
10865
10327
  var state = s.state;
10866
10328
  var queriesCount = s.queriesCount;
10867
10329
  var helper = s.helper;
10868
10330
  var specificResults = results.splice(0, queriesCount);
10869
-
10870
10331
  if (!state.index) {
10871
10332
  helper.emit('result', {
10872
10333
  results: null,
@@ -10874,57 +10335,43 @@
10874
10335
  });
10875
10336
  return;
10876
10337
  }
10877
-
10878
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
10879
-
10338
+ helper.lastResults = new SearchResults_1(state, specificResults);
10880
10339
  helper.emit('result', {
10881
- results: formattedResponse,
10340
+ results: helper.lastResults,
10882
10341
  state: state
10883
10342
  });
10884
10343
  });
10885
10344
  };
10886
-
10887
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
10345
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (queryId, error) {
10888
10346
  if (queryId < this._lastQueryIdReceived) {
10889
10347
  // Outdated answer
10890
10348
  return;
10891
10349
  }
10892
-
10893
10350
  this._currentNbQueries -= queryId - this._lastQueryIdReceived;
10894
10351
  this._lastQueryIdReceived = queryId;
10895
-
10896
10352
  this.emit('error', {
10897
10353
  error: error
10898
10354
  });
10899
-
10900
10355
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
10901
10356
  };
10902
-
10903
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
10904
- return query ||
10905
- facetFilters.length !== 0 ||
10906
- numericFilters.length !== 0 ||
10907
- tagFilters.length !== 0;
10357
+ AlgoliaSearchHelper.prototype.containsRefinement = function (query, facetFilters, numericFilters, tagFilters) {
10358
+ return query || facetFilters.length !== 0 || numericFilters.length !== 0 || tagFilters.length !== 0;
10908
10359
  };
10909
10360
 
10910
10361
  /**
10911
10362
  * Test if there are some disjunctive refinements on the facet
10912
10363
  * @private
10913
10364
  * @param {string} facet the attribute to test
10914
- * @return {boolean}
10365
+ * @return {boolean} true if there are refinements on this attribute
10915
10366
  */
10916
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
10917
- return this.state.disjunctiveRefinements[facet] &&
10918
- this.state.disjunctiveRefinements[facet].length > 0;
10367
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
10368
+ return this.state.disjunctiveRefinements[facet] && this.state.disjunctiveRefinements[facet].length > 0;
10919
10369
  };
10920
-
10921
- AlgoliaSearchHelper.prototype._change = function(event) {
10370
+ AlgoliaSearchHelper.prototype._change = function (event) {
10922
10371
  var state = event.state;
10923
10372
  var isPageReset = event.isPageReset;
10924
-
10925
10373
  if (state !== this.state) {
10926
10374
  this.state = state;
10927
-
10928
10375
  this.emit('change', {
10929
10376
  state: this.state,
10930
10377
  results: this.lastResults,
@@ -10935,10 +10382,10 @@
10935
10382
 
10936
10383
  /**
10937
10384
  * Clears the cache of the underlying Algolia client.
10938
- * @return {AlgoliaSearchHelper}
10385
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10939
10386
  */
10940
- AlgoliaSearchHelper.prototype.clearCache = function() {
10941
- this.client.clearCache && this.client.clearCache();
10387
+ AlgoliaSearchHelper.prototype.clearCache = function () {
10388
+ if (this.client.clearCache) this.client.clearCache();
10942
10389
  return this;
10943
10390
  };
10944
10391
 
@@ -10946,24 +10393,22 @@
10946
10393
  * Updates the internal client instance. If the reference of the clients
10947
10394
  * are equal then no update is actually done.
10948
10395
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
10949
- * @return {AlgoliaSearchHelper}
10396
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
10950
10397
  */
10951
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
10398
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
10952
10399
  if (this.client === newClient) return this;
10953
-
10954
10400
  if (typeof newClient.addAlgoliaAgent === 'function') {
10955
10401
  newClient.addAlgoliaAgent('JS Helper (' + version + ')');
10956
10402
  }
10957
10403
  this.client = newClient;
10958
-
10959
10404
  return this;
10960
10405
  };
10961
10406
 
10962
10407
  /**
10963
10408
  * Gets the instance of the currently used client.
10964
- * @return {AlgoliaSearch}
10409
+ * @return {AlgoliaSearch} the currently used client
10965
10410
  */
10966
- AlgoliaSearchHelper.prototype.getClient = function() {
10411
+ AlgoliaSearchHelper.prototype.getClient = function () {
10967
10412
  return this.client;
10968
10413
  };
10969
10414
 
@@ -10984,9 +10429,9 @@
10984
10429
  * and the SearchParameters that is returned by the call of the
10985
10430
  * parameter function.
10986
10431
  * @param {function} fn SearchParameters -> SearchParameters
10987
- * @return {DerivedHelper}
10432
+ * @return {DerivedHelper} a new DerivedHelper
10988
10433
  */
10989
- AlgoliaSearchHelper.prototype.derive = function(fn) {
10434
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
10990
10435
  var derivedHelper = new DerivedHelper_1(this, fn);
10991
10436
  this.derivedHelpers.push(derivedHelper);
10992
10437
  return derivedHelper;
@@ -10996,10 +10441,11 @@
10996
10441
  * This method detaches a derived Helper from the main one. Prefer using the one from the
10997
10442
  * derived helper itself, to remove the event listeners too.
10998
10443
  * @private
10999
- * @return {undefined}
10444
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
10445
+ * @return {undefined} nothing is returned
11000
10446
  * @throws Error
11001
10447
  */
11002
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
10448
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
11003
10449
  var pos = this.derivedHelpers.indexOf(derivedHelper);
11004
10450
  if (pos === -1) throw new Error('Derived helper already detached');
11005
10451
  this.derivedHelpers.splice(pos, 1);
@@ -11009,7 +10455,7 @@
11009
10455
  * This method returns true if there is currently at least one on-going search.
11010
10456
  * @return {boolean} true if there is a search pending
11011
10457
  */
11012
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
10458
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
11013
10459
  return this._currentNbQueries > 0;
11014
10460
  };
11015
10461
 
@@ -11060,7 +10506,7 @@
11060
10506
  * @param {AlgoliaSearch} client an AlgoliaSearch client
11061
10507
  * @param {string} index the name of the index to query
11062
10508
  * @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}
10509
+ * @return {AlgoliaSearchHelper} The helper instance
11064
10510
  */
11065
10511
  function algoliasearchHelper(client, index, opts) {
11066
10512
  return new algoliasearch_helper(client, index, opts);
@@ -11093,7 +10539,6 @@
11093
10539
  * @type {SearchResults}
11094
10540
  */
11095
10541
  algoliasearchHelper.SearchResults = SearchResults_1;
11096
-
11097
10542
  var algoliasearchHelper_1 = algoliasearchHelper;
11098
10543
 
11099
10544
  var withUsage$l = createDocumentationMessageGenerator({
@@ -12448,7 +11893,7 @@
12448
11893
  return obj;
12449
11894
  };
12450
11895
 
12451
- var merge$1 = function merge(target, source, options) {
11896
+ var merge$2 = function merge(target, source, options) {
12452
11897
  /* eslint no-param-reassign: 0 */
12453
11898
  if (!source) {
12454
11899
  return target;
@@ -12652,7 +12097,7 @@
12652
12097
  isBuffer: isBuffer,
12653
12098
  isRegExp: isRegExp,
12654
12099
  maybeMap: maybeMap,
12655
- merge: merge$1
12100
+ merge: merge$2
12656
12101
  };
12657
12102
 
12658
12103
  var has$1 = Object.prototype.hasOwnProperty;
@@ -14143,7 +13588,7 @@
14143
13588
  };
14144
13589
  }
14145
13590
 
14146
- var version$1 = '4.56.5';
13591
+ var version$1 = '4.56.6';
14147
13592
 
14148
13593
  var withUsage$r = createDocumentationMessageGenerator({
14149
13594
  name: 'instantsearch'