react-instantsearch 6.40.1 → 6.40.3

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.
package/dist/umd/Dom.js CHANGED
@@ -870,7 +870,7 @@
870
870
  });
871
871
  }
872
872
 
873
- var version = '6.40.1';
873
+ var version = '6.40.3';
874
874
 
875
875
  function _typeof$2(obj) {
876
876
  "@babel/helpers - typeof";
@@ -1529,12 +1529,14 @@
1529
1529
  return target;
1530
1530
  }
1531
1531
 
1532
+ // eslint-disable-next-line no-restricted-syntax
1532
1533
  for (var key in source) {
1533
1534
  if (
1534
1535
  !Object.prototype.hasOwnProperty.call(source, key) ||
1535
1536
  key === '__proto__' ||
1536
1537
  key === 'constructor'
1537
1538
  ) {
1539
+ // eslint-disable-next-line no-continue
1538
1540
  continue;
1539
1541
  }
1540
1542
 
@@ -1542,6 +1544,7 @@
1542
1544
  var targetVal = target[key];
1543
1545
 
1544
1546
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
1547
+ // eslint-disable-next-line no-continue
1545
1548
  continue;
1546
1549
  }
1547
1550
 
@@ -1568,11 +1571,10 @@
1568
1571
  * - treats sparse arrays as sparse
1569
1572
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
1570
1573
  *
1571
- * @param {Object} object The destination object.
1574
+ * @param {Object} target The destination object.
1572
1575
  * @param {...Object} [sources] The source objects.
1573
1576
  * @returns {Object} Returns `object`.
1574
1577
  */
1575
-
1576
1578
  function merge(target) {
1577
1579
  if (!isObjectOrArrayOrFunction(target)) {
1578
1580
  target = {};
@@ -1595,8 +1597,8 @@
1595
1597
  var defaultsPure = function defaultsPure() {
1596
1598
  var sources = Array.prototype.slice.call(arguments);
1597
1599
 
1598
- return sources.reduceRight(function(acc, source) {
1599
- Object.keys(Object(source)).forEach(function(key) {
1600
+ return sources.reduceRight(function (acc, source) {
1601
+ Object.keys(Object(source)).forEach(function (key) {
1600
1602
  if (source[key] === undefined) {
1601
1603
  return;
1602
1604
  }
@@ -1611,7 +1613,7 @@
1611
1613
  };
1612
1614
 
1613
1615
  function intersection(arr1, arr2) {
1614
- return arr1.filter(function(value, index) {
1616
+ return arr1.filter(function (value, index) {
1615
1617
  return (
1616
1618
  arr2.indexOf(value) > -1 &&
1617
1619
  arr1.indexOf(value) === index /* skips duplicates */
@@ -1632,6 +1634,8 @@
1632
1634
  return array[i];
1633
1635
  }
1634
1636
  }
1637
+
1638
+ return undefined;
1635
1639
  };
1636
1640
 
1637
1641
  function valToNumber(v) {
@@ -1643,7 +1647,9 @@
1643
1647
  return v.map(valToNumber);
1644
1648
  }
1645
1649
 
1646
- throw new Error('The value should be a number, a parsable string or an array of those.');
1650
+ throw new Error(
1651
+ 'The value should be a number, a parsable string or an array of those.'
1652
+ );
1647
1653
  }
1648
1654
 
1649
1655
  var valToNumber_1 = valToNumber;
@@ -1657,6 +1663,7 @@
1657
1663
  var i;
1658
1664
  for (i = 0; i < sourceKeys.length; i++) {
1659
1665
  key = sourceKeys[i];
1666
+ // eslint-disable-next-line no-continue
1660
1667
  if (excluded.indexOf(key) >= 0) continue;
1661
1668
  target[key] = source[key];
1662
1669
  }
@@ -1709,9 +1716,9 @@
1709
1716
 
1710
1717
  var valueAsString = '' + value;
1711
1718
 
1712
- var facetRefinement = !refinementList[attribute] ?
1713
- [valueAsString] :
1714
- refinementList[attribute].concat(valueAsString);
1719
+ var facetRefinement = !refinementList[attribute]
1720
+ ? [valueAsString]
1721
+ : refinementList[attribute].concat(valueAsString);
1715
1722
 
1716
1723
  var mod = {};
1717
1724
 
@@ -1728,18 +1735,22 @@
1728
1735
  * @param {string} [value] the value of the refinement
1729
1736
  * @return {RefinementList} a new and updated refinement lst
1730
1737
  */
1731
- removeRefinement: function removeRefinement(refinementList, attribute, value) {
1738
+ removeRefinement: function removeRefinement(
1739
+ refinementList,
1740
+ attribute,
1741
+ value
1742
+ ) {
1732
1743
  if (value === undefined) {
1733
1744
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
1734
1745
  // the form with a string will remove the attribute completely
1735
- return lib.clearRefinement(refinementList, function(v, f) {
1746
+ return lib.clearRefinement(refinementList, function (v, f) {
1736
1747
  return attribute === f;
1737
1748
  });
1738
1749
  }
1739
1750
 
1740
1751
  var valueAsString = '' + value;
1741
1752
 
1742
- return lib.clearRefinement(refinementList, function(v, f) {
1753
+ return lib.clearRefinement(refinementList, function (v, f) {
1743
1754
  return attribute === f && valueAsString === v;
1744
1755
  });
1745
1756
  },
@@ -1750,8 +1761,13 @@
1750
1761
  * @param {string} value the value of the refinement
1751
1762
  * @return {RefinementList} a new and updated list
1752
1763
  */
1753
- toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
1754
- if (value === undefined) throw new Error('toggleRefinement should be used with a value');
1764
+ toggleRefinement: function toggleRefinement(
1765
+ refinementList,
1766
+ attribute,
1767
+ value
1768
+ ) {
1769
+ if (value === undefined)
1770
+ throw new Error('toggleRefinement should be used with a value');
1755
1771
 
1756
1772
  if (lib.isRefined(refinementList, attribute, value)) {
1757
1773
  return lib.removeRefinement(refinementList, attribute, value);
@@ -1770,8 +1786,14 @@
1770
1786
  * @param {string} [refinementType] optional parameter to give more context to the attribute function
1771
1787
  * @return {RefinementList} a new and updated refinement list
1772
1788
  */
1773
- clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
1789
+ clearRefinement: function clearRefinement(
1790
+ refinementList,
1791
+ attribute,
1792
+ refinementType
1793
+ ) {
1774
1794
  if (attribute === undefined) {
1795
+ // return the same object if the list is already empty
1796
+ // this is mainly for tests, as it doesn't have much impact on performance
1775
1797
  if (!objectHasKeys_1(refinementList)) {
1776
1798
  return refinementList;
1777
1799
  }
@@ -1781,23 +1803,32 @@
1781
1803
  } else if (typeof attribute === 'function') {
1782
1804
  var hasChanged = false;
1783
1805
 
1784
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
1806
+ var newRefinementList = Object.keys(refinementList).reduce(function (
1807
+ memo,
1808
+ key
1809
+ ) {
1785
1810
  var values = refinementList[key] || [];
1786
- var facetList = values.filter(function(value) {
1811
+ var facetList = values.filter(function (value) {
1787
1812
  return !attribute(value, key, refinementType);
1788
1813
  });
1789
1814
 
1790
1815
  if (facetList.length !== values.length) {
1791
1816
  hasChanged = true;
1792
1817
  }
1818
+
1793
1819
  memo[key] = facetList;
1794
1820
 
1795
1821
  return memo;
1796
- }, {});
1822
+ },
1823
+ {});
1797
1824
 
1798
1825
  if (hasChanged) return newRefinementList;
1799
1826
  return refinementList;
1800
1827
  }
1828
+
1829
+ // We return nothing if the attribute is not undefined, a string or a function,
1830
+ // as it is not a valid value for a refinement
1831
+ return undefined;
1801
1832
  },
1802
1833
  /**
1803
1834
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -1806,10 +1837,11 @@
1806
1837
  * @param {RefinementList} refinementList the list of refinement
1807
1838
  * @param {string} attribute name of the attribute
1808
1839
  * @param {string} [refinementValue] value of the filter/refinement
1809
- * @return {boolean}
1840
+ * @return {boolean} true if the attribute is refined, false otherwise
1810
1841
  */
1811
1842
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
1812
- var containsRefinements = !!refinementList[attribute] &&
1843
+ var containsRefinements =
1844
+ Boolean(refinementList[attribute]) &&
1813
1845
  refinementList[attribute].length > 0;
1814
1846
 
1815
1847
  if (refinementValue === undefined || !containsRefinements) {
@@ -1819,7 +1851,7 @@
1819
1851
  var refinementValueAsString = '' + refinementValue;
1820
1852
 
1821
1853
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
1822
- }
1854
+ },
1823
1855
  };
1824
1856
 
1825
1857
  var RefinementList = lib;
@@ -1830,12 +1862,15 @@
1830
1862
  * - [5]
1831
1863
  * - [[5]]
1832
1864
  * - [[5,5],[4]]
1865
+ * @param {any} a numeric refinement value
1866
+ * @param {any} b numeric refinement value
1867
+ * @return {boolean} true if the values are equal
1833
1868
  */
1834
1869
  function isEqualNumericRefinement(a, b) {
1835
1870
  if (Array.isArray(a) && Array.isArray(b)) {
1836
1871
  return (
1837
1872
  a.length === b.length &&
1838
- a.every(function(el, i) {
1873
+ a.every(function (el, i) {
1839
1874
  return isEqualNumericRefinement(b[i], el);
1840
1875
  })
1841
1876
  );
@@ -1852,7 +1887,7 @@
1852
1887
  * @return {any} the searched value or undefined
1853
1888
  */
1854
1889
  function findArray(array, searchedValue) {
1855
- return find$1(array, function(currentValue) {
1890
+ return find$1(array, function (currentValue) {
1856
1891
  return isEqualNumericRefinement(currentValue, searchedValue);
1857
1892
  });
1858
1893
  }
@@ -1905,10 +1940,15 @@
1905
1940
  }
1906
1941
  */
1907
1942
  function SearchParameters(newParameters) {
1908
- var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
1943
+ var params = newParameters
1944
+ ? SearchParameters._parseNumbers(newParameters)
1945
+ : {};
1909
1946
 
1910
1947
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
1911
- console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
1948
+ // eslint-disable-next-line no-console
1949
+ console.warn(
1950
+ '[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}'
1951
+ );
1912
1952
  }
1913
1953
  /**
1914
1954
  * This attribute contains the list of all the conjunctive facets
@@ -2008,10 +2048,12 @@
2008
2048
  * be translated into the `facetFilters` attribute.
2009
2049
  * @member {Object.<string, SearchParameters.FacetList>}
2010
2050
  */
2011
- this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
2051
+ this.hierarchicalFacetsRefinements =
2052
+ params.hierarchicalFacetsRefinements || {};
2012
2053
 
2054
+ // eslint-disable-next-line consistent-this
2013
2055
  var self = this;
2014
- Object.keys(params).forEach(function(paramName) {
2056
+ Object.keys(params).forEach(function (paramName) {
2015
2057
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
2016
2058
  var isValueDefined = params[paramName] !== undefined;
2017
2059
 
@@ -2033,8 +2075,8 @@
2033
2075
  * @param {object} partialState full or part of a state
2034
2076
  * @return {object} a new object with the number keys as number
2035
2077
  */
2036
- SearchParameters._parseNumbers = function(partialState) {
2037
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
2078
+ SearchParameters._parseNumbers = function (partialState) {
2079
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
2038
2080
  if (partialState instanceof SearchParameters) return partialState;
2039
2081
 
2040
2082
  var numbers = {};
@@ -2050,10 +2092,10 @@
2050
2092
  'distinct',
2051
2093
  'minimumAroundRadius',
2052
2094
  'hitsPerPage',
2053
- 'minProximity'
2095
+ 'minProximity',
2054
2096
  ];
2055
2097
 
2056
- numberKeys.forEach(function(k) {
2098
+ numberKeys.forEach(function (k) {
2057
2099
  var value = partialState[k];
2058
2100
  if (typeof value === 'string') {
2059
2101
  var parsedValue = parseFloat(value);
@@ -2065,9 +2107,11 @@
2065
2107
  // there's two formats of insideBoundingBox, we need to parse
2066
2108
  // the one which is an array of float geo rectangles
2067
2109
  if (Array.isArray(partialState.insideBoundingBox)) {
2068
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
2110
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
2111
+ geoRect
2112
+ ) {
2069
2113
  if (Array.isArray(geoRect)) {
2070
- return geoRect.map(function(value) {
2114
+ return geoRect.map(function (value) {
2071
2115
  return parseFloat(value);
2072
2116
  });
2073
2117
  }
@@ -2077,14 +2121,14 @@
2077
2121
 
2078
2122
  if (partialState.numericRefinements) {
2079
2123
  var numericRefinements = {};
2080
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
2124
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
2081
2125
  var operators = partialState.numericRefinements[attribute] || {};
2082
2126
  numericRefinements[attribute] = {};
2083
- Object.keys(operators).forEach(function(operator) {
2127
+ Object.keys(operators).forEach(function (operator) {
2084
2128
  var values = operators[operator];
2085
- var parsedValues = values.map(function(v) {
2129
+ var parsedValues = values.map(function (v) {
2086
2130
  if (Array.isArray(v)) {
2087
- return v.map(function(vPrime) {
2131
+ return v.map(function (vPrime) {
2088
2132
  if (typeof vPrime === 'string') {
2089
2133
  return parseFloat(vPrime);
2090
2134
  }
@@ -2114,18 +2158,24 @@
2114
2158
  var instance = new SearchParameters(newParameters);
2115
2159
 
2116
2160
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
2117
- hierarchicalFacets.forEach(function(facet) {
2161
+ hierarchicalFacets.forEach(function (facet) {
2118
2162
  if (facet.rootPath) {
2119
2163
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
2120
2164
 
2121
- if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
2165
+ if (
2166
+ currentRefinement.length > 0 &&
2167
+ currentRefinement[0].indexOf(facet.rootPath) !== 0
2168
+ ) {
2122
2169
  instance = instance.clearRefinements(facet.name);
2123
2170
  }
2124
2171
 
2125
2172
  // get it again in case it has been cleared
2126
2173
  currentRefinement = instance.getHierarchicalRefinement(facet.name);
2127
2174
  if (currentRefinement.length === 0) {
2128
- instance = instance.toggleHierarchicalFacetRefinement(facet.name, facet.rootPath);
2175
+ instance = instance.toggleHierarchicalFacetRefinement(
2176
+ facet.name,
2177
+ facet.rootPath
2178
+ );
2129
2179
  }
2130
2180
  }
2131
2181
  });
@@ -2139,19 +2189,25 @@
2139
2189
  * @param {object|SearchParameters} parameters the new parameters to set
2140
2190
  * @return {Error|null} Error if the modification is invalid, null otherwise
2141
2191
  */
2142
- SearchParameters.validate = function(currentState, parameters) {
2192
+ SearchParameters.validate = function (currentState, parameters) {
2143
2193
  var params = parameters || {};
2144
2194
 
2145
- if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
2195
+ if (
2196
+ currentState.tagFilters &&
2197
+ params.tagRefinements &&
2198
+ params.tagRefinements.length > 0
2199
+ ) {
2146
2200
  return new Error(
2147
2201
  '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
2148
- 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
2202
+ 'an error, if it is really what you want, you should first clear the tags with clearTags method.'
2203
+ );
2149
2204
  }
2150
2205
 
2151
2206
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
2152
2207
  return new Error(
2153
2208
  '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
2154
- 'an error, if it is not, you should first clear the tags with clearTags method.');
2209
+ 'an error, if it is not, you should first clear the tags with clearTags method.'
2210
+ );
2155
2211
  }
2156
2212
 
2157
2213
  if (
@@ -2169,8 +2225,9 @@
2169
2225
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
2170
2226
  return new Error(
2171
2227
  "[Numeric filters] Can't switch from the managed API to the advanced. It" +
2172
- ' is probably an error, if this is really what you want, you have to first' +
2173
- ' clear the numeric filters.');
2228
+ ' is probably an error, if this is really what you want, you have to first' +
2229
+ ' clear the numeric filters.'
2230
+ );
2174
2231
  }
2175
2232
 
2176
2233
  return null;
@@ -2186,7 +2243,7 @@
2186
2243
  * - If not given, means to clear all the filters.
2187
2244
  * - If `string`, means to clear all refinements for the `attribute` named filter.
2188
2245
  * - If `function`, means to clear all the refinements that return truthy values.
2189
- * @return {SearchParameters}
2246
+ * @return {SearchParameters} new instance with filters cleared
2190
2247
  */
2191
2248
  clearRefinements: function clearRefinements(attribute) {
2192
2249
  var patch = {
@@ -2210,13 +2267,14 @@
2210
2267
  this.hierarchicalFacetsRefinements,
2211
2268
  attribute,
2212
2269
  'hierarchicalFacet'
2213
- )
2270
+ ),
2214
2271
  };
2215
2272
  if (
2216
2273
  patch.numericRefinements === this.numericRefinements &&
2217
2274
  patch.facetsRefinements === this.facetsRefinements &&
2218
2275
  patch.facetsExcludes === this.facetsExcludes &&
2219
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
2276
+ patch.disjunctiveFacetsRefinements ===
2277
+ this.disjunctiveFacetsRefinements &&
2220
2278
  patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
2221
2279
  ) {
2222
2280
  return this;
@@ -2226,53 +2284,54 @@
2226
2284
  /**
2227
2285
  * Remove all the refined tags from the SearchParameters
2228
2286
  * @method
2229
- * @return {SearchParameters}
2287
+ * @return {SearchParameters} new instance with tags cleared
2230
2288
  */
2231
2289
  clearTags: function clearTags() {
2232
- if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
2290
+ if (this.tagFilters === undefined && this.tagRefinements.length === 0)
2291
+ return this;
2233
2292
 
2234
2293
  return this.setQueryParameters({
2235
2294
  tagFilters: undefined,
2236
- tagRefinements: []
2295
+ tagRefinements: [],
2237
2296
  });
2238
2297
  },
2239
2298
  /**
2240
2299
  * Set the index.
2241
2300
  * @method
2242
2301
  * @param {string} index the index name
2243
- * @return {SearchParameters}
2302
+ * @return {SearchParameters} new instance
2244
2303
  */
2245
2304
  setIndex: function setIndex(index) {
2246
2305
  if (index === this.index) return this;
2247
2306
 
2248
2307
  return this.setQueryParameters({
2249
- index: index
2308
+ index: index,
2250
2309
  });
2251
2310
  },
2252
2311
  /**
2253
2312
  * Query setter
2254
2313
  * @method
2255
2314
  * @param {string} newQuery value for the new query
2256
- * @return {SearchParameters}
2315
+ * @return {SearchParameters} new instance
2257
2316
  */
2258
2317
  setQuery: function setQuery(newQuery) {
2259
2318
  if (newQuery === this.query) return this;
2260
2319
 
2261
2320
  return this.setQueryParameters({
2262
- query: newQuery
2321
+ query: newQuery,
2263
2322
  });
2264
2323
  },
2265
2324
  /**
2266
2325
  * Page setter
2267
2326
  * @method
2268
2327
  * @param {number} newPage new page number
2269
- * @return {SearchParameters}
2328
+ * @return {SearchParameters} new instance
2270
2329
  */
2271
2330
  setPage: function setPage(newPage) {
2272
2331
  if (newPage === this.page) return this;
2273
2332
 
2274
2333
  return this.setQueryParameters({
2275
- page: newPage
2334
+ page: newPage,
2276
2335
  });
2277
2336
  },
2278
2337
  /**
@@ -2280,11 +2339,11 @@
2280
2339
  * The facets are the simple facets, used for conjunctive (and) faceting.
2281
2340
  * @method
2282
2341
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
2283
- * @return {SearchParameters}
2342
+ * @return {SearchParameters} new instance
2284
2343
  */
2285
2344
  setFacets: function setFacets(facets) {
2286
2345
  return this.setQueryParameters({
2287
- facets: facets
2346
+ facets: facets,
2288
2347
  });
2289
2348
  },
2290
2349
  /**
@@ -2292,11 +2351,11 @@
2292
2351
  * Change the list of disjunctive (or) facets the helper chan handle.
2293
2352
  * @method
2294
2353
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
2295
- * @return {SearchParameters}
2354
+ * @return {SearchParameters} new instance
2296
2355
  */
2297
2356
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
2298
2357
  return this.setQueryParameters({
2299
- disjunctiveFacets: facets
2358
+ disjunctiveFacets: facets,
2300
2359
  });
2301
2360
  },
2302
2361
  /**
@@ -2304,13 +2363,13 @@
2304
2363
  * Hits per page represents the number of hits retrieved for this query
2305
2364
  * @method
2306
2365
  * @param {number} n number of hits retrieved per page of results
2307
- * @return {SearchParameters}
2366
+ * @return {SearchParameters} new instance
2308
2367
  */
2309
2368
  setHitsPerPage: function setHitsPerPage(n) {
2310
2369
  if (this.hitsPerPage === n) return this;
2311
2370
 
2312
2371
  return this.setQueryParameters({
2313
- hitsPerPage: n
2372
+ hitsPerPage: n,
2314
2373
  });
2315
2374
  },
2316
2375
  /**
@@ -2318,13 +2377,13 @@
2318
2377
  * Set the value of typoTolerance
2319
2378
  * @method
2320
2379
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
2321
- * @return {SearchParameters}
2380
+ * @return {SearchParameters} new instance
2322
2381
  */
2323
2382
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
2324
2383
  if (this.typoTolerance === typoTolerance) return this;
2325
2384
 
2326
2385
  return this.setQueryParameters({
2327
- typoTolerance: typoTolerance
2386
+ typoTolerance: typoTolerance,
2328
2387
  });
2329
2388
  },
2330
2389
  /**
@@ -2335,19 +2394,19 @@
2335
2394
  * @param {string} attribute attribute to set the filter on
2336
2395
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
2337
2396
  * @param {number | number[]} value value of the filter
2338
- * @return {SearchParameters}
2397
+ * @return {SearchParameters} new instance
2339
2398
  * @example
2340
2399
  * // for price = 50 or 40
2341
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
2400
+ * state.addNumericRefinement('price', '=', [50, 40]);
2342
2401
  * @example
2343
2402
  * // for size = 38 and 40
2344
- * searchparameter.addNumericRefinement('size', '=', 38);
2345
- * searchparameter.addNumericRefinement('size', '=', 40);
2403
+ * state.addNumericRefinement('size', '=', 38);
2404
+ * state.addNumericRefinement('size', '=', 40);
2346
2405
  */
2347
- addNumericRefinement: function(attribute, operator, v) {
2348
- var value = valToNumber_1(v);
2406
+ addNumericRefinement: function (attribute, operator, value) {
2407
+ var val = valToNumber_1(value);
2349
2408
 
2350
- if (this.isNumericRefined(attribute, operator, value)) return this;
2409
+ if (this.isNumericRefined(attribute, operator, val)) return this;
2351
2410
 
2352
2411
  var mod = merge_1({}, this.numericRefinements);
2353
2412
 
@@ -2357,13 +2416,13 @@
2357
2416
  // Array copy
2358
2417
  mod[attribute][operator] = mod[attribute][operator].slice();
2359
2418
  // Add the element. Concat can't be used here because value can be an array.
2360
- mod[attribute][operator].push(value);
2419
+ mod[attribute][operator].push(val);
2361
2420
  } else {
2362
- mod[attribute][operator] = [value];
2421
+ mod[attribute][operator] = [val];
2363
2422
  }
2364
2423
 
2365
2424
  return this.setQueryParameters({
2366
- numericRefinements: mod
2425
+ numericRefinements: mod,
2367
2426
  });
2368
2427
  },
2369
2428
  /**
@@ -2371,7 +2430,7 @@
2371
2430
  * @param {string} facetName name of the attribute used for faceting
2372
2431
  * @return {string[]} list of refinements
2373
2432
  */
2374
- getConjunctiveRefinements: function(facetName) {
2433
+ getConjunctiveRefinements: function (facetName) {
2375
2434
  if (!this.isConjunctiveFacet(facetName)) {
2376
2435
  return [];
2377
2436
  }
@@ -2382,7 +2441,7 @@
2382
2441
  * @param {string} facetName name of the attribute used for faceting
2383
2442
  * @return {string[]} list of refinements
2384
2443
  */
2385
- getDisjunctiveRefinements: function(facetName) {
2444
+ getDisjunctiveRefinements: function (facetName) {
2386
2445
  if (!this.isDisjunctiveFacet(facetName)) {
2387
2446
  return [];
2388
2447
  }
@@ -2393,7 +2452,7 @@
2393
2452
  * @param {string} facetName name of the attribute used for faceting
2394
2453
  * @return {string[]} list of refinements
2395
2454
  */
2396
- getHierarchicalRefinement: function(facetName) {
2455
+ getHierarchicalRefinement: function (facetName) {
2397
2456
  // we send an array but we currently do not support multiple
2398
2457
  // hierarchicalRefinements for a hierarchicalFacet
2399
2458
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -2403,7 +2462,7 @@
2403
2462
  * @param {string} facetName name of the attribute used for faceting
2404
2463
  * @return {string[]} list of refinements
2405
2464
  */
2406
- getExcludeRefinements: function(facetName) {
2465
+ getExcludeRefinements: function (facetName) {
2407
2466
  if (!this.isConjunctiveFacet(facetName)) {
2408
2467
  return [];
2409
2468
  }
@@ -2416,36 +2475,43 @@
2416
2475
  * @param {string} attribute attribute to set the filter on
2417
2476
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
2418
2477
  * @param {number} [number] the value to be removed
2419
- * @return {SearchParameters}
2478
+ * @return {SearchParameters} new instance
2420
2479
  */
2421
- removeNumericRefinement: function(attribute, operator, paramValue) {
2480
+ removeNumericRefinement: function (attribute, operator, number) {
2481
+ var paramValue = number;
2422
2482
  if (paramValue !== undefined) {
2423
2483
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
2424
2484
  return this;
2425
2485
  }
2426
2486
  return this.setQueryParameters({
2427
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2487
+ numericRefinements: this._clearNumericRefinements(function (
2488
+ value,
2489
+ key
2490
+ ) {
2428
2491
  return (
2429
2492
  key === attribute &&
2430
2493
  value.op === operator &&
2431
2494
  isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
2432
2495
  );
2433
- })
2496
+ }),
2434
2497
  });
2435
2498
  } else if (operator !== undefined) {
2436
2499
  if (!this.isNumericRefined(attribute, operator)) return this;
2437
2500
  return this.setQueryParameters({
2438
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2501
+ numericRefinements: this._clearNumericRefinements(function (
2502
+ value,
2503
+ key
2504
+ ) {
2439
2505
  return key === attribute && value.op === operator;
2440
- })
2506
+ }),
2441
2507
  });
2442
2508
  }
2443
2509
 
2444
2510
  if (!this.isNumericRefined(attribute)) return this;
2445
2511
  return this.setQueryParameters({
2446
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2512
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2447
2513
  return key === attribute;
2448
- })
2514
+ }),
2449
2515
  });
2450
2516
  },
2451
2517
  /**
@@ -2453,7 +2519,7 @@
2453
2519
  * @param {string} facetName name of the attribute used for faceting
2454
2520
  * @return {SearchParameters.OperatorList} list of refinements
2455
2521
  */
2456
- getNumericRefinements: function(facetName) {
2522
+ getNumericRefinements: function (facetName) {
2457
2523
  return this.numericRefinements[facetName] || {};
2458
2524
  },
2459
2525
  /**
@@ -2462,8 +2528,11 @@
2462
2528
  * @param {string} operator operator applied on the refined values
2463
2529
  * @return {Array.<number|number[]>} refined values
2464
2530
  */
2465
- getNumericRefinement: function(attribute, operator) {
2466
- return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
2531
+ getNumericRefinement: function (attribute, operator) {
2532
+ return (
2533
+ this.numericRefinements[attribute] &&
2534
+ this.numericRefinements[attribute][operator]
2535
+ );
2467
2536
  },
2468
2537
  /**
2469
2538
  * Clear numeric filters.
@@ -2473,7 +2542,7 @@
2473
2542
  * - If not given, means to clear all the filters.
2474
2543
  * - If `string`, means to clear all refinements for the `attribute` named filter.
2475
2544
  * - If `function`, means to clear all the refinements that return truthy values.
2476
- * @return {Object.<string, OperatorList>}
2545
+ * @return {Object.<string, OperatorList>} new numeric refinements
2477
2546
  */
2478
2547
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
2479
2548
  if (attribute === undefined) {
@@ -2486,39 +2555,50 @@
2486
2555
  } else if (typeof attribute === 'function') {
2487
2556
  var hasChanged = false;
2488
2557
  var numericRefinements = this.numericRefinements;
2489
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
2490
- var operators = numericRefinements[key];
2491
- var operatorList = {};
2492
-
2493
- operators = operators || {};
2494
- Object.keys(operators).forEach(function(operator) {
2495
- var values = operators[operator] || [];
2496
- var outValues = [];
2497
- values.forEach(function(value) {
2498
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
2499
- if (!predicateResult) outValues.push(value);
2558
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(
2559
+ function (memo, key) {
2560
+ var operators = numericRefinements[key];
2561
+ var operatorList = {};
2562
+
2563
+ operators = operators || {};
2564
+ Object.keys(operators).forEach(function (operator) {
2565
+ var values = operators[operator] || [];
2566
+ var outValues = [];
2567
+ values.forEach(function (value) {
2568
+ var predicateResult = attribute(
2569
+ { val: value, op: operator },
2570
+ key,
2571
+ 'numeric'
2572
+ );
2573
+ if (!predicateResult) outValues.push(value);
2574
+ });
2575
+ if (outValues.length !== values.length) {
2576
+ hasChanged = true;
2577
+ }
2578
+ operatorList[operator] = outValues;
2500
2579
  });
2501
- if (outValues.length !== values.length) {
2502
- hasChanged = true;
2503
- }
2504
- operatorList[operator] = outValues;
2505
- });
2506
2580
 
2507
- memo[key] = operatorList;
2581
+ memo[key] = operatorList;
2508
2582
 
2509
- return memo;
2510
- }, {});
2583
+ return memo;
2584
+ },
2585
+ {}
2586
+ );
2511
2587
 
2512
2588
  if (hasChanged) return newNumericRefinements;
2513
2589
  return this.numericRefinements;
2514
2590
  }
2591
+
2592
+ // We return nothing if the attribute is not undefined, a string or a function,
2593
+ // as it is not a valid value for a refinement
2594
+ return undefined;
2515
2595
  },
2516
2596
  /**
2517
2597
  * Add a facet to the facets attribute of the helper configuration, if it
2518
2598
  * isn't already present.
2519
2599
  * @method
2520
2600
  * @param {string} facet facet name to add
2521
- * @return {SearchParameters}
2601
+ * @return {SearchParameters} new instance
2522
2602
  */
2523
2603
  addFacet: function addFacet(facet) {
2524
2604
  if (this.isConjunctiveFacet(facet)) {
@@ -2526,7 +2606,7 @@
2526
2606
  }
2527
2607
 
2528
2608
  return this.setQueryParameters({
2529
- facets: this.facets.concat([facet])
2609
+ facets: this.facets.concat([facet]),
2530
2610
  });
2531
2611
  },
2532
2612
  /**
@@ -2534,7 +2614,7 @@
2534
2614
  * configuration, if it isn't already present.
2535
2615
  * @method
2536
2616
  * @param {string} facet disjunctive facet name to add
2537
- * @return {SearchParameters}
2617
+ * @return {SearchParameters} new instance
2538
2618
  */
2539
2619
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
2540
2620
  if (this.isDisjunctiveFacet(facet)) {
@@ -2542,7 +2622,7 @@
2542
2622
  }
2543
2623
 
2544
2624
  return this.setQueryParameters({
2545
- disjunctiveFacets: this.disjunctiveFacets.concat([facet])
2625
+ disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
2546
2626
  });
2547
2627
  },
2548
2628
  /**
@@ -2550,17 +2630,20 @@
2550
2630
  * configuration.
2551
2631
  * @method
2552
2632
  * @param {object} hierarchicalFacet hierarchical facet to add
2553
- * @return {SearchParameters}
2633
+ * @return {SearchParameters} new instance
2554
2634
  * @throws will throw an error if a hierarchical facet with the same name was already declared
2555
2635
  */
2556
2636
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
2557
2637
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
2558
2638
  throw new Error(
2559
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2639
+ 'Cannot declare two hierarchical facets with the same name: `' +
2640
+ hierarchicalFacet.name +
2641
+ '`'
2642
+ );
2560
2643
  }
2561
2644
 
2562
2645
  return this.setQueryParameters({
2563
- hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
2646
+ hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
2564
2647
  });
2565
2648
  },
2566
2649
  /**
@@ -2568,16 +2651,24 @@
2568
2651
  * @method
2569
2652
  * @param {string} facet attribute to apply the faceting on
2570
2653
  * @param {string} value value of the attribute (will be converted to string)
2571
- * @return {SearchParameters}
2654
+ * @return {SearchParameters} new instance
2572
2655
  */
2573
2656
  addFacetRefinement: function addFacetRefinement(facet, value) {
2574
2657
  if (!this.isConjunctiveFacet(facet)) {
2575
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2658
+ throw new Error(
2659
+ facet +
2660
+ ' is not defined in the facets attribute of the helper configuration'
2661
+ );
2576
2662
  }
2577
- if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2663
+ if (RefinementList.isRefined(this.facetsRefinements, facet, value))
2664
+ return this;
2578
2665
 
2579
2666
  return this.setQueryParameters({
2580
- facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
2667
+ facetsRefinements: RefinementList.addRefinement(
2668
+ this.facetsRefinements,
2669
+ facet,
2670
+ value
2671
+ ),
2581
2672
  });
2582
2673
  },
2583
2674
  /**
@@ -2585,16 +2676,24 @@
2585
2676
  * @method
2586
2677
  * @param {string} facet attribute to apply the exclusion on
2587
2678
  * @param {string} value value of the attribute (will be converted to string)
2588
- * @return {SearchParameters}
2679
+ * @return {SearchParameters} new instance
2589
2680
  */
2590
2681
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
2591
2682
  if (!this.isConjunctiveFacet(facet)) {
2592
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2683
+ throw new Error(
2684
+ facet +
2685
+ ' is not defined in the facets attribute of the helper configuration'
2686
+ );
2593
2687
  }
2594
- if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2688
+ if (RefinementList.isRefined(this.facetsExcludes, facet, value))
2689
+ return this;
2595
2690
 
2596
2691
  return this.setQueryParameters({
2597
- facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
2692
+ facetsExcludes: RefinementList.addRefinement(
2693
+ this.facetsExcludes,
2694
+ facet,
2695
+ value
2696
+ ),
2598
2697
  });
2599
2698
  },
2600
2699
  /**
@@ -2602,31 +2701,42 @@
2602
2701
  * @method
2603
2702
  * @param {string} facet attribute to apply the faceting on
2604
2703
  * @param {string} value value of the attribute (will be converted to string)
2605
- * @return {SearchParameters}
2704
+ * @return {SearchParameters} new instance
2606
2705
  */
2607
- addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
2706
+ addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
2707
+ facet,
2708
+ value
2709
+ ) {
2608
2710
  if (!this.isDisjunctiveFacet(facet)) {
2609
2711
  throw new Error(
2610
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2712
+ facet +
2713
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2714
+ );
2611
2715
  }
2612
2716
 
2613
- if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2717
+ if (
2718
+ RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
2719
+ )
2720
+ return this;
2614
2721
 
2615
2722
  return this.setQueryParameters({
2616
2723
  disjunctiveFacetsRefinements: RefinementList.addRefinement(
2617
- this.disjunctiveFacetsRefinements, facet, value)
2724
+ this.disjunctiveFacetsRefinements,
2725
+ facet,
2726
+ value
2727
+ ),
2618
2728
  });
2619
2729
  },
2620
2730
  /**
2621
2731
  * addTagRefinement adds a tag to the list used to filter the results
2622
2732
  * @param {string} tag tag to be added
2623
- * @return {SearchParameters}
2733
+ * @return {SearchParameters} new instance
2624
2734
  */
2625
2735
  addTagRefinement: function addTagRefinement(tag) {
2626
2736
  if (this.isTagRefined(tag)) return this;
2627
2737
 
2628
2738
  var modification = {
2629
- tagRefinements: this.tagRefinements.concat(tag)
2739
+ tagRefinements: this.tagRefinements.concat(tag),
2630
2740
  };
2631
2741
 
2632
2742
  return this.setQueryParameters(modification);
@@ -2636,7 +2746,7 @@
2636
2746
  * is present.
2637
2747
  * @method
2638
2748
  * @param {string} facet facet name to remove
2639
- * @return {SearchParameters}
2749
+ * @return {SearchParameters} new instance
2640
2750
  */
2641
2751
  removeFacet: function removeFacet(facet) {
2642
2752
  if (!this.isConjunctiveFacet(facet)) {
@@ -2644,9 +2754,9 @@
2644
2754
  }
2645
2755
 
2646
2756
  return this.clearRefinements(facet).setQueryParameters({
2647
- facets: this.facets.filter(function(f) {
2757
+ facets: this.facets.filter(function (f) {
2648
2758
  return f !== facet;
2649
- })
2759
+ }),
2650
2760
  });
2651
2761
  },
2652
2762
  /**
@@ -2654,7 +2764,7 @@
2654
2764
  * helper configuration, if it is present.
2655
2765
  * @method
2656
2766
  * @param {string} facet disjunctive facet name to remove
2657
- * @return {SearchParameters}
2767
+ * @return {SearchParameters} new instance
2658
2768
  */
2659
2769
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
2660
2770
  if (!this.isDisjunctiveFacet(facet)) {
@@ -2662,9 +2772,9 @@
2662
2772
  }
2663
2773
 
2664
2774
  return this.clearRefinements(facet).setQueryParameters({
2665
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
2775
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
2666
2776
  return f !== facet;
2667
- })
2777
+ }),
2668
2778
  });
2669
2779
  },
2670
2780
  /**
@@ -2672,7 +2782,7 @@
2672
2782
  * helper configuration, if it is present.
2673
2783
  * @method
2674
2784
  * @param {string} facet hierarchical facet name to remove
2675
- * @return {SearchParameters}
2785
+ * @return {SearchParameters} new instance
2676
2786
  */
2677
2787
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
2678
2788
  if (!this.isHierarchicalFacet(facet)) {
@@ -2680,9 +2790,9 @@
2680
2790
  }
2681
2791
 
2682
2792
  return this.clearRefinements(facet).setQueryParameters({
2683
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
2793
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
2684
2794
  return f.name !== facet;
2685
- })
2795
+ }),
2686
2796
  });
2687
2797
  },
2688
2798
  /**
@@ -2692,16 +2802,24 @@
2692
2802
  * @method
2693
2803
  * @param {string} facet name of the attribute used for faceting
2694
2804
  * @param {string} [value] value used to filter
2695
- * @return {SearchParameters}
2805
+ * @return {SearchParameters} new instance
2696
2806
  */
2697
2807
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
2698
2808
  if (!this.isConjunctiveFacet(facet)) {
2699
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2809
+ throw new Error(
2810
+ facet +
2811
+ ' is not defined in the facets attribute of the helper configuration'
2812
+ );
2700
2813
  }
2701
- if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2814
+ if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
2815
+ return this;
2702
2816
 
2703
2817
  return this.setQueryParameters({
2704
- facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
2818
+ facetsRefinements: RefinementList.removeRefinement(
2819
+ this.facetsRefinements,
2820
+ facet,
2821
+ value
2822
+ ),
2705
2823
  });
2706
2824
  },
2707
2825
  /**
@@ -2709,16 +2827,24 @@
2709
2827
  * @method
2710
2828
  * @param {string} facet name of the attribute used for faceting
2711
2829
  * @param {string} value value used to filter
2712
- * @return {SearchParameters}
2830
+ * @return {SearchParameters} new instance
2713
2831
  */
2714
2832
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
2715
2833
  if (!this.isConjunctiveFacet(facet)) {
2716
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2834
+ throw new Error(
2835
+ facet +
2836
+ ' is not defined in the facets attribute of the helper configuration'
2837
+ );
2717
2838
  }
2718
- if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2839
+ if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
2840
+ return this;
2719
2841
 
2720
2842
  return this.setQueryParameters({
2721
- facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
2843
+ facetsExcludes: RefinementList.removeRefinement(
2844
+ this.facetsExcludes,
2845
+ facet,
2846
+ value
2847
+ ),
2722
2848
  });
2723
2849
  },
2724
2850
  /**
@@ -2726,33 +2852,44 @@
2726
2852
  * @method
2727
2853
  * @param {string} facet name of the attribute used for faceting
2728
2854
  * @param {string} value value used to filter
2729
- * @return {SearchParameters}
2855
+ * @return {SearchParameters} new instance
2730
2856
  */
2731
- removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
2857
+ removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
2858
+ facet,
2859
+ value
2860
+ ) {
2732
2861
  if (!this.isDisjunctiveFacet(facet)) {
2733
2862
  throw new Error(
2734
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2863
+ facet +
2864
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2865
+ );
2735
2866
  }
2736
- if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2867
+ if (
2868
+ !RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
2869
+ )
2870
+ return this;
2737
2871
 
2738
2872
  return this.setQueryParameters({
2739
2873
  disjunctiveFacetsRefinements: RefinementList.removeRefinement(
2740
- this.disjunctiveFacetsRefinements, facet, value)
2874
+ this.disjunctiveFacetsRefinements,
2875
+ facet,
2876
+ value
2877
+ ),
2741
2878
  });
2742
2879
  },
2743
2880
  /**
2744
2881
  * Remove a tag from the list of tag refinements
2745
2882
  * @method
2746
2883
  * @param {string} tag the tag to remove
2747
- * @return {SearchParameters}
2884
+ * @return {SearchParameters} new instance
2748
2885
  */
2749
2886
  removeTagRefinement: function removeTagRefinement(tag) {
2750
2887
  if (!this.isTagRefined(tag)) return this;
2751
2888
 
2752
2889
  var modification = {
2753
- tagRefinements: this.tagRefinements.filter(function(t) {
2890
+ tagRefinements: this.tagRefinements.filter(function (t) {
2754
2891
  return t !== tag;
2755
- })
2892
+ }),
2756
2893
  };
2757
2894
 
2758
2895
  return this.setQueryParameters(modification);
@@ -2762,7 +2899,7 @@
2762
2899
  * and hierarchical facets
2763
2900
  * @param {string} facet the facet to refine
2764
2901
  * @param {string} value the associated value
2765
- * @return {SearchParameters}
2902
+ * @return {SearchParameters} new instance
2766
2903
  * @throws will throw an error if the facet is not declared in the settings of the helper
2767
2904
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
2768
2905
  */
@@ -2774,7 +2911,7 @@
2774
2911
  * and hierarchical facets
2775
2912
  * @param {string} facet the facet to refine
2776
2913
  * @param {string} value the associated value
2777
- * @return {SearchParameters}
2914
+ * @return {SearchParameters} new instance
2778
2915
  * @throws will throw an error if the facet is not declared in the settings of the helper
2779
2916
  */
2780
2917
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -2786,23 +2923,36 @@
2786
2923
  return this.toggleDisjunctiveFacetRefinement(facet, value);
2787
2924
  }
2788
2925
 
2789
- throw new Error('Cannot refine the undeclared facet ' + facet +
2790
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2926
+ throw new Error(
2927
+ 'Cannot refine the undeclared facet ' +
2928
+ facet +
2929
+ '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets'
2930
+ );
2791
2931
  },
2792
2932
  /**
2793
2933
  * Switch the refinement applied over a facet/value
2794
2934
  * @method
2795
2935
  * @param {string} facet name of the attribute used for faceting
2796
2936
  * @param {value} value value used for filtering
2797
- * @return {SearchParameters}
2937
+ * @return {SearchParameters} new instance
2798
2938
  */
2799
- toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
2939
+ toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
2940
+ facet,
2941
+ value
2942
+ ) {
2800
2943
  if (!this.isConjunctiveFacet(facet)) {
2801
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2944
+ throw new Error(
2945
+ facet +
2946
+ ' is not defined in the facets attribute of the helper configuration'
2947
+ );
2802
2948
  }
2803
2949
 
2804
2950
  return this.setQueryParameters({
2805
- facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
2951
+ facetsRefinements: RefinementList.toggleRefinement(
2952
+ this.facetsRefinements,
2953
+ facet,
2954
+ value
2955
+ ),
2806
2956
  });
2807
2957
  },
2808
2958
  /**
@@ -2810,15 +2960,25 @@
2810
2960
  * @method
2811
2961
  * @param {string} facet name of the attribute used for faceting
2812
2962
  * @param {value} value value used for filtering
2813
- * @return {SearchParameters}
2963
+ * @return {SearchParameters} new instance
2814
2964
  */
2815
- toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
2965
+ toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
2966
+ facet,
2967
+ value
2968
+ ) {
2816
2969
  if (!this.isConjunctiveFacet(facet)) {
2817
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2970
+ throw new Error(
2971
+ facet +
2972
+ ' is not defined in the facets attribute of the helper configuration'
2973
+ );
2818
2974
  }
2819
2975
 
2820
2976
  return this.setQueryParameters({
2821
- facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
2977
+ facetsExcludes: RefinementList.toggleRefinement(
2978
+ this.facetsExcludes,
2979
+ facet,
2980
+ value
2981
+ ),
2822
2982
  });
2823
2983
  },
2824
2984
  /**
@@ -2826,17 +2986,25 @@
2826
2986
  * @method
2827
2987
  * @param {string} facet name of the attribute used for faceting
2828
2988
  * @param {value} value value used for filtering
2829
- * @return {SearchParameters}
2989
+ * @return {SearchParameters} new instance
2830
2990
  */
2831
- toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
2991
+ toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
2992
+ facet,
2993
+ value
2994
+ ) {
2832
2995
  if (!this.isDisjunctiveFacet(facet)) {
2833
2996
  throw new Error(
2834
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2997
+ facet +
2998
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2999
+ );
2835
3000
  }
2836
3001
 
2837
3002
  return this.setQueryParameters({
2838
3003
  disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
2839
- this.disjunctiveFacetsRefinements, facet, value)
3004
+ this.disjunctiveFacetsRefinements,
3005
+ facet,
3006
+ value
3007
+ ),
2840
3008
  });
2841
3009
  },
2842
3010
  /**
@@ -2844,29 +3012,38 @@
2844
3012
  * @method
2845
3013
  * @param {string} facet name of the attribute used for faceting
2846
3014
  * @param {value} value value used for filtering
2847
- * @return {SearchParameters}
3015
+ * @return {SearchParameters} new instance
2848
3016
  */
2849
- toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
3017
+ toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
3018
+ facet,
3019
+ value
3020
+ ) {
2850
3021
  if (!this.isHierarchicalFacet(facet)) {
2851
3022
  throw new Error(
2852
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
3023
+ facet +
3024
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration'
3025
+ );
2853
3026
  }
2854
3027
 
2855
- var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
3028
+ var separator = this._getHierarchicalFacetSeparator(
3029
+ this.getHierarchicalFacetByName(facet)
3030
+ );
2856
3031
 
2857
3032
  var mod = {};
2858
3033
 
2859
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
2860
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
3034
+ var upOneOrMultipleLevel =
3035
+ this.hierarchicalFacetsRefinements[facet] !== undefined &&
3036
+ this.hierarchicalFacetsRefinements[facet].length > 0 &&
2861
3037
  // remove current refinement:
2862
3038
  // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2863
- this.hierarchicalFacetsRefinements[facet][0] === value ||
2864
- // remove a parent refinement of the current refinement:
2865
- // - refinement was 'beer > IPA > Flying dog'
2866
- // - call is toggleRefine('beer > IPA')
2867
- // - refinement should be `beer`
2868
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
2869
- );
3039
+ (this.hierarchicalFacetsRefinements[facet][0] === value ||
3040
+ // remove a parent refinement of the current refinement:
3041
+ // - refinement was 'beer > IPA > Flying dog'
3042
+ // - call is toggleRefine('beer > IPA')
3043
+ // - refinement should be `beer`
3044
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(
3045
+ value + separator
3046
+ ) === 0);
2870
3047
 
2871
3048
  if (upOneOrMultipleLevel) {
2872
3049
  if (value.indexOf(separator) === -1) {
@@ -2880,7 +3057,11 @@
2880
3057
  }
2881
3058
 
2882
3059
  return this.setQueryParameters({
2883
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
3060
+ hierarchicalFacetsRefinements: defaultsPure(
3061
+ {},
3062
+ mod,
3063
+ this.hierarchicalFacetsRefinements
3064
+ ),
2884
3065
  });
2885
3066
  },
2886
3067
 
@@ -2891,17 +3072,24 @@
2891
3072
  * @return {SearchParameter} the new state
2892
3073
  * @throws Error if the facet is not defined or if the facet is refined
2893
3074
  */
2894
- addHierarchicalFacetRefinement: function(facet, path) {
3075
+ addHierarchicalFacetRefinement: function (facet, path) {
2895
3076
  if (this.isHierarchicalFacetRefined(facet)) {
2896
3077
  throw new Error(facet + ' is already refined.');
2897
3078
  }
2898
3079
  if (!this.isHierarchicalFacet(facet)) {
2899
- throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration.');
3080
+ throw new Error(
3081
+ facet +
3082
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration.'
3083
+ );
2900
3084
  }
2901
3085
  var mod = {};
2902
3086
  mod[facet] = [path];
2903
3087
  return this.setQueryParameters({
2904
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
3088
+ hierarchicalFacetsRefinements: defaultsPure(
3089
+ {},
3090
+ mod,
3091
+ this.hierarchicalFacetsRefinements
3092
+ ),
2905
3093
  });
2906
3094
  },
2907
3095
 
@@ -2911,21 +3099,25 @@
2911
3099
  * @return {SearchParameter} the new state
2912
3100
  * @throws Error if the facet is not defined or if the facet is not refined
2913
3101
  */
2914
- removeHierarchicalFacetRefinement: function(facet) {
3102
+ removeHierarchicalFacetRefinement: function (facet) {
2915
3103
  if (!this.isHierarchicalFacetRefined(facet)) {
2916
3104
  return this;
2917
3105
  }
2918
3106
  var mod = {};
2919
3107
  mod[facet] = [];
2920
3108
  return this.setQueryParameters({
2921
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
3109
+ hierarchicalFacetsRefinements: defaultsPure(
3110
+ {},
3111
+ mod,
3112
+ this.hierarchicalFacetsRefinements
3113
+ ),
2922
3114
  });
2923
3115
  },
2924
3116
  /**
2925
3117
  * Switch the tag refinement
2926
3118
  * @method
2927
3119
  * @param {string} tag the tag to remove or add
2928
- * @return {SearchParameters}
3120
+ * @return {SearchParameters} new instance
2929
3121
  */
2930
3122
  toggleTagRefinement: function toggleTagRefinement(tag) {
2931
3123
  if (this.isTagRefined(tag)) {
@@ -2938,27 +3130,27 @@
2938
3130
  * Test if the facet name is from one of the disjunctive facets
2939
3131
  * @method
2940
3132
  * @param {string} facet facet name to test
2941
- * @return {boolean}
3133
+ * @return {boolean} true if facet is a disjunctive facet
2942
3134
  */
2943
- isDisjunctiveFacet: function(facet) {
3135
+ isDisjunctiveFacet: function (facet) {
2944
3136
  return this.disjunctiveFacets.indexOf(facet) > -1;
2945
3137
  },
2946
3138
  /**
2947
3139
  * Test if the facet name is from one of the hierarchical facets
2948
3140
  * @method
2949
3141
  * @param {string} facetName facet name to test
2950
- * @return {boolean}
3142
+ * @return {boolean} true if facetName is a hierarchical facet
2951
3143
  */
2952
- isHierarchicalFacet: function(facetName) {
3144
+ isHierarchicalFacet: function (facetName) {
2953
3145
  return this.getHierarchicalFacetByName(facetName) !== undefined;
2954
3146
  },
2955
3147
  /**
2956
3148
  * Test if the facet name is from one of the conjunctive/normal facets
2957
3149
  * @method
2958
3150
  * @param {string} facet facet name to test
2959
- * @return {boolean}
3151
+ * @return {boolean} true if facet is a conjunctive facet
2960
3152
  */
2961
- isConjunctiveFacet: function(facet) {
3153
+ isConjunctiveFacet: function (facet) {
2962
3154
  return this.facets.indexOf(facet) > -1;
2963
3155
  },
2964
3156
  /**
@@ -2999,13 +3191,17 @@
2999
3191
  * @param {string} facet name of the attribute for used for faceting
3000
3192
  * @param {string} value optional, will test if the value is used for refinement
3001
3193
  * if there is one, otherwise will test if the facet contains any refinement
3002
- * @return {boolean}
3194
+ * @return {boolean} true if the facet is refined
3003
3195
  */
3004
3196
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
3005
3197
  if (!this.isDisjunctiveFacet(facet)) {
3006
3198
  return false;
3007
3199
  }
3008
- return RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value);
3200
+ return RefinementList.isRefined(
3201
+ this.disjunctiveFacetsRefinements,
3202
+ facet,
3203
+ value
3204
+ );
3009
3205
  },
3010
3206
  /**
3011
3207
  * Returns true if the facet contains a refinement, or if a value passed is a
@@ -3014,9 +3210,12 @@
3014
3210
  * @param {string} facet name of the attribute for used for faceting
3015
3211
  * @param {string} value optional, will test if the value is used for refinement
3016
3212
  * if there is one, otherwise will test if the facet contains any refinement
3017
- * @return {boolean}
3213
+ * @return {boolean} true if the facet is refined
3018
3214
  */
3019
- isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
3215
+ isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
3216
+ facet,
3217
+ value
3218
+ ) {
3020
3219
  if (!this.isHierarchicalFacet(facet)) {
3021
3220
  return false;
3022
3221
  }
@@ -3041,7 +3240,7 @@
3041
3240
  */
3042
3241
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
3043
3242
  if (value === undefined && operator === undefined) {
3044
- return !!this.numericRefinements[attribute];
3243
+ return Boolean(this.numericRefinements[attribute]);
3045
3244
  }
3046
3245
 
3047
3246
  var isOperatorDefined =
@@ -3063,7 +3262,7 @@
3063
3262
  * Returns true if the tag refined, false otherwise
3064
3263
  * @method
3065
3264
  * @param {string} tag the tag to check
3066
- * @return {boolean}
3265
+ * @return {boolean} true if tag is refined
3067
3266
  */
3068
3267
  isTagRefined: function isTagRefined(tag) {
3069
3268
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -3073,22 +3272,24 @@
3073
3272
  * @method
3074
3273
  * @param {string} facet name of the attribute used for faceting
3075
3274
  * @param {value} value value used for filtering
3076
- * @return {string[]}
3275
+ * @return {string[]} returns the list of refinements
3077
3276
  */
3078
3277
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
3278
+ // eslint-disable-next-line consistent-this
3079
3279
  var self = this;
3080
3280
 
3081
3281
  // attributes used for numeric filter can also be disjunctive
3082
3282
  var disjunctiveNumericRefinedFacets = intersection_1(
3083
- Object.keys(this.numericRefinements).filter(function(facet) {
3283
+ Object.keys(this.numericRefinements).filter(function (facet) {
3084
3284
  return Object.keys(self.numericRefinements[facet]).length > 0;
3085
3285
  }),
3086
3286
  this.disjunctiveFacets
3087
3287
  );
3088
3288
 
3089
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
3090
- return self.disjunctiveFacetsRefinements[facet].length > 0;
3091
- })
3289
+ return Object.keys(this.disjunctiveFacetsRefinements)
3290
+ .filter(function (facet) {
3291
+ return self.disjunctiveFacetsRefinements[facet].length > 0;
3292
+ })
3092
3293
  .concat(disjunctiveNumericRefinedFacets)
3093
3294
  .concat(this.getRefinedHierarchicalFacets());
3094
3295
  },
@@ -3097,15 +3298,18 @@
3097
3298
  * @method
3098
3299
  * @param {string} facet name of the attribute used for faceting
3099
3300
  * @param {value} value value used for filtering
3100
- * @return {string[]}
3301
+ * @return {string[]} returns the list of refinements
3101
3302
  */
3102
3303
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
3304
+ // eslint-disable-next-line consistent-this
3103
3305
  var self = this;
3104
3306
  return intersection_1(
3105
3307
  // enforce the order between the two arrays,
3106
3308
  // so that refinement name index === hierarchical facet index
3107
- this.hierarchicalFacets.map(function(facet) { return facet.name; }),
3108
- Object.keys(this.hierarchicalFacetsRefinements).filter(function(facet) {
3309
+ this.hierarchicalFacets.map(function (facet) {
3310
+ return facet.name;
3311
+ }),
3312
+ Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
3109
3313
  return self.hierarchicalFacetsRefinements[facet].length > 0;
3110
3314
  })
3111
3315
  );
@@ -3113,12 +3317,12 @@
3113
3317
  /**
3114
3318
  * Returned the list of all disjunctive facets not refined
3115
3319
  * @method
3116
- * @return {string[]}
3320
+ * @return {string[]} returns the list of facets that are not refined
3117
3321
  */
3118
- getUnrefinedDisjunctiveFacets: function() {
3322
+ getUnrefinedDisjunctiveFacets: function () {
3119
3323
  var refinedFacets = this.getRefinedDisjunctiveFacets();
3120
3324
 
3121
- return this.disjunctiveFacets.filter(function(f) {
3325
+ return this.disjunctiveFacets.filter(function (f) {
3122
3326
  return refinedFacets.indexOf(f) === -1;
3123
3327
  });
3124
3328
  },
@@ -3135,17 +3339,22 @@
3135
3339
  'disjunctiveFacetsRefinements',
3136
3340
  'numericRefinements',
3137
3341
  'tagRefinements',
3138
- 'hierarchicalFacetsRefinements'
3342
+ 'hierarchicalFacetsRefinements',
3139
3343
  ],
3344
+
3140
3345
  getQueryParams: function getQueryParams() {
3141
3346
  var managedParameters = this.managedParameters;
3142
3347
 
3143
3348
  var queryParams = {};
3144
3349
 
3350
+ // eslint-disable-next-line consistent-this
3145
3351
  var self = this;
3146
- Object.keys(this).forEach(function(paramName) {
3352
+ Object.keys(this).forEach(function (paramName) {
3147
3353
  var paramValue = self[paramName];
3148
- if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
3354
+ if (
3355
+ managedParameters.indexOf(paramName) === -1 &&
3356
+ paramValue !== undefined
3357
+ ) {
3149
3358
  queryParams[paramName] = paramValue;
3150
3359
  }
3151
3360
  });
@@ -3186,30 +3395,32 @@
3186
3395
  throw error;
3187
3396
  }
3188
3397
 
3398
+ // eslint-disable-next-line consistent-this
3189
3399
  var self = this;
3190
3400
  var nextWithNumbers = SearchParameters._parseNumbers(params);
3191
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
3401
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
3192
3402
  acc[key] = self[key];
3193
3403
  return acc;
3194
3404
  }, {});
3195
3405
 
3196
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
3197
- function(previous, key) {
3198
- var isPreviousValueDefined = previous[key] !== undefined;
3199
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
3406
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
3407
+ previous,
3408
+ key
3409
+ ) {
3410
+ var isPreviousValueDefined = previous[key] !== undefined;
3411
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
3200
3412
 
3201
- if (isPreviousValueDefined && !isNextValueDefined) {
3202
- return omit$1(previous, [key]);
3203
- }
3413
+ if (isPreviousValueDefined && !isNextValueDefined) {
3414
+ return omit$1(previous, [key]);
3415
+ }
3204
3416
 
3205
- if (isNextValueDefined) {
3206
- previous[key] = nextWithNumbers[key];
3207
- }
3417
+ if (isNextValueDefined) {
3418
+ previous[key] = nextWithNumbers[key];
3419
+ }
3208
3420
 
3209
- return previous;
3210
- },
3211
- previousPlainObject
3212
- );
3421
+ return previous;
3422
+ },
3423
+ previousPlainObject);
3213
3424
 
3214
3425
  return new this.constructor(nextPlainObject);
3215
3426
  },
@@ -3220,7 +3431,7 @@
3220
3431
  * the page is set -> return a new instance with a page of 0
3221
3432
  * @return {SearchParameters} a new updated instance
3222
3433
  */
3223
- resetPage: function() {
3434
+ resetPage: function () {
3224
3435
  if (this.page === undefined) {
3225
3436
  return this;
3226
3437
  }
@@ -3230,40 +3441,40 @@
3230
3441
 
3231
3442
  /**
3232
3443
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
3233
- * @param {object} hierarchicalFacet
3444
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3234
3445
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
3235
3446
  */
3236
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
3447
+ _getHierarchicalFacetSortBy: function (hierarchicalFacet) {
3237
3448
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
3238
3449
  },
3239
3450
 
3240
3451
  /**
3241
3452
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
3242
3453
  * @private
3243
- * @param {object} hierarchicalFacet
3454
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3244
3455
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
3245
3456
  */
3246
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
3457
+ _getHierarchicalFacetSeparator: function (hierarchicalFacet) {
3247
3458
  return hierarchicalFacet.separator || ' > ';
3248
3459
  },
3249
3460
 
3250
3461
  /**
3251
3462
  * Helper function to get the hierarchicalFacet prefix path or null
3252
3463
  * @private
3253
- * @param {object} hierarchicalFacet
3464
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3254
3465
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
3255
3466
  */
3256
- _getHierarchicalRootPath: function(hierarchicalFacet) {
3467
+ _getHierarchicalRootPath: function (hierarchicalFacet) {
3257
3468
  return hierarchicalFacet.rootPath || null;
3258
3469
  },
3259
3470
 
3260
3471
  /**
3261
3472
  * Helper function to check if we show the parent level of the hierarchicalFacet
3262
3473
  * @private
3263
- * @param {object} hierarchicalFacet
3474
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3264
3475
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
3265
3476
  */
3266
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
3477
+ _getHierarchicalShowParentLevel: function (hierarchicalFacet) {
3267
3478
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
3268
3479
  return hierarchicalFacet.showParentLevel;
3269
3480
  }
@@ -3272,16 +3483,13 @@
3272
3483
 
3273
3484
  /**
3274
3485
  * Helper function to get the hierarchicalFacet by it's name
3275
- * @param {string} hierarchicalFacetName
3486
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
3276
3487
  * @return {object} a hierarchicalFacet
3277
3488
  */
3278
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
3279
- return find$1(
3280
- this.hierarchicalFacets,
3281
- function(f) {
3282
- return f.name === hierarchicalFacetName;
3283
- }
3284
- );
3489
+ getHierarchicalFacetByName: function (hierarchicalFacetName) {
3490
+ return find$1(this.hierarchicalFacets, function (f) {
3491
+ return f.name === hierarchicalFacetName;
3492
+ });
3285
3493
  },
3286
3494
 
3287
3495
  /**
@@ -3289,7 +3497,7 @@
3289
3497
  * @param {string} facetName Hierarchical facet name
3290
3498
  * @return {array.<string>} the path as an array of string
3291
3499
  */
3292
- getHierarchicalFacetBreadcrumb: function(facetName) {
3500
+ getHierarchicalFacetBreadcrumb: function (facetName) {
3293
3501
  if (!this.isHierarchicalFacet(facetName)) {
3294
3502
  return [];
3295
3503
  }
@@ -3301,14 +3509,14 @@
3301
3509
  this.getHierarchicalFacetByName(facetName)
3302
3510
  );
3303
3511
  var path = refinement.split(separator);
3304
- return path.map(function(part) {
3512
+ return path.map(function (part) {
3305
3513
  return part.trim();
3306
3514
  });
3307
3515
  },
3308
3516
 
3309
- toString: function() {
3517
+ toString: function () {
3310
3518
  return JSON.stringify(this, null, 2);
3311
- }
3519
+ },
3312
3520
  };
3313
3521
 
3314
3522
  /**
@@ -3352,6 +3560,7 @@
3352
3560
  * @param {Array<object>} collection object with keys in attributes
3353
3561
  * @param {Array<string>} iteratees attributes
3354
3562
  * @param {Array<string>} orders asc | desc
3563
+ * @return {Array<object>} sorted collection
3355
3564
  */
3356
3565
  function orderBy(collection, iteratees, orders) {
3357
3566
  if (!Array.isArray(collection)) {
@@ -3362,13 +3571,13 @@
3362
3571
  orders = [];
3363
3572
  }
3364
3573
 
3365
- var result = collection.map(function(value, index) {
3574
+ var result = collection.map(function (value, index) {
3366
3575
  return {
3367
- criteria: iteratees.map(function(iteratee) {
3576
+ criteria: iteratees.map(function (iteratee) {
3368
3577
  return value[iteratee];
3369
3578
  }),
3370
3579
  index: index,
3371
- value: value
3580
+ value: value,
3372
3581
  };
3373
3582
  });
3374
3583
 
@@ -3393,7 +3602,7 @@
3393
3602
  return object.index - other.index;
3394
3603
  });
3395
3604
 
3396
- return result.map(function(res) {
3605
+ return result.map(function (res) {
3397
3606
  return res.value;
3398
3607
  });
3399
3608
  }
@@ -3429,7 +3638,7 @@
3429
3638
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
3430
3639
  */
3431
3640
  var formatSort = function formatSort(sortBy, defaults) {
3432
- var defaultInstructions = (defaults || []).map(function(sort) {
3641
+ var defaultInstructions = (defaults || []).map(function (sort) {
3433
3642
  return sort.split(':');
3434
3643
  });
3435
3644
 
@@ -3437,11 +3646,12 @@
3437
3646
  function preparePredicate(out, sort) {
3438
3647
  var sortInstruction = sort.split(':');
3439
3648
 
3440
- var matchingDefault = find$1(defaultInstructions, function(
3441
- defaultInstruction
3442
- ) {
3443
- return defaultInstruction[0] === sortInstruction[0];
3444
- });
3649
+ var matchingDefault = find$1(
3650
+ defaultInstructions,
3651
+ function (defaultInstruction) {
3652
+ return defaultInstruction[0] === sortInstruction[0];
3653
+ }
3654
+ );
3445
3655
 
3446
3656
  if (sortInstruction.length > 1 || !matchingDefault) {
3447
3657
  out[0].push(sortInstruction[0]);
@@ -3461,7 +3671,7 @@
3461
3671
  * Replaces a leading - with \-
3462
3672
  * @private
3463
3673
  * @param {any} value the facet value to replace
3464
- * @returns any
3674
+ * @returns {any} the escaped facet value or the value if it was not a string
3465
3675
  */
3466
3676
  function escapeFacetValue(value) {
3467
3677
  if (typeof value !== 'string') return value;
@@ -3473,7 +3683,7 @@
3473
3683
  * Replaces a leading \- with -
3474
3684
  * @private
3475
3685
  * @param {any} value the escaped facet value
3476
- * @returns any
3686
+ * @returns {any} the unescaped facet value or the value if it was not a string
3477
3687
  */
3478
3688
  function unescapeFacetValue$1(value) {
3479
3689
  if (typeof value !== 'string') return value;
@@ -3483,7 +3693,7 @@
3483
3693
 
3484
3694
  var escapeFacetValue_1 = {
3485
3695
  escapeFacetValue: escapeFacetValue,
3486
- unescapeFacetValue: unescapeFacetValue$1
3696
+ unescapeFacetValue: unescapeFacetValue$1,
3487
3697
  };
3488
3698
 
3489
3699
  var generateHierarchicalTree_1 = generateTrees;
@@ -3502,20 +3712,17 @@
3502
3712
  (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
3503
3713
  state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
3504
3714
  '';
3505
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
3506
- hierarchicalFacet
3507
- );
3508
- var hierarchicalRootPath = state._getHierarchicalRootPath(
3509
- hierarchicalFacet
3510
- );
3511
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
3512
- hierarchicalFacet
3513
- );
3715
+ var hierarchicalSeparator =
3716
+ state._getHierarchicalFacetSeparator(hierarchicalFacet);
3717
+ var hierarchicalRootPath =
3718
+ state._getHierarchicalRootPath(hierarchicalFacet);
3719
+ var hierarchicalShowParentLevel =
3720
+ state._getHierarchicalShowParentLevel(hierarchicalFacet);
3514
3721
  var sortBy = formatSort(
3515
3722
  state._getHierarchicalFacetSortBy(hierarchicalFacet)
3516
3723
  );
3517
3724
 
3518
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
3725
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
3519
3726
  return facetResult.exhaustive;
3520
3727
  });
3521
3728
 
@@ -3542,7 +3749,7 @@
3542
3749
  path: null, // root level, no path
3543
3750
  escapedValue: null,
3544
3751
  exhaustive: rootExhaustive,
3545
- data: null
3752
+ data: null,
3546
3753
  });
3547
3754
  };
3548
3755
  }
@@ -3571,7 +3778,7 @@
3571
3778
  * @type {object[]]} hierarchical data
3572
3779
  */
3573
3780
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
3574
- parent = find$1(data, function(subtree) {
3781
+ parent = find$1(data, function (subtree) {
3575
3782
  return subtree.isRefined;
3576
3783
  });
3577
3784
  level++;
@@ -3592,10 +3799,10 @@
3592
3799
  // showing up
3593
3800
 
3594
3801
  var picked = Object.keys(hierarchicalFacetResult.data)
3595
- .map(function(facetValue) {
3802
+ .map(function (facetValue) {
3596
3803
  return [facetValue, hierarchicalFacetResult.data[facetValue]];
3597
3804
  })
3598
- .filter(function(tuple) {
3805
+ .filter(function (tuple) {
3599
3806
  var facetValue = tuple[0];
3600
3807
  return onlyMatchingTree(
3601
3808
  facetValue,
@@ -3608,7 +3815,7 @@
3608
3815
  });
3609
3816
 
3610
3817
  parent.data = orderBy_1(
3611
- picked.map(function(tuple) {
3818
+ picked.map(function (tuple) {
3612
3819
  var facetValue = tuple[0];
3613
3820
  var facetCount = tuple[1];
3614
3821
 
@@ -3629,6 +3836,7 @@
3629
3836
  };
3630
3837
  }
3631
3838
 
3839
+ // eslint-disable-next-line max-params
3632
3840
  function onlyMatchingTree(
3633
3841
  facetValue,
3634
3842
  parentPath,
@@ -3685,7 +3893,7 @@
3685
3893
  currentRefinement === facetValue ||
3686
3894
  currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3687
3895
  exhaustive: exhaustive,
3688
- data: null
3896
+ data: null,
3689
3897
  };
3690
3898
  }
3691
3899
 
@@ -3736,12 +3944,14 @@
3736
3944
  */
3737
3945
 
3738
3946
  /**
3739
- * @param {string[]} attributes
3947
+ * Turn an array of attributes in an object of attributes with their position in the array as value
3948
+ * @param {string[]} attributes the list of attributes in the record
3949
+ * @return {object} the list of attributes indexed by attribute name
3740
3950
  */
3741
3951
  function getIndices(attributes) {
3742
3952
  var indices = {};
3743
3953
 
3744
- attributes.forEach(function(val, idx) {
3954
+ attributes.forEach(function (val, idx) {
3745
3955
  indices[val] = idx;
3746
3956
  });
3747
3957
 
@@ -3761,22 +3971,24 @@
3761
3971
  */
3762
3972
 
3763
3973
  /**
3764
- * @param {HierarchicalFacet[]} hierarchicalFacets
3765
- * @param {string} hierarchicalAttributeName
3974
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
3975
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
3976
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
3766
3977
  */
3767
3978
  function findMatchingHierarchicalFacetFromAttributeName(
3768
3979
  hierarchicalFacets,
3769
3980
  hierarchicalAttributeName
3770
3981
  ) {
3771
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
3772
- hierarchicalFacet
3773
- ) {
3774
- var facetNames = hierarchicalFacet.attributes || [];
3775
- return facetNames.indexOf(hierarchicalAttributeName) > -1;
3776
- });
3982
+ return find$1(
3983
+ hierarchicalFacets,
3984
+ function facetKeyMatchesAttribute(hierarchicalFacet) {
3985
+ var facetNames = hierarchicalFacet.attributes || [];
3986
+ return facetNames.indexOf(hierarchicalAttributeName) > -1;
3987
+ }
3988
+ );
3777
3989
  }
3778
3990
 
3779
- /*eslint-disable */
3991
+ // eslint-disable-next-line valid-jsdoc
3780
3992
  /**
3781
3993
  * Constructor for SearchResults
3782
3994
  * @class
@@ -3907,21 +4119,21 @@
3907
4119
  "index": "bestbuy"
3908
4120
  }
3909
4121
  **/
3910
- /*eslint-enable */
3911
4122
  function SearchResults(state, results, options) {
3912
4123
  var mainSubResponse = results[0];
3913
4124
 
3914
4125
  this._rawResults = results;
3915
4126
 
4127
+ // eslint-disable-next-line consistent-this
3916
4128
  var self = this;
3917
4129
 
3918
4130
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
3919
- Object.keys(mainSubResponse).forEach(function(key) {
4131
+ Object.keys(mainSubResponse).forEach(function (key) {
3920
4132
  self[key] = mainSubResponse[key];
3921
4133
  });
3922
4134
 
3923
4135
  // Make every key of the result options reachable from the instance
3924
- Object.keys(options || {}).forEach(function(key) {
4136
+ Object.keys(options || {}).forEach(function (key) {
3925
4137
  self[key] = options[key];
3926
4138
  });
3927
4139
 
@@ -3943,8 +4155,8 @@
3943
4155
  * all the records that match the search parameters. Each record is
3944
4156
  * augmented with a new attribute `_highlightResult`
3945
4157
  * which is an object keyed by attribute and with the following properties:
3946
- * - `value` : the value of the facet highlighted (html)
3947
- * - `matchLevel`: full, partial or none depending on how the query terms match
4158
+ * - `value` : the value of the facet highlighted (html)
4159
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
3948
4160
  * @name hits
3949
4161
  * @member {object[]}
3950
4162
  * @memberof SearchResults
@@ -4065,7 +4277,7 @@
4065
4277
  * @memberof SearchResults
4066
4278
  * @instance
4067
4279
  */
4068
- this.processingTimeMS = results.reduce(function(sum, result) {
4280
+ this.processingTimeMS = results.reduce(function (sum, result) {
4069
4281
  return result.processingTimeMS === undefined
4070
4282
  ? sum
4071
4283
  : sum + result.processingTimeMS;
@@ -4080,9 +4292,11 @@
4080
4292
  * disjunctive facets results
4081
4293
  * @member {SearchResults.HierarchicalFacet[]}
4082
4294
  */
4083
- this.hierarchicalFacets = state.hierarchicalFacets.map(function initFutureTree() {
4084
- return [];
4085
- });
4295
+ this.hierarchicalFacets = state.hierarchicalFacets.map(
4296
+ function initFutureTree() {
4297
+ return [];
4298
+ }
4299
+ );
4086
4300
  /**
4087
4301
  * other facets results
4088
4302
  * @member {SearchResults.Facet[]}
@@ -4100,7 +4314,7 @@
4100
4314
 
4101
4315
  var mainFacets = mainSubResponse.facets || {};
4102
4316
 
4103
- Object.keys(mainFacets).forEach(function(facetKey) {
4317
+ Object.keys(mainFacets).forEach(function (facetKey) {
4104
4318
  var facetValueObject = mainFacets[facetKey];
4105
4319
 
4106
4320
  var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
@@ -4112,13 +4326,13 @@
4112
4326
  // Place the hierarchicalFacet data at the correct index depending on
4113
4327
  // the attributes order that was defined at the helper initialization
4114
4328
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
4115
- var idxAttributeName = findIndex(state.hierarchicalFacets, function(f) {
4329
+ var idxAttributeName = findIndex(state.hierarchicalFacets, function (f) {
4116
4330
  return f.name === hierarchicalFacet.name;
4117
4331
  });
4118
4332
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
4119
4333
  attribute: facetKey,
4120
4334
  data: facetValueObject,
4121
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4335
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
4122
4336
  };
4123
4337
  } else {
4124
4338
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
@@ -4130,18 +4344,26 @@
4130
4344
  self.disjunctiveFacets[position] = {
4131
4345
  name: facetKey,
4132
4346
  data: facetValueObject,
4133
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4347
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
4134
4348
  };
4135
- assignFacetStats(self.disjunctiveFacets[position], mainSubResponse.facets_stats, facetKey);
4349
+ assignFacetStats(
4350
+ self.disjunctiveFacets[position],
4351
+ mainSubResponse.facets_stats,
4352
+ facetKey
4353
+ );
4136
4354
  }
4137
4355
  if (isFacetConjunctive) {
4138
4356
  position = facetsIndices[facetKey];
4139
4357
  self.facets[position] = {
4140
4358
  name: facetKey,
4141
4359
  data: facetValueObject,
4142
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4360
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
4143
4361
  };
4144
- assignFacetStats(self.facets[position], mainSubResponse.facets_stats, facetKey);
4362
+ assignFacetStats(
4363
+ self.facets[position],
4364
+ mainSubResponse.facets_stats,
4365
+ facetKey
4366
+ );
4145
4367
  }
4146
4368
  }
4147
4369
  });
@@ -4150,24 +4372,27 @@
4150
4372
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
4151
4373
 
4152
4374
  // aggregate the refined disjunctive facets
4153
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
4375
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
4154
4376
  var result = results[nextDisjunctiveResult];
4155
4377
  var facets = result && result.facets ? result.facets : {};
4156
4378
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
4157
4379
 
4158
4380
  // There should be only item in facets.
4159
- Object.keys(facets).forEach(function(dfacet) {
4381
+ Object.keys(facets).forEach(function (dfacet) {
4160
4382
  var facetResults = facets[dfacet];
4161
4383
 
4162
4384
  var position;
4163
4385
 
4164
4386
  if (hierarchicalFacet) {
4165
- position = findIndex(state.hierarchicalFacets, function(f) {
4387
+ position = findIndex(state.hierarchicalFacets, function (f) {
4166
4388
  return f.name === hierarchicalFacet.name;
4167
4389
  });
4168
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
4169
- return f.attribute === dfacet;
4170
- });
4390
+ var attributeIndex = findIndex(
4391
+ self.hierarchicalFacets[position],
4392
+ function (f) {
4393
+ return f.attribute === dfacet;
4394
+ }
4395
+ );
4171
4396
 
4172
4397
  // previous refinements and no results so not able to find it
4173
4398
  if (attributeIndex === -1) {
@@ -4182,20 +4407,31 @@
4182
4407
  } else {
4183
4408
  position = disjunctiveFacetsIndices[dfacet];
4184
4409
 
4185
- var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
4410
+ var dataFromMainRequest =
4411
+ (mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
4186
4412
 
4187
4413
  self.disjunctiveFacets[position] = {
4188
4414
  name: dfacet,
4189
4415
  data: defaultsPure({}, facetResults, dataFromMainRequest),
4190
- exhaustive: result.exhaustiveFacetsCount
4416
+ exhaustive: result.exhaustiveFacetsCount,
4191
4417
  };
4192
- assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
4418
+ assignFacetStats(
4419
+ self.disjunctiveFacets[position],
4420
+ result.facets_stats,
4421
+ dfacet
4422
+ );
4193
4423
 
4194
4424
  if (state.disjunctiveFacetsRefinements[dfacet]) {
4195
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
4425
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (
4426
+ refinementValue
4427
+ ) {
4196
4428
  // add the disjunctive refinements if it is no more retrieved
4197
- if (!self.disjunctiveFacets[position].data[refinementValue] &&
4198
- state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
4429
+ if (
4430
+ !self.disjunctiveFacets[position].data[refinementValue] &&
4431
+ state.disjunctiveFacetsRefinements[dfacet].indexOf(
4432
+ unescapeFacetValue$3(refinementValue)
4433
+ ) > -1
4434
+ ) {
4199
4435
  self.disjunctiveFacets[position].data[refinementValue] = 0;
4200
4436
  }
4201
4437
  });
@@ -4206,30 +4442,34 @@
4206
4442
  });
4207
4443
 
4208
4444
  // if we have some parent level values for hierarchical facets, merge them
4209
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
4445
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
4210
4446
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
4211
4447
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
4212
4448
 
4213
4449
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
4214
4450
  // if we are already at a root refinement (or no refinement at all), there is no
4215
4451
  // root level values request
4216
- if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
4452
+ if (
4453
+ currentRefinement.length === 0 ||
4454
+ currentRefinement[0].split(separator).length < 2
4455
+ ) {
4217
4456
  return;
4218
4457
  }
4219
4458
 
4220
- results.slice(nextDisjunctiveResult).forEach(function(result) {
4221
- var facets = result && result.facets
4222
- ? result.facets
4223
- : {};
4459
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
4460
+ var facets = result && result.facets ? result.facets : {};
4224
4461
 
4225
- Object.keys(facets).forEach(function(dfacet) {
4462
+ Object.keys(facets).forEach(function (dfacet) {
4226
4463
  var facetResults = facets[dfacet];
4227
- var position = findIndex(state.hierarchicalFacets, function(f) {
4464
+ var position = findIndex(state.hierarchicalFacets, function (f) {
4228
4465
  return f.name === hierarchicalFacet.name;
4229
4466
  });
4230
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
4231
- return f.attribute === dfacet;
4232
- });
4467
+ var attributeIndex = findIndex(
4468
+ self.hierarchicalFacets[position],
4469
+ function (f) {
4470
+ return f.attribute === dfacet;
4471
+ }
4472
+ );
4233
4473
 
4234
4474
  // previous refinements and no results so not able to find it
4235
4475
  if (attributeIndex === -1) {
@@ -4248,7 +4488,8 @@
4248
4488
 
4249
4489
  if (currentRefinement.length > 0) {
4250
4490
  var root = currentRefinement[0].split(separator)[0];
4251
- defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
4491
+ defaultData[root] =
4492
+ self.hierarchicalFacets[position][attributeIndex].data[root];
4252
4493
  }
4253
4494
 
4254
4495
  self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
@@ -4263,17 +4504,17 @@
4263
4504
  });
4264
4505
 
4265
4506
  // add the excludes
4266
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
4507
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
4267
4508
  var excludes = state.facetsExcludes[facetName];
4268
4509
  var position = facetsIndices[facetName];
4269
4510
 
4270
4511
  self.facets[position] = {
4271
4512
  name: facetName,
4272
4513
  data: mainFacets[facetName],
4273
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4514
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
4274
4515
  };
4275
- excludes.forEach(function(facetValue) {
4276
- self.facets[position] = self.facets[position] || {name: facetName};
4516
+ excludes.forEach(function (facetValue) {
4517
+ self.facets[position] = self.facets[position] || { name: facetName };
4277
4518
  self.facets[position].data = self.facets[position].data || {};
4278
4519
  self.facets[position].data[facetValue] = 0;
4279
4520
  });
@@ -4282,7 +4523,9 @@
4282
4523
  /**
4283
4524
  * @type {Array}
4284
4525
  */
4285
- this.hierarchicalFacets = this.hierarchicalFacets.map(generateHierarchicalTree_1(state));
4526
+ this.hierarchicalFacets = this.hierarchicalFacets.map(
4527
+ generateHierarchicalTree_1(state)
4528
+ );
4286
4529
 
4287
4530
  /**
4288
4531
  * @type {Array}
@@ -4302,14 +4545,16 @@
4302
4545
  * @param {string} name name of the faceted attribute
4303
4546
  * @return {SearchResults.Facet} the facet object
4304
4547
  */
4305
- SearchResults.prototype.getFacetByName = function(name) {
4548
+ SearchResults.prototype.getFacetByName = function (name) {
4306
4549
  function predicate(facet) {
4307
4550
  return facet.name === name;
4308
4551
  }
4309
4552
 
4310
- return find$1(this.facets, predicate) ||
4553
+ return (
4554
+ find$1(this.facets, predicate) ||
4311
4555
  find$1(this.disjunctiveFacets, predicate) ||
4312
- find$1(this.hierarchicalFacets, predicate);
4556
+ find$1(this.hierarchicalFacets, predicate)
4557
+ );
4313
4558
  };
4314
4559
 
4315
4560
  /**
@@ -4328,55 +4573,70 @@
4328
4573
  var facet = find$1(results.facets, predicate);
4329
4574
  if (!facet) return [];
4330
4575
 
4331
- return Object.keys(facet.data).map(function(name) {
4576
+ return Object.keys(facet.data).map(function (name) {
4332
4577
  var value = escapeFacetValue$2(name);
4333
4578
  return {
4334
4579
  name: name,
4335
4580
  escapedValue: value,
4336
4581
  count: facet.data[name],
4337
4582
  isRefined: results._state.isFacetRefined(attribute, value),
4338
- isExcluded: results._state.isExcludeRefined(attribute, name)
4583
+ isExcluded: results._state.isExcludeRefined(attribute, name),
4339
4584
  };
4340
4585
  });
4341
4586
  } else if (results._state.isDisjunctiveFacet(attribute)) {
4342
4587
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
4343
4588
  if (!disjunctiveFacet) return [];
4344
4589
 
4345
- return Object.keys(disjunctiveFacet.data).map(function(name) {
4590
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
4346
4591
  var value = escapeFacetValue$2(name);
4347
4592
  return {
4348
4593
  name: name,
4349
4594
  escapedValue: value,
4350
4595
  count: disjunctiveFacet.data[name],
4351
- isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
4596
+ isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
4352
4597
  };
4353
4598
  });
4354
4599
  } else if (results._state.isHierarchicalFacet(attribute)) {
4355
4600
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
4356
4601
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
4357
4602
 
4358
- var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
4359
- var currentRefinementSplit = unescapeFacetValue$3(
4603
+ var hierarchicalFacet =
4604
+ results._state.getHierarchicalFacetByName(attribute);
4605
+ var separator =
4606
+ results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
4607
+ var currentRefinement = unescapeFacetValue$3(
4360
4608
  results._state.getHierarchicalRefinement(attribute)[0] || ''
4361
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
4609
+ );
4610
+
4611
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
4612
+ currentRefinement = currentRefinement.replace(
4613
+ hierarchicalFacet.rootPath + separator,
4614
+ ''
4615
+ );
4616
+ }
4617
+
4618
+ var currentRefinementSplit = currentRefinement.split(separator);
4362
4619
  currentRefinementSplit.unshift(attribute);
4363
4620
 
4364
4621
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
4365
4622
 
4366
4623
  return hierarchicalFacetValues;
4367
4624
  }
4625
+
4626
+ return undefined;
4368
4627
  }
4369
4628
 
4370
4629
  /**
4371
4630
  * Set the isRefined of a hierarchical facet result based on the current state.
4372
4631
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
4373
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
4632
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
4374
4633
  * @param {number} depth recursion depth in the currentRefinement
4634
+ * @return {undefined} function mutates the item
4375
4635
  */
4376
4636
  function setIsRefined(item, currentRefinement, depth) {
4377
4637
  item.isRefined = item.name === currentRefinement[depth];
4378
4638
  if (item.data) {
4379
- item.data.forEach(function(child) {
4639
+ item.data.forEach(function (child) {
4380
4640
  setIsRefined(child, currentRefinement, depth + 1);
4381
4641
  });
4382
4642
  }
@@ -4385,10 +4645,11 @@
4385
4645
  /**
4386
4646
  * Sort nodes of a hierarchical or disjunctive facet results
4387
4647
  * @private
4388
- * @param {function} sortFn
4648
+ * @param {function} sortFn sort function to apply
4389
4649
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
4390
4650
  * @param {string[]} names attribute names
4391
4651
  * @param {number} [level=0] current index in the names array
4652
+ * @return {HierarchicalFacet|Array} sorted node
4392
4653
  */
4393
4654
  function recSort(sortFn, node, names, level) {
4394
4655
  level = level || 0;
@@ -4401,11 +4662,11 @@
4401
4662
  return node;
4402
4663
  }
4403
4664
 
4404
- var children = node.data.map(function(childNode) {
4665
+ var children = node.data.map(function (childNode) {
4405
4666
  return recSort(sortFn, childNode, names, level + 1);
4406
4667
  });
4407
4668
  var sortedChildren = sortFn(children, names[level]);
4408
- var newNode = defaultsPure({data: sortedChildren}, node);
4669
+ var newNode = defaultsPure({ data: sortedChildren }, node);
4409
4670
  return newNode;
4410
4671
  }
4411
4672
 
@@ -4426,7 +4687,7 @@
4426
4687
  * Sorts facet arrays via their facet ordering
4427
4688
  * @param {Array} facetValues the values
4428
4689
  * @param {FacetOrdering} facetOrdering the ordering
4429
- * @returns {Array}
4690
+ * @returns {Array} the sorted facet values
4430
4691
  */
4431
4692
  function sortViaFacetOrdering(facetValues, facetOrdering) {
4432
4693
  var orderedFacets = [];
@@ -4437,12 +4698,12 @@
4437
4698
  * an object with the keys being the values in order, the values their index:
4438
4699
  * ['one', 'two'] -> { one: 0, two: 1 }
4439
4700
  */
4440
- var reverseOrder = order.reduce(function(acc, name, i) {
4701
+ var reverseOrder = order.reduce(function (acc, name, i) {
4441
4702
  acc[name] = i;
4442
4703
  return acc;
4443
4704
  }, {});
4444
4705
 
4445
- facetValues.forEach(function(item) {
4706
+ facetValues.forEach(function (item) {
4446
4707
  // hierarchical facets get sorted using their raw name
4447
4708
  var name = item.path || item.name;
4448
4709
  if (reverseOrder[name] !== undefined) {
@@ -4452,7 +4713,7 @@
4452
4713
  }
4453
4714
  });
4454
4715
 
4455
- orderedFacets = orderedFacets.filter(function(facet) {
4716
+ orderedFacets = orderedFacets.filter(function (facet) {
4456
4717
  return facet;
4457
4718
  });
4458
4719
 
@@ -4461,7 +4722,10 @@
4461
4722
  if (sortRemainingBy === 'hidden') {
4462
4723
  return orderedFacets;
4463
4724
  } else if (sortRemainingBy === 'alpha') {
4464
- ordering = [['path', 'name'], ['asc', 'asc']];
4725
+ ordering = [
4726
+ ['path', 'name'],
4727
+ ['asc', 'asc'],
4728
+ ];
4465
4729
  } else {
4466
4730
  ordering = [['count'], ['desc']];
4467
4731
  }
@@ -4474,7 +4738,7 @@
4474
4738
  /**
4475
4739
  * @param {SearchResults} results the search results class
4476
4740
  * @param {string} attribute the attribute to retrieve ordering of
4477
- * @returns {FacetOrdering=}
4741
+ * @returns {FacetOrdering | undefined} the facet ordering
4478
4742
  */
4479
4743
  function getFacetOrdering(results, attribute) {
4480
4744
  return (
@@ -4533,7 +4797,7 @@
4533
4797
  * });
4534
4798
  * });
4535
4799
  */
4536
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
4800
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
4537
4801
  var facetValues = extractNormalizedFacetValues(this, attribute);
4538
4802
  if (!facetValues) {
4539
4803
  return undefined;
@@ -4543,9 +4807,10 @@
4543
4807
  sortBy: SearchResults.DEFAULT_SORT,
4544
4808
  // if no sortBy is given, attempt to sort based on facetOrdering
4545
4809
  // if it is given, we still allow to sort via facet ordering first
4546
- facetOrdering: !(opts && opts.sortBy)
4810
+ facetOrdering: !(opts && opts.sortBy),
4547
4811
  });
4548
4812
 
4813
+ // eslint-disable-next-line consistent-this
4549
4814
  var results = this;
4550
4815
  var attributes;
4551
4816
  if (Array.isArray(facetValues)) {
@@ -4555,25 +4820,29 @@
4555
4820
  attributes = config.attributes;
4556
4821
  }
4557
4822
 
4558
- return recSort(function(data, facetName) {
4559
- if (options.facetOrdering) {
4560
- var facetOrdering = getFacetOrdering(results, facetName);
4561
- if (Boolean(facetOrdering)) {
4562
- return sortViaFacetOrdering(data, facetOrdering);
4823
+ return recSort(
4824
+ function (data, facetName) {
4825
+ if (options.facetOrdering) {
4826
+ var facetOrdering = getFacetOrdering(results, facetName);
4827
+ if (facetOrdering) {
4828
+ return sortViaFacetOrdering(data, facetOrdering);
4829
+ }
4563
4830
  }
4564
- }
4565
4831
 
4566
- if (Array.isArray(options.sortBy)) {
4567
- var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4568
- return orderBy_1(data, order[0], order[1]);
4569
- } else if (typeof options.sortBy === 'function') {
4570
- return vanillaSortFn(options.sortBy, data);
4571
- }
4572
- throw new Error(
4573
- 'options.sortBy is optional but if defined it must be ' +
4574
- 'either an array of string (predicates) or a sorting function'
4575
- );
4576
- }, facetValues, attributes);
4832
+ if (Array.isArray(options.sortBy)) {
4833
+ var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4834
+ return orderBy_1(data, order[0], order[1]);
4835
+ } else if (typeof options.sortBy === 'function') {
4836
+ return vanillaSortFn(options.sortBy, data);
4837
+ }
4838
+ throw new Error(
4839
+ 'options.sortBy is optional but if defined it must be ' +
4840
+ 'either an array of string (predicates) or a sorting function'
4841
+ );
4842
+ },
4843
+ facetValues,
4844
+ attributes
4845
+ );
4577
4846
  };
4578
4847
 
4579
4848
  /**
@@ -4582,7 +4851,7 @@
4582
4851
  * @param {string} attribute name of the faceted attribute
4583
4852
  * @return {object} The stats of the facet
4584
4853
  */
4585
- SearchResults.prototype.getFacetStats = function(attribute) {
4854
+ SearchResults.prototype.getFacetStats = function (attribute) {
4586
4855
  if (this._state.isConjunctiveFacet(attribute)) {
4587
4856
  return getFacetStatsIfAvailable(this.facets, attribute);
4588
4857
  } else if (this._state.isDisjunctiveFacet(attribute)) {
@@ -4599,10 +4868,11 @@
4599
4868
 
4600
4869
  /**
4601
4870
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
4602
- * @param {string} facetName
4871
+ * @param {string} facetName The attribute to look for
4872
+ * @return {object|undefined} The stats of the facet
4603
4873
  */
4604
4874
  function getFacetStatsIfAvailable(facetList, facetName) {
4605
- var data = find$1(facetList, function(facet) {
4875
+ var data = find$1(facetList, function (facet) {
4606
4876
  return facet.name === facetName;
4607
4877
  });
4608
4878
  return data && data.stats;
@@ -4620,53 +4890,76 @@
4620
4890
  *
4621
4891
  * @return {Array.<Refinement>} all the refinements
4622
4892
  */
4623
- SearchResults.prototype.getRefinements = function() {
4893
+ SearchResults.prototype.getRefinements = function () {
4624
4894
  var state = this._state;
4895
+ // eslint-disable-next-line consistent-this
4625
4896
  var results = this;
4626
4897
  var res = [];
4627
4898
 
4628
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
4629
- state.facetsRefinements[attributeName].forEach(function(name) {
4630
- res.push(getRefinement(state, 'facet', attributeName, name, results.facets));
4899
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
4900
+ state.facetsRefinements[attributeName].forEach(function (name) {
4901
+ res.push(
4902
+ getRefinement(state, 'facet', attributeName, name, results.facets)
4903
+ );
4631
4904
  });
4632
4905
  });
4633
4906
 
4634
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
4635
- state.facetsExcludes[attributeName].forEach(function(name) {
4636
- res.push(getRefinement(state, 'exclude', attributeName, name, results.facets));
4907
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
4908
+ state.facetsExcludes[attributeName].forEach(function (name) {
4909
+ res.push(
4910
+ getRefinement(state, 'exclude', attributeName, name, results.facets)
4911
+ );
4637
4912
  });
4638
4913
  });
4639
4914
 
4640
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
4641
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
4642
- res.push(getRefinement(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
4915
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
4916
+ attributeName
4917
+ ) {
4918
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
4919
+ res.push(
4920
+ getRefinement(
4921
+ state,
4922
+ 'disjunctive',
4923
+ attributeName,
4924
+ name,
4925
+ results.disjunctiveFacets
4926
+ )
4927
+ );
4643
4928
  });
4644
4929
  });
4645
4930
 
4646
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
4647
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
4648
- res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
4931
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
4932
+ attributeName
4933
+ ) {
4934
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
4935
+ res.push(
4936
+ getHierarchicalRefinement(
4937
+ state,
4938
+ attributeName,
4939
+ name,
4940
+ results.hierarchicalFacets
4941
+ )
4942
+ );
4649
4943
  });
4650
4944
  });
4651
4945
 
4652
-
4653
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
4946
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
4654
4947
  var operators = state.numericRefinements[attributeName];
4655
- Object.keys(operators).forEach(function(operator) {
4656
- operators[operator].forEach(function(value) {
4948
+ Object.keys(operators).forEach(function (operator) {
4949
+ operators[operator].forEach(function (value) {
4657
4950
  res.push({
4658
4951
  type: 'numeric',
4659
4952
  attributeName: attributeName,
4660
4953
  name: value,
4661
4954
  numericValue: value,
4662
- operator: operator
4955
+ operator: operator,
4663
4956
  });
4664
4957
  });
4665
4958
  });
4666
4959
  });
4667
4960
 
4668
- state.tagRefinements.forEach(function(name) {
4669
- res.push({type: 'tag', attributeName: '_tags', name: name});
4961
+ state.tagRefinements.forEach(function (name) {
4962
+ res.push({ type: 'tag', attributeName: '_tags', name: name });
4670
4963
  });
4671
4964
 
4672
4965
  return res;
@@ -4680,14 +4973,15 @@
4680
4973
  */
4681
4974
 
4682
4975
  /**
4683
- * @param {*} state
4684
- * @param {*} type
4685
- * @param {string} attributeName
4686
- * @param {*} name
4687
- * @param {Facet[]} resultsFacets
4976
+ * @param {SearchParameters} state the current state
4977
+ * @param {string} type the type of the refinement
4978
+ * @param {string} attributeName The attribute of the facet
4979
+ * @param {*} name The name of the facet
4980
+ * @param {Facet[]} resultsFacets facets from the results
4981
+ * @return {Refinement} the refinement
4688
4982
  */
4689
4983
  function getRefinement(state, type, attributeName, name, resultsFacets) {
4690
- var facet = find$1(resultsFacets, function(f) {
4984
+ var facet = find$1(resultsFacets, function (f) {
4691
4985
  return f.name === attributeName;
4692
4986
  });
4693
4987
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
@@ -4698,27 +4992,29 @@
4698
4992
  attributeName: attributeName,
4699
4993
  name: name,
4700
4994
  count: count,
4701
- exhaustive: exhaustive
4995
+ exhaustive: exhaustive,
4702
4996
  };
4703
4997
  }
4704
4998
 
4705
4999
  /**
4706
- * @param {*} state
4707
- * @param {string} attributeName
4708
- * @param {*} name
4709
- * @param {Facet[]} resultsFacets
5000
+ * @param {SearchParameters} state the current state
5001
+ * @param {string} attributeName the attribute of the hierarchical facet
5002
+ * @param {string} name the name of the facet
5003
+ * @param {Facet[]} resultsFacets facets from the results
5004
+ * @return {HierarchicalFacet} the hierarchical facet
4710
5005
  */
4711
5006
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
4712
5007
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
4713
5008
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
4714
5009
  var split = name.split(separator);
4715
- var rootFacet = find$1(resultsFacets, function(facet) {
5010
+ var rootFacet = find$1(resultsFacets, function (facet) {
4716
5011
  return facet.name === attributeName;
4717
5012
  });
4718
5013
 
4719
- var facet = split.reduce(function(intermediateFacet, part) {
5014
+ var facet = split.reduce(function (intermediateFacet, part) {
4720
5015
  var newFacet =
4721
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
5016
+ intermediateFacet &&
5017
+ find$1(intermediateFacet.data, function (f) {
4722
5018
  return f.name === part;
4723
5019
  });
4724
5020
  return newFacet !== undefined ? newFacet : intermediateFacet;
@@ -4733,7 +5029,7 @@
4733
5029
  attributeName: attributeName,
4734
5030
  name: path,
4735
5031
  count: count,
4736
- exhaustive: exhaustive
5032
+ exhaustive: exhaustive,
4737
5033
  };
4738
5034
  }
4739
5035
 
@@ -5048,8 +5344,8 @@
5048
5344
  value: ctor,
5049
5345
  enumerable: false,
5050
5346
  writable: true,
5051
- configurable: true
5052
- }
5347
+ configurable: true,
5348
+ },
5053
5349
  });
5054
5350
  }
5055
5351
 
@@ -5064,6 +5360,8 @@
5064
5360
  * - result: when the response is retrieved from Algolia and is processed.
5065
5361
  * This event contains a {@link SearchResults} object and the
5066
5362
  * {@link SearchParameters} corresponding to this answer.
5363
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
5364
+ * @param {function} fn the function to create the derived state
5067
5365
  */
5068
5366
  function DerivedHelper(mainHelper, fn) {
5069
5367
  this.main = mainHelper;
@@ -5078,12 +5376,12 @@
5078
5376
  * @return {undefined}
5079
5377
  * @throws Error if the derived helper is already detached
5080
5378
  */
5081
- DerivedHelper.prototype.detach = function() {
5379
+ DerivedHelper.prototype.detach = function () {
5082
5380
  this.removeAllListeners();
5083
5381
  this.main.detachDerivedHelper(this);
5084
5382
  };
5085
5383
 
5086
- DerivedHelper.prototype.getModifiedState = function(parameters) {
5384
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
5087
5385
  return this.fn(parameters);
5088
5386
  };
5089
5387
 
@@ -5091,10 +5389,10 @@
5091
5389
 
5092
5390
  function sortObject(obj) {
5093
5391
  return Object.keys(obj)
5094
- .sort(function(a, b) {
5392
+ .sort(function (a, b) {
5095
5393
  return a.localeCompare(b);
5096
5394
  })
5097
- .reduce(function(acc, curr) {
5395
+ .reduce(function (acc, curr) {
5098
5396
  acc[curr] = obj[curr];
5099
5397
  return acc;
5100
5398
  }, {});
@@ -5105,6 +5403,8 @@
5105
5403
  * Get all the queries to send to the client, those queries can used directly
5106
5404
  * with the Algolia client.
5107
5405
  * @private
5406
+ * @param {string} index The name of the index
5407
+ * @param {SearchParameters} state The state from which to get the queries
5108
5408
  * @return {object[]} The queries
5109
5409
  */
5110
5410
  _getQueries: function getQueries(index, state) {
@@ -5113,39 +5413,47 @@
5113
5413
  // One query for the hits
5114
5414
  queries.push({
5115
5415
  indexName: index,
5116
- params: requestBuilder._getHitsSearchParams(state)
5416
+ params: requestBuilder._getHitsSearchParams(state),
5117
5417
  });
5118
5418
 
5119
5419
  // One for each disjunctive facets
5120
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
5420
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
5121
5421
  queries.push({
5122
5422
  indexName: index,
5123
- params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
5423
+ params: requestBuilder._getDisjunctiveFacetSearchParams(
5424
+ state,
5425
+ refinedFacet
5426
+ ),
5124
5427
  });
5125
5428
  });
5126
5429
 
5127
5430
  // More to get the parent levels of the hierarchical facets when refined
5128
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
5431
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
5129
5432
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
5130
5433
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
5131
5434
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5132
5435
 
5133
5436
  // If we are deeper than level 0 (starting from `beer > IPA`)
5134
5437
  // we want to get all parent values
5135
- if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
5438
+ if (
5439
+ currentRefinement.length > 0 &&
5440
+ currentRefinement[0].split(separator).length > 1
5441
+ ) {
5136
5442
  // We generate a map of the filters we will use for our facet values queries
5137
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
5138
- function createFiltersMap(map, segment, level) {
5443
+ var filtersMap = currentRefinement[0]
5444
+ .split(separator)
5445
+ .slice(0, -1)
5446
+ .reduce(function createFiltersMap(map, segment, level) {
5139
5447
  return map.concat({
5140
5448
  attribute: hierarchicalFacet.attributes[level],
5141
- value: level === 0
5142
- ? segment
5143
- : [map[map.length - 1].value, segment].join(separator)
5449
+ value:
5450
+ level === 0
5451
+ ? segment
5452
+ : [map[map.length - 1].value, segment].join(separator),
5144
5453
  });
5145
- }
5146
- , []);
5454
+ }, []);
5147
5455
 
5148
- filtersMap.forEach(function(filter, level) {
5456
+ filtersMap.forEach(function (filter, level) {
5149
5457
  var params = requestBuilder._getDisjunctiveFacetSearchParams(
5150
5458
  state,
5151
5459
  filter.attribute,
@@ -5154,37 +5462,48 @@
5154
5462
 
5155
5463
  // Keep facet filters unrelated to current hierarchical attributes
5156
5464
  function hasHierarchicalFacetFilter(value) {
5157
- return hierarchicalFacet.attributes.some(function(attribute) {
5465
+ return hierarchicalFacet.attributes.some(function (attribute) {
5158
5466
  return attribute === value.split(':')[0];
5159
5467
  });
5160
5468
  }
5161
5469
 
5162
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
5163
- if (Array.isArray(facetFilter)) {
5164
- var filtered = facetFilter.filter(function(filterValue) {
5165
- return !hasHierarchicalFacetFilter(filterValue);
5166
- });
5470
+ var filteredFacetFilters = (params.facetFilters || []).reduce(
5471
+ function (acc, facetFilter) {
5472
+ if (Array.isArray(facetFilter)) {
5473
+ var filtered = facetFilter.filter(function (filterValue) {
5474
+ return !hasHierarchicalFacetFilter(filterValue);
5475
+ });
5167
5476
 
5168
- if (filtered.length > 0) {
5169
- acc.push(filtered);
5477
+ if (filtered.length > 0) {
5478
+ acc.push(filtered);
5479
+ }
5170
5480
  }
5171
- }
5172
5481
 
5173
- if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
5174
- acc.push(facetFilter);
5175
- }
5482
+ if (
5483
+ typeof facetFilter === 'string' &&
5484
+ !hasHierarchicalFacetFilter(facetFilter)
5485
+ ) {
5486
+ acc.push(facetFilter);
5487
+ }
5176
5488
 
5177
- return acc;
5178
- }, []);
5489
+ return acc;
5490
+ },
5491
+ []
5492
+ );
5179
5493
 
5180
5494
  var parent = filtersMap[level - 1];
5181
5495
  if (level > 0) {
5182
- params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
5496
+ params.facetFilters = filteredFacetFilters.concat(
5497
+ parent.attribute + ':' + parent.value
5498
+ );
5183
5499
  } else {
5184
- params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
5500
+ params.facetFilters =
5501
+ filteredFacetFilters.length > 0
5502
+ ? filteredFacetFilters
5503
+ : undefined;
5185
5504
  }
5186
5505
 
5187
- queries.push({indexName: index, params: params});
5506
+ queries.push({ indexName: index, params: params });
5188
5507
  });
5189
5508
  }
5190
5509
  });
@@ -5195,20 +5514,20 @@
5195
5514
  /**
5196
5515
  * Build search parameters used to fetch hits
5197
5516
  * @private
5198
- * @return {object.<string, any>}
5517
+ * @param {SearchParameters} state The state from which to get the queries
5518
+ * @return {object.<string, any>} The search parameters for hits
5199
5519
  */
5200
- _getHitsSearchParams: function(state) {
5520
+ _getHitsSearchParams: function (state) {
5201
5521
  var facets = state.facets
5202
5522
  .concat(state.disjunctiveFacets)
5203
5523
  .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
5204
5524
 
5205
-
5206
5525
  var facetFilters = requestBuilder._getFacetFilters(state);
5207
5526
  var numericFilters = requestBuilder._getNumericFilters(state);
5208
5527
  var tagFilters = requestBuilder._getTagFilters(state);
5209
5528
  var additionalParams = {
5210
5529
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
5211
- tagFilters: tagFilters
5530
+ tagFilters: tagFilters,
5212
5531
  };
5213
5532
 
5214
5533
  if (facetFilters.length > 0) {
@@ -5225,19 +5544,28 @@
5225
5544
  /**
5226
5545
  * Build search parameters used to fetch a disjunctive facet
5227
5546
  * @private
5547
+ * @param {SearchParameters} state The state from which to get the queries
5228
5548
  * @param {string} facet the associated facet name
5229
5549
  * @param {boolean} hierarchicalRootLevel ?? FIXME
5230
- * @return {object}
5550
+ * @return {object} The search parameters for a disjunctive facet
5231
5551
  */
5232
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
5233
- var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
5552
+ _getDisjunctiveFacetSearchParams: function (
5553
+ state,
5554
+ facet,
5555
+ hierarchicalRootLevel
5556
+ ) {
5557
+ var facetFilters = requestBuilder._getFacetFilters(
5558
+ state,
5559
+ facet,
5560
+ hierarchicalRootLevel
5561
+ );
5234
5562
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
5235
5563
  var tagFilters = requestBuilder._getTagFilters(state);
5236
5564
  var additionalParams = {
5237
5565
  hitsPerPage: 0,
5238
5566
  page: 0,
5239
5567
  analytics: false,
5240
- clickAnalytics: false
5568
+ clickAnalytics: false,
5241
5569
  };
5242
5570
 
5243
5571
  if (tagFilters.length > 0) {
@@ -5247,11 +5575,12 @@
5247
5575
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
5248
5576
 
5249
5577
  if (hierarchicalFacet) {
5250
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
5251
- state,
5252
- hierarchicalFacet,
5253
- hierarchicalRootLevel
5254
- );
5578
+ additionalParams.facets =
5579
+ requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
5580
+ state,
5581
+ hierarchicalFacet,
5582
+ hierarchicalRootLevel
5583
+ );
5255
5584
  } else {
5256
5585
  additionalParams.facets = facet;
5257
5586
  }
@@ -5270,24 +5599,25 @@
5270
5599
  /**
5271
5600
  * Return the numeric filters in an algolia request fashion
5272
5601
  * @private
5602
+ * @param {SearchParameters} state the state from which to get the filters
5273
5603
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
5274
5604
  * @return {string[]} the numeric filters in the algolia format
5275
5605
  */
5276
- _getNumericFilters: function(state, facetName) {
5606
+ _getNumericFilters: function (state, facetName) {
5277
5607
  if (state.numericFilters) {
5278
5608
  return state.numericFilters;
5279
5609
  }
5280
5610
 
5281
5611
  var numericFilters = [];
5282
5612
 
5283
- Object.keys(state.numericRefinements).forEach(function(attribute) {
5613
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
5284
5614
  var operators = state.numericRefinements[attribute] || {};
5285
- Object.keys(operators).forEach(function(operator) {
5615
+ Object.keys(operators).forEach(function (operator) {
5286
5616
  var values = operators[operator] || [];
5287
5617
  if (facetName !== attribute) {
5288
- values.forEach(function(value) {
5618
+ values.forEach(function (value) {
5289
5619
  if (Array.isArray(value)) {
5290
- var vs = value.map(function(v) {
5620
+ var vs = value.map(function (v) {
5291
5621
  return attribute + operator + v;
5292
5622
  });
5293
5623
  numericFilters.push(vs);
@@ -5303,11 +5633,12 @@
5303
5633
  },
5304
5634
 
5305
5635
  /**
5306
- * Return the tags filters depending
5636
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
5307
5637
  * @private
5308
- * @return {string}
5638
+ * @param {SearchParameters} state the state from which to get the filters
5639
+ * @return {string} Tag filters in a single string
5309
5640
  */
5310
- _getTagFilters: function(state) {
5641
+ _getTagFilters: function (state) {
5311
5642
  if (state.tagFilters) {
5312
5643
  return state.tagFilters;
5313
5644
  }
@@ -5315,50 +5646,52 @@
5315
5646
  return state.tagRefinements.join(',');
5316
5647
  },
5317
5648
 
5318
-
5319
5649
  /**
5320
5650
  * Build facetFilters parameter based on current refinements. The array returned
5321
5651
  * contains strings representing the facet filters in the algolia format.
5322
5652
  * @private
5653
+ * @param {SearchParameters} state The state from which to get the queries
5323
5654
  * @param {string} [facet] if set, the current disjunctive facet
5324
- * @return {array.<string>}
5655
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
5656
+ * @return {array.<string>} The facet filters in the algolia format
5325
5657
  */
5326
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
5658
+ _getFacetFilters: function (state, facet, hierarchicalRootLevel) {
5327
5659
  var facetFilters = [];
5328
5660
 
5329
5661
  var facetsRefinements = state.facetsRefinements || {};
5330
- Object.keys(facetsRefinements).forEach(function(facetName) {
5662
+ Object.keys(facetsRefinements).forEach(function (facetName) {
5331
5663
  var facetValues = facetsRefinements[facetName] || [];
5332
- facetValues.forEach(function(facetValue) {
5664
+ facetValues.forEach(function (facetValue) {
5333
5665
  facetFilters.push(facetName + ':' + facetValue);
5334
5666
  });
5335
5667
  });
5336
5668
 
5337
5669
  var facetsExcludes = state.facetsExcludes || {};
5338
- Object.keys(facetsExcludes).forEach(function(facetName) {
5670
+ Object.keys(facetsExcludes).forEach(function (facetName) {
5339
5671
  var facetValues = facetsExcludes[facetName] || [];
5340
- facetValues.forEach(function(facetValue) {
5672
+ facetValues.forEach(function (facetValue) {
5341
5673
  facetFilters.push(facetName + ':-' + facetValue);
5342
5674
  });
5343
5675
  });
5344
5676
 
5345
5677
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
5346
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
5678
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
5347
5679
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
5348
5680
  if (facetName === facet || !facetValues || facetValues.length === 0) {
5349
5681
  return;
5350
5682
  }
5351
5683
  var orFilters = [];
5352
5684
 
5353
- facetValues.forEach(function(facetValue) {
5685
+ facetValues.forEach(function (facetValue) {
5354
5686
  orFilters.push(facetName + ':' + facetValue);
5355
5687
  });
5356
5688
 
5357
5689
  facetFilters.push(orFilters);
5358
5690
  });
5359
5691
 
5360
- var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
5361
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
5692
+ var hierarchicalFacetsRefinements =
5693
+ state.hierarchicalFacetsRefinements || {};
5694
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
5362
5695
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
5363
5696
  var facetValue = facetValues[0];
5364
5697
 
@@ -5376,8 +5709,13 @@
5376
5709
  if (facet === facetName) {
5377
5710
  // if we are at the root level already, no need to ask for facet values, we get them from
5378
5711
  // the hits query
5379
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
5380
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
5712
+ if (
5713
+ facetValue.indexOf(separator) === -1 ||
5714
+ (!rootPath && hierarchicalRootLevel === true) ||
5715
+ (rootPath &&
5716
+ rootPath.split(separator).length ===
5717
+ facetValue.split(separator).length)
5718
+ ) {
5381
5719
  return;
5382
5720
  }
5383
5721
 
@@ -5404,13 +5742,18 @@
5404
5742
  return facetFilters;
5405
5743
  },
5406
5744
 
5407
- _getHitsHierarchicalFacetsAttributes: function(state) {
5745
+ _getHitsHierarchicalFacetsAttributes: function (state) {
5408
5746
  var out = [];
5409
5747
 
5410
5748
  return state.hierarchicalFacets.reduce(
5411
5749
  // ask for as much levels as there's hierarchical refinements
5412
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
5413
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
5750
+ function getHitsAttributesForHierarchicalFacet(
5751
+ allAttributes,
5752
+ hierarchicalFacet
5753
+ ) {
5754
+ var hierarchicalRefinement = state.getHierarchicalRefinement(
5755
+ hierarchicalFacet.name
5756
+ )[0];
5414
5757
 
5415
5758
  // if no refinement, ask for root level
5416
5759
  if (!hierarchicalRefinement) {
@@ -5423,10 +5766,16 @@
5423
5766
  var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
5424
5767
 
5425
5768
  return allAttributes.concat(newAttributes);
5426
- }, out);
5769
+ },
5770
+ out
5771
+ );
5427
5772
  },
5428
5773
 
5429
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
5774
+ _getDisjunctiveHierarchicalFacetAttribute: function (
5775
+ state,
5776
+ hierarchicalFacet,
5777
+ rootLevel
5778
+ ) {
5430
5779
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5431
5780
  if (rootLevel === true) {
5432
5781
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -5438,7 +5787,8 @@
5438
5787
  return [hierarchicalFacet.attributes[attributeIndex]];
5439
5788
  }
5440
5789
 
5441
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5790
+ var hierarchicalRefinement =
5791
+ state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5442
5792
  // if refinement is 'beers > IPA > Flying dog',
5443
5793
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
5444
5794
 
@@ -5446,28 +5796,30 @@
5446
5796
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
5447
5797
  },
5448
5798
 
5449
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
5450
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
5451
- state.clearRefinements(facetName) :
5452
- state;
5799
+ getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
5800
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
5801
+ ? state.clearRefinements(facetName)
5802
+ : state;
5453
5803
  var searchForFacetSearchParameters = {
5454
5804
  facetQuery: query,
5455
- facetName: facetName
5805
+ facetName: facetName,
5456
5806
  };
5457
5807
  if (typeof maxFacetHits === 'number') {
5458
5808
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
5459
5809
  }
5460
- return sortObject(merge_1(
5461
- {},
5462
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5463
- searchForFacetSearchParameters
5464
- ));
5465
- }
5810
+ return sortObject(
5811
+ merge_1(
5812
+ {},
5813
+ requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5814
+ searchForFacetSearchParameters
5815
+ )
5816
+ );
5817
+ },
5466
5818
  };
5467
5819
 
5468
5820
  var requestBuilder_1 = requestBuilder;
5469
5821
 
5470
- var version$1 = '3.13.2';
5822
+ var version$1 = '3.13.5';
5471
5823
 
5472
5824
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
5473
5825
 
@@ -5597,19 +5949,19 @@
5597
5949
  * method is called, it triggers a `search` event. The results will
5598
5950
  * be available through the `result` event. If an error occurs, an
5599
5951
  * `error` will be fired instead.
5600
- * @return {AlgoliaSearchHelper}
5952
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5601
5953
  * @fires search
5602
5954
  * @fires result
5603
5955
  * @fires error
5604
5956
  * @chainable
5605
5957
  */
5606
- AlgoliaSearchHelper.prototype.search = function() {
5607
- this._search({onlyWithDerivedHelpers: false});
5958
+ AlgoliaSearchHelper.prototype.search = function () {
5959
+ this._search({ onlyWithDerivedHelpers: false });
5608
5960
  return this;
5609
5961
  };
5610
5962
 
5611
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
5612
- this._search({onlyWithDerivedHelpers: true});
5963
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
5964
+ this._search({ onlyWithDerivedHelpers: true });
5613
5965
  return this;
5614
5966
  };
5615
5967
 
@@ -5618,7 +5970,7 @@
5618
5970
  * for the hits
5619
5971
  * @return {object} Query Parameters
5620
5972
  */
5621
- AlgoliaSearchHelper.prototype.getQuery = function() {
5973
+ AlgoliaSearchHelper.prototype.getQuery = function () {
5622
5974
  var state = this.state;
5623
5975
  return requestBuilder_1._getHitsSearchParams(state);
5624
5976
  };
@@ -5630,7 +5982,7 @@
5630
5982
  * same as a search call before calling searchOnce.
5631
5983
  * @param {object} options can contain all the parameters that can be set to SearchParameters
5632
5984
  * plus the index
5633
- * @param {function} [callback] optional callback executed when the response from the
5985
+ * @param {function} [cb] optional callback executed when the response from the
5634
5986
  * server is back.
5635
5987
  * @return {promise|undefined} if a callback is passed the method returns undefined
5636
5988
  * otherwise it returns a promise containing an object with two keys :
@@ -5659,21 +6011,24 @@
5659
6011
  * // }
5660
6012
  * }
5661
6013
  */
5662
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
5663
- var tempState = !options ? this.state : this.state.setQueryParameters(options);
6014
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
6015
+ var tempState = !options
6016
+ ? this.state
6017
+ : this.state.setQueryParameters(options);
5664
6018
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
6019
+ // eslint-disable-next-line consistent-this
5665
6020
  var self = this;
5666
6021
 
5667
6022
  this._currentNbQueries++;
5668
6023
 
5669
6024
  this.emit('searchOnce', {
5670
- state: tempState
6025
+ state: tempState,
5671
6026
  });
5672
6027
 
5673
6028
  if (cb) {
5674
6029
  this.client
5675
6030
  .search(queries)
5676
- .then(function(content) {
6031
+ .then(function (content) {
5677
6032
  self._currentNbQueries--;
5678
6033
  if (self._currentNbQueries === 0) {
5679
6034
  self.emit('searchQueueEmpty');
@@ -5681,7 +6036,7 @@
5681
6036
 
5682
6037
  cb(null, new SearchResults_1(tempState, content.results), tempState);
5683
6038
  })
5684
- .catch(function(err) {
6039
+ .catch(function (err) {
5685
6040
  self._currentNbQueries--;
5686
6041
  if (self._currentNbQueries === 0) {
5687
6042
  self.emit('searchQueueEmpty');
@@ -5693,22 +6048,25 @@
5693
6048
  return undefined;
5694
6049
  }
5695
6050
 
5696
- return this.client.search(queries).then(function(content) {
5697
- self._currentNbQueries--;
5698
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5699
- return {
5700
- content: new SearchResults_1(tempState, content.results),
5701
- state: tempState,
5702
- _originalResponse: content
5703
- };
5704
- }, function(e) {
5705
- self._currentNbQueries--;
5706
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5707
- throw e;
5708
- });
6051
+ return this.client.search(queries).then(
6052
+ function (content) {
6053
+ self._currentNbQueries--;
6054
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
6055
+ return {
6056
+ content: new SearchResults_1(tempState, content.results),
6057
+ state: tempState,
6058
+ _originalResponse: content,
6059
+ };
6060
+ },
6061
+ function (e) {
6062
+ self._currentNbQueries--;
6063
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
6064
+ throw e;
6065
+ }
6066
+ );
5709
6067
  };
5710
6068
 
5711
- /**
6069
+ /**
5712
6070
  * Start the search for answers with the parameters set in the state.
5713
6071
  * This method returns a promise.
5714
6072
  * @param {Object} options - the options for answers API call
@@ -5719,7 +6077,8 @@
5719
6077
  * @return {promise} the answer results
5720
6078
  * @deprecated answers is deprecated and will be replaced with new initiatives
5721
6079
  */
5722
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
6080
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
6081
+ // eslint-disable-next-line no-console
5723
6082
  console.warn('[algoliasearch-helper] answers is no longer supported');
5724
6083
  var state = this.state;
5725
6084
  var derivedHelper = this.derivedHelpers[0];
@@ -5730,19 +6089,20 @@
5730
6089
  var data = merge_1(
5731
6090
  {
5732
6091
  attributesForPrediction: options.attributesForPrediction,
5733
- nbHits: options.nbHits
6092
+ nbHits: options.nbHits,
5734
6093
  },
5735
6094
  {
5736
6095
  params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
5737
6096
  'attributesToSnippet',
5738
6097
  'hitsPerPage',
5739
6098
  'restrictSearchableAttributes',
5740
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
5741
- ])
6099
+ 'snippetEllipsisText',
6100
+ ]),
5742
6101
  }
5743
6102
  );
5744
6103
 
5745
- var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
6104
+ var errorMessage =
6105
+ 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
5746
6106
  if (typeof this.client.initIndex !== 'function') {
5747
6107
  throw new Error(errorMessage);
5748
6108
  }
@@ -5787,7 +6147,12 @@
5787
6147
  * it in the generated query.
5788
6148
  * @return {promise.<FacetSearchResult>} the results of the search
5789
6149
  */
5790
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
6150
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
6151
+ facet,
6152
+ query,
6153
+ maxFacetHits,
6154
+ userState
6155
+ ) {
5791
6156
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
5792
6157
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
5793
6158
  if (
@@ -5802,15 +6167,21 @@
5802
6167
 
5803
6168
  var state = this.state.setQueryParameters(userState || {});
5804
6169
  var isDisjunctive = state.isDisjunctiveFacet(facet);
5805
- var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
6170
+ var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
6171
+ facet,
6172
+ query,
6173
+ maxFacetHits,
6174
+ state
6175
+ );
5806
6176
 
5807
6177
  this._currentNbQueries++;
6178
+ // eslint-disable-next-line consistent-this
5808
6179
  var self = this;
5809
6180
  var searchForFacetValuesPromise;
5810
6181
  // newer algoliasearch ^3.27.1 - ~4.0.0
5811
6182
  if (clientHasSFFV) {
5812
6183
  searchForFacetValuesPromise = this.client.searchForFacetValues([
5813
- {indexName: state.index, params: algoliaQuery}
6184
+ { indexName: state.index, params: algoliaQuery },
5814
6185
  ]);
5815
6186
  // algoliasearch < 3.27.1
5816
6187
  } else if (clientHasInitIndex) {
@@ -5827,8 +6198,8 @@
5827
6198
  type: 'facet',
5828
6199
  facet: facet,
5829
6200
  indexName: state.index,
5830
- params: algoliaQuery
5831
- }
6201
+ params: algoliaQuery,
6202
+ },
5832
6203
  ])
5833
6204
  .then(function processResponse(response) {
5834
6205
  return response.results[0];
@@ -5838,28 +6209,31 @@
5838
6209
  this.emit('searchForFacetValues', {
5839
6210
  state: state,
5840
6211
  facet: facet,
5841
- query: query
6212
+ query: query,
5842
6213
  });
5843
6214
 
5844
- return searchForFacetValuesPromise.then(function addIsRefined(content) {
5845
- self._currentNbQueries--;
5846
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
6215
+ return searchForFacetValuesPromise.then(
6216
+ function addIsRefined(content) {
6217
+ self._currentNbQueries--;
6218
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5847
6219
 
5848
- content = Array.isArray(content) ? content[0] : content;
6220
+ content = Array.isArray(content) ? content[0] : content;
5849
6221
 
5850
- content.facetHits.forEach(function(f) {
5851
- f.escapedValue = escapeFacetValue$3(f.value);
5852
- f.isRefined = isDisjunctive
5853
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
5854
- : state.isFacetRefined(facet, f.escapedValue);
5855
- });
6222
+ content.facetHits.forEach(function (f) {
6223
+ f.escapedValue = escapeFacetValue$3(f.value);
6224
+ f.isRefined = isDisjunctive
6225
+ ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
6226
+ : state.isFacetRefined(facet, f.escapedValue);
6227
+ });
5856
6228
 
5857
- return content;
5858
- }, function(e) {
5859
- self._currentNbQueries--;
5860
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5861
- throw e;
5862
- });
6229
+ return content;
6230
+ },
6231
+ function (e) {
6232
+ self._currentNbQueries--;
6233
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
6234
+ throw e;
6235
+ }
6236
+ );
5863
6237
  };
5864
6238
 
5865
6239
  /**
@@ -5867,14 +6241,14 @@
5867
6241
  *
5868
6242
  * This method resets the current page to 0.
5869
6243
  * @param {string} q the user query
5870
- * @return {AlgoliaSearchHelper}
6244
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5871
6245
  * @fires change
5872
6246
  * @chainable
5873
6247
  */
5874
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
6248
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
5875
6249
  this._change({
5876
6250
  state: this.state.resetPage().setQuery(q),
5877
- isPageReset: true
6251
+ isPageReset: true,
5878
6252
  });
5879
6253
 
5880
6254
  return this;
@@ -5888,7 +6262,7 @@
5888
6262
  *
5889
6263
  * This method resets the current page to 0.
5890
6264
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
5891
- * @return {AlgoliaSearchHelper}
6265
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5892
6266
  * @fires change
5893
6267
  * @chainable
5894
6268
  * @example
@@ -5903,10 +6277,10 @@
5903
6277
  * return type === 'exclude' && attribute === 'category';
5904
6278
  * }).search();
5905
6279
  */
5906
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
6280
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
5907
6281
  this._change({
5908
6282
  state: this.state.resetPage().clearRefinements(name),
5909
- isPageReset: true
6283
+ isPageReset: true,
5910
6284
  });
5911
6285
 
5912
6286
  return this;
@@ -5916,14 +6290,14 @@
5916
6290
  * Remove all the tag filters.
5917
6291
  *
5918
6292
  * This method resets the current page to 0.
5919
- * @return {AlgoliaSearchHelper}
6293
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5920
6294
  * @fires change
5921
6295
  * @chainable
5922
6296
  */
5923
- AlgoliaSearchHelper.prototype.clearTags = function() {
6297
+ AlgoliaSearchHelper.prototype.clearTags = function () {
5924
6298
  this._change({
5925
6299
  state: this.state.resetPage().clearTags(),
5926
- isPageReset: true
6300
+ isPageReset: true,
5927
6301
  });
5928
6302
 
5929
6303
  return this;
@@ -5936,23 +6310,27 @@
5936
6310
  * This method resets the current page to 0.
5937
6311
  * @param {string} facet the facet to refine
5938
6312
  * @param {string} value the associated value (will be converted to string)
5939
- * @return {AlgoliaSearchHelper}
6313
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5940
6314
  * @fires change
5941
6315
  * @chainable
5942
6316
  */
5943
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
6317
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
6318
+ facet,
6319
+ value
6320
+ ) {
5944
6321
  this._change({
5945
6322
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
5946
- isPageReset: true
6323
+ isPageReset: true,
5947
6324
  });
5948
6325
 
5949
6326
  return this;
5950
6327
  };
5951
6328
 
6329
+ // eslint-disable-next-line valid-jsdoc
5952
6330
  /**
5953
6331
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
5954
6332
  */
5955
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
6333
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
5956
6334
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
5957
6335
  };
5958
6336
 
@@ -5964,15 +6342,18 @@
5964
6342
  * This method resets the current page to 0.
5965
6343
  * @param {string} facet the facet name
5966
6344
  * @param {string} path the hierarchical facet path
5967
- * @return {AlgoliaSearchHelper}
6345
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5968
6346
  * @throws Error if the facet is not defined or if the facet is refined
5969
6347
  * @chainable
5970
6348
  * @fires change
5971
6349
  */
5972
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
6350
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
6351
+ facet,
6352
+ path
6353
+ ) {
5973
6354
  this._change({
5974
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
5975
- isPageReset: true
6355
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
6356
+ isPageReset: true,
5976
6357
  });
5977
6358
 
5978
6359
  return this;
@@ -5986,14 +6367,20 @@
5986
6367
  * @param {string} attribute the attribute on which the numeric filter applies
5987
6368
  * @param {string} operator the operator of the filter
5988
6369
  * @param {number} value the value of the filter
5989
- * @return {AlgoliaSearchHelper}
6370
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5990
6371
  * @fires change
5991
6372
  * @chainable
5992
6373
  */
5993
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
6374
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (
6375
+ attribute,
6376
+ operator,
6377
+ value
6378
+ ) {
5994
6379
  this._change({
5995
- state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
5996
- isPageReset: true
6380
+ state: this.state
6381
+ .resetPage()
6382
+ .addNumericRefinement(attribute, operator, value),
6383
+ isPageReset: true,
5997
6384
  });
5998
6385
 
5999
6386
  return this;
@@ -6006,27 +6393,27 @@
6006
6393
  * This method resets the current page to 0.
6007
6394
  * @param {string} facet the facet to refine
6008
6395
  * @param {string} value the associated value (will be converted to string)
6009
- * @return {AlgoliaSearchHelper}
6396
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6010
6397
  * @fires change
6011
6398
  * @chainable
6012
6399
  */
6013
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
6400
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
6014
6401
  this._change({
6015
6402
  state: this.state.resetPage().addFacetRefinement(facet, value),
6016
- isPageReset: true
6403
+ isPageReset: true,
6017
6404
  });
6018
6405
 
6019
6406
  return this;
6020
6407
  };
6021
6408
 
6409
+ // eslint-disable-next-line valid-jsdoc
6022
6410
  /**
6023
6411
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
6024
6412
  */
6025
- AlgoliaSearchHelper.prototype.addRefine = function() {
6413
+ AlgoliaSearchHelper.prototype.addRefine = function () {
6026
6414
  return this.addFacetRefinement.apply(this, arguments);
6027
6415
  };
6028
6416
 
6029
-
6030
6417
  /**
6031
6418
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
6032
6419
  * filter is already set, it doesn't change the filters.
@@ -6034,23 +6421,24 @@
6034
6421
  * This method resets the current page to 0.
6035
6422
  * @param {string} facet the facet to refine
6036
6423
  * @param {string} value the associated value (will be converted to string)
6037
- * @return {AlgoliaSearchHelper}
6424
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6038
6425
  * @fires change
6039
6426
  * @chainable
6040
6427
  */
6041
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
6428
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
6042
6429
  this._change({
6043
6430
  state: this.state.resetPage().addExcludeRefinement(facet, value),
6044
- isPageReset: true
6431
+ isPageReset: true,
6045
6432
  });
6046
6433
 
6047
6434
  return this;
6048
6435
  };
6049
6436
 
6437
+ // eslint-disable-next-line valid-jsdoc
6050
6438
  /**
6051
6439
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
6052
6440
  */
6053
- AlgoliaSearchHelper.prototype.addExclude = function() {
6441
+ AlgoliaSearchHelper.prototype.addExclude = function () {
6054
6442
  return this.addFacetExclusion.apply(this, arguments);
6055
6443
  };
6056
6444
 
@@ -6060,14 +6448,14 @@
6060
6448
  *
6061
6449
  * This method resets the current page to 0.
6062
6450
  * @param {string} tag the tag to add to the filter
6063
- * @return {AlgoliaSearchHelper}
6451
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6064
6452
  * @fires change
6065
6453
  * @chainable
6066
6454
  */
6067
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
6455
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
6068
6456
  this._change({
6069
6457
  state: this.state.resetPage().addTagRefinement(tag),
6070
- isPageReset: true
6458
+ isPageReset: true,
6071
6459
  });
6072
6460
 
6073
6461
  return this;
@@ -6087,14 +6475,20 @@
6087
6475
  * @param {string} attribute the attribute on which the numeric filter applies
6088
6476
  * @param {string} [operator] the operator of the filter
6089
6477
  * @param {number} [value] the value of the filter
6090
- * @return {AlgoliaSearchHelper}
6478
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6091
6479
  * @fires change
6092
6480
  * @chainable
6093
6481
  */
6094
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
6482
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
6483
+ attribute,
6484
+ operator,
6485
+ value
6486
+ ) {
6095
6487
  this._change({
6096
- state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
6097
- isPageReset: true
6488
+ state: this.state
6489
+ .resetPage()
6490
+ .removeNumericRefinement(attribute, operator, value),
6491
+ isPageReset: true,
6098
6492
  });
6099
6493
 
6100
6494
  return this;
@@ -6110,38 +6504,46 @@
6110
6504
  * This method resets the current page to 0.
6111
6505
  * @param {string} facet the facet to refine
6112
6506
  * @param {string} [value] the associated value
6113
- * @return {AlgoliaSearchHelper}
6507
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6114
6508
  * @fires change
6115
6509
  * @chainable
6116
6510
  */
6117
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
6511
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
6512
+ facet,
6513
+ value
6514
+ ) {
6118
6515
  this._change({
6119
- state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
6120
- isPageReset: true
6516
+ state: this.state
6517
+ .resetPage()
6518
+ .removeDisjunctiveFacetRefinement(facet, value),
6519
+ isPageReset: true,
6121
6520
  });
6122
6521
 
6123
6522
  return this;
6124
6523
  };
6125
6524
 
6525
+ // eslint-disable-next-line valid-jsdoc
6126
6526
  /**
6127
6527
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
6128
6528
  */
6129
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
6529
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
6130
6530
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
6131
6531
  };
6132
6532
 
6133
6533
  /**
6134
6534
  * Removes the refinement set on a hierarchical facet.
6135
6535
  * @param {string} facet the facet name
6136
- * @return {AlgoliaSearchHelper}
6536
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6137
6537
  * @throws Error if the facet is not defined or if the facet is not refined
6138
6538
  * @fires change
6139
6539
  * @chainable
6140
6540
  */
6141
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
6541
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
6542
+ facet
6543
+ ) {
6142
6544
  this._change({
6143
6545
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
6144
- isPageReset: true
6546
+ isPageReset: true,
6145
6547
  });
6146
6548
 
6147
6549
  return this;
@@ -6157,23 +6559,24 @@
6157
6559
  * This method resets the current page to 0.
6158
6560
  * @param {string} facet the facet to refine
6159
6561
  * @param {string} [value] the associated value
6160
- * @return {AlgoliaSearchHelper}
6562
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6161
6563
  * @fires change
6162
6564
  * @chainable
6163
6565
  */
6164
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
6566
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
6165
6567
  this._change({
6166
6568
  state: this.state.resetPage().removeFacetRefinement(facet, value),
6167
- isPageReset: true
6569
+ isPageReset: true,
6168
6570
  });
6169
6571
 
6170
6572
  return this;
6171
6573
  };
6172
6574
 
6575
+ // eslint-disable-next-line valid-jsdoc
6173
6576
  /**
6174
6577
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
6175
6578
  */
6176
- AlgoliaSearchHelper.prototype.removeRefine = function() {
6579
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
6177
6580
  return this.removeFacetRefinement.apply(this, arguments);
6178
6581
  };
6179
6582
 
@@ -6187,23 +6590,24 @@
6187
6590
  * This method resets the current page to 0.
6188
6591
  * @param {string} facet the facet to refine
6189
6592
  * @param {string} [value] the associated value
6190
- * @return {AlgoliaSearchHelper}
6593
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6191
6594
  * @fires change
6192
6595
  * @chainable
6193
6596
  */
6194
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
6597
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
6195
6598
  this._change({
6196
6599
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
6197
- isPageReset: true
6600
+ isPageReset: true,
6198
6601
  });
6199
6602
 
6200
6603
  return this;
6201
6604
  };
6202
6605
 
6606
+ // eslint-disable-next-line valid-jsdoc
6203
6607
  /**
6204
6608
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
6205
6609
  */
6206
- AlgoliaSearchHelper.prototype.removeExclude = function() {
6610
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
6207
6611
  return this.removeFacetExclusion.apply(this, arguments);
6208
6612
  };
6209
6613
 
@@ -6213,14 +6617,14 @@
6213
6617
  *
6214
6618
  * This method resets the current page to 0.
6215
6619
  * @param {string} tag tag to remove from the filter
6216
- * @return {AlgoliaSearchHelper}
6620
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6217
6621
  * @fires change
6218
6622
  * @chainable
6219
6623
  */
6220
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
6624
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
6221
6625
  this._change({
6222
6626
  state: this.state.resetPage().removeTagRefinement(tag),
6223
- isPageReset: true
6627
+ isPageReset: true,
6224
6628
  });
6225
6629
 
6226
6630
  return this;
@@ -6233,23 +6637,24 @@
6233
6637
  * This method resets the current page to 0.
6234
6638
  * @param {string} facet the facet to refine
6235
6639
  * @param {string} value the associated value
6236
- * @return {AlgoliaSearchHelper}
6640
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6237
6641
  * @fires change
6238
6642
  * @chainable
6239
6643
  */
6240
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
6644
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
6241
6645
  this._change({
6242
6646
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
6243
- isPageReset: true
6647
+ isPageReset: true,
6244
6648
  });
6245
6649
 
6246
6650
  return this;
6247
6651
  };
6248
6652
 
6653
+ // eslint-disable-next-line valid-jsdoc
6249
6654
  /**
6250
6655
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
6251
6656
  */
6252
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
6657
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
6253
6658
  return this.toggleFacetExclusion.apply(this, arguments);
6254
6659
  };
6255
6660
 
@@ -6262,13 +6667,13 @@
6262
6667
  * This method resets the current page to 0.
6263
6668
  * @param {string} facet the facet to refine
6264
6669
  * @param {string} value the associated value
6265
- * @return {AlgoliaSearchHelper}
6670
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6266
6671
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
6267
6672
  * @fires change
6268
6673
  * @chainable
6269
6674
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6270
6675
  */
6271
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
6676
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
6272
6677
  return this.toggleFacetRefinement(facet, value);
6273
6678
  };
6274
6679
 
@@ -6281,24 +6686,25 @@
6281
6686
  * This method resets the current page to 0.
6282
6687
  * @param {string} facet the facet to refine
6283
6688
  * @param {string} value the associated value
6284
- * @return {AlgoliaSearchHelper}
6689
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6285
6690
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
6286
6691
  * @fires change
6287
6692
  * @chainable
6288
6693
  */
6289
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
6694
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
6290
6695
  this._change({
6291
6696
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
6292
- isPageReset: true
6697
+ isPageReset: true,
6293
6698
  });
6294
6699
 
6295
6700
  return this;
6296
6701
  };
6297
6702
 
6703
+ // eslint-disable-next-line valid-jsdoc
6298
6704
  /**
6299
6705
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6300
6706
  */
6301
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
6707
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
6302
6708
  return this.toggleFacetRefinement.apply(this, arguments);
6303
6709
  };
6304
6710
 
@@ -6308,14 +6714,14 @@
6308
6714
  *
6309
6715
  * This method resets the current page to 0.
6310
6716
  * @param {string} tag tag to remove or add
6311
- * @return {AlgoliaSearchHelper}
6717
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6312
6718
  * @fires change
6313
6719
  * @chainable
6314
6720
  */
6315
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
6721
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
6316
6722
  this._change({
6317
6723
  state: this.state.resetPage().toggleTagRefinement(tag),
6318
- isPageReset: true
6724
+ isPageReset: true,
6319
6725
  });
6320
6726
 
6321
6727
  return this;
@@ -6323,14 +6729,14 @@
6323
6729
 
6324
6730
  /**
6325
6731
  * Increments the page number by one.
6326
- * @return {AlgoliaSearchHelper}
6732
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6327
6733
  * @fires change
6328
6734
  * @chainable
6329
6735
  * @example
6330
6736
  * helper.setPage(0).nextPage().getPage();
6331
6737
  * // returns 1
6332
6738
  */
6333
- AlgoliaSearchHelper.prototype.nextPage = function() {
6739
+ AlgoliaSearchHelper.prototype.nextPage = function () {
6334
6740
  var page = this.state.page || 0;
6335
6741
  return this.setPage(page + 1);
6336
6742
  };
@@ -6338,26 +6744,30 @@
6338
6744
  /**
6339
6745
  * Decrements the page number by one.
6340
6746
  * @fires change
6341
- * @return {AlgoliaSearchHelper}
6747
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6342
6748
  * @chainable
6343
6749
  * @example
6344
6750
  * helper.setPage(1).previousPage().getPage();
6345
6751
  * // returns 0
6346
6752
  */
6347
- AlgoliaSearchHelper.prototype.previousPage = function() {
6753
+ AlgoliaSearchHelper.prototype.previousPage = function () {
6348
6754
  var page = this.state.page || 0;
6349
6755
  return this.setPage(page - 1);
6350
6756
  };
6351
6757
 
6352
6758
  /**
6353
6759
  * @private
6760
+ * @param {number} page The page number
6761
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6762
+ * @chainable
6763
+ * @fires change
6354
6764
  */
6355
6765
  function setCurrentPage(page) {
6356
6766
  if (page < 0) throw new Error('Page requested below 0.');
6357
6767
 
6358
6768
  this._change({
6359
6769
  state: this.state.setPage(page),
6360
- isPageReset: false
6770
+ isPageReset: false,
6361
6771
  });
6362
6772
 
6363
6773
  return this;
@@ -6367,7 +6777,7 @@
6367
6777
  * Change the current page
6368
6778
  * @deprecated
6369
6779
  * @param {number} page The page number
6370
- * @return {AlgoliaSearchHelper}
6780
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6371
6781
  * @fires change
6372
6782
  * @chainable
6373
6783
  */
@@ -6377,7 +6787,7 @@
6377
6787
  * Updates the current page.
6378
6788
  * @function
6379
6789
  * @param {number} page The page number
6380
- * @return {AlgoliaSearchHelper}
6790
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6381
6791
  * @fires change
6382
6792
  * @chainable
6383
6793
  */
@@ -6388,14 +6798,14 @@
6388
6798
  *
6389
6799
  * This method resets the current page to 0.
6390
6800
  * @param {string} name the index name
6391
- * @return {AlgoliaSearchHelper}
6801
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6392
6802
  * @fires change
6393
6803
  * @chainable
6394
6804
  */
6395
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
6805
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
6396
6806
  this._change({
6397
6807
  state: this.state.resetPage().setIndex(name),
6398
- isPageReset: true
6808
+ isPageReset: true,
6399
6809
  });
6400
6810
 
6401
6811
  return this;
@@ -6412,16 +6822,16 @@
6412
6822
  * This method resets the current page to 0.
6413
6823
  * @param {string} parameter name of the parameter to update
6414
6824
  * @param {any} value new value of the parameter
6415
- * @return {AlgoliaSearchHelper}
6825
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6416
6826
  * @fires change
6417
6827
  * @chainable
6418
6828
  * @example
6419
6829
  * helper.setQueryParameter('hitsPerPage', 20).search();
6420
6830
  */
6421
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
6831
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
6422
6832
  this._change({
6423
6833
  state: this.state.resetPage().setQueryParameter(parameter, value),
6424
- isPageReset: true
6834
+ isPageReset: true,
6425
6835
  });
6426
6836
 
6427
6837
  return this;
@@ -6430,14 +6840,14 @@
6430
6840
  /**
6431
6841
  * Set the whole state (warning: will erase previous state)
6432
6842
  * @param {SearchParameters} newState the whole new state
6433
- * @return {AlgoliaSearchHelper}
6843
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6434
6844
  * @fires change
6435
6845
  * @chainable
6436
6846
  */
6437
- AlgoliaSearchHelper.prototype.setState = function(newState) {
6847
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
6438
6848
  this._change({
6439
6849
  state: SearchParameters_1.make(newState),
6440
- isPageReset: false
6850
+ isPageReset: false,
6441
6851
  });
6442
6852
 
6443
6853
  return this;
@@ -6448,7 +6858,7 @@
6448
6858
  * Do not use this method unless you know what you are doing. (see the example
6449
6859
  * for a legit use case)
6450
6860
  * @param {SearchParameters} newState the whole new state
6451
- * @return {AlgoliaSearchHelper}
6861
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6452
6862
  * @example
6453
6863
  * helper.on('change', function(state){
6454
6864
  * // In this function you might want to find a way to store the state in the url/history
@@ -6460,10 +6870,11 @@
6460
6870
  * }
6461
6871
  * @chainable
6462
6872
  */
6463
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
6464
- this.state = new SearchParameters_1(newState);
6465
- return this;
6466
- };
6873
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
6874
+ function (newState) {
6875
+ this.state = new SearchParameters_1(newState);
6876
+ return this;
6877
+ };
6467
6878
 
6468
6879
  /**
6469
6880
  * Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
@@ -6488,7 +6899,7 @@
6488
6899
  * helper.hasRefinements('categories'); // true
6489
6900
  *
6490
6901
  */
6491
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
6902
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
6492
6903
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
6493
6904
  return true;
6494
6905
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -6513,7 +6924,7 @@
6513
6924
  *
6514
6925
  * @param {string} facet name of the attribute for used for faceting
6515
6926
  * @param {string} [value] optional value. If passed will test that this value
6516
- * is filtering the given facet.
6927
+ * is filtering the given facet.
6517
6928
  * @return {boolean} true if refined
6518
6929
  * @example
6519
6930
  * helper.isExcludeRefined('color'); // false
@@ -6526,42 +6937,43 @@
6526
6937
  * helper.isExcludeRefined('color', 'blue') // false
6527
6938
  * helper.isExcludeRefined('color', 'red') // true
6528
6939
  */
6529
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
6940
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
6530
6941
  return this.state.isExcludeRefined(facet, value);
6531
6942
  };
6532
6943
 
6944
+ // eslint-disable-next-line valid-jsdoc
6533
6945
  /**
6534
6946
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
6535
6947
  */
6536
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
6948
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
6537
6949
  return this.state.isDisjunctiveFacetRefined(facet, value);
6538
6950
  };
6539
6951
 
6540
6952
  /**
6541
6953
  * Check if the string is a currently filtering tag.
6542
6954
  * @param {string} tag tag to check
6543
- * @return {boolean}
6955
+ * @return {boolean} true if the tag is currently refined
6544
6956
  */
6545
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
6957
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
6546
6958
  return this.state.isTagRefined(tag);
6547
6959
  };
6548
6960
 
6961
+ // eslint-disable-next-line valid-jsdoc
6549
6962
  /**
6550
6963
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
6551
6964
  */
6552
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
6965
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
6553
6966
  return this.hasTagRefinements.apply(this, arguments);
6554
6967
  };
6555
6968
 
6556
-
6557
6969
  /**
6558
6970
  * Get the name of the currently used index.
6559
- * @return {string}
6971
+ * @return {string} name of the index
6560
6972
  * @example
6561
6973
  * helper.setIndex('highestPrice_products').getIndex();
6562
6974
  * // returns 'highestPrice_products'
6563
6975
  */
6564
- AlgoliaSearchHelper.prototype.getIndex = function() {
6976
+ AlgoliaSearchHelper.prototype.getIndex = function () {
6565
6977
  return this.state.index;
6566
6978
  };
6567
6979
 
@@ -6587,7 +6999,7 @@
6587
6999
  *
6588
7000
  * @return {string[]} The list of tags currently set.
6589
7001
  */
6590
- AlgoliaSearchHelper.prototype.getTags = function() {
7002
+ AlgoliaSearchHelper.prototype.getTags = function () {
6591
7003
  return this.state.tagRefinements;
6592
7004
  };
6593
7005
 
@@ -6635,47 +7047,48 @@
6635
7047
  * // }
6636
7048
  * // ]
6637
7049
  */
6638
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
7050
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
6639
7051
  var refinements = [];
6640
7052
 
6641
7053
  if (this.state.isConjunctiveFacet(facetName)) {
6642
7054
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
6643
7055
 
6644
- conjRefinements.forEach(function(r) {
7056
+ conjRefinements.forEach(function (r) {
6645
7057
  refinements.push({
6646
7058
  value: r,
6647
- type: 'conjunctive'
7059
+ type: 'conjunctive',
6648
7060
  });
6649
7061
  });
6650
7062
 
6651
7063
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
6652
7064
 
6653
- excludeRefinements.forEach(function(r) {
7065
+ excludeRefinements.forEach(function (r) {
6654
7066
  refinements.push({
6655
7067
  value: r,
6656
- type: 'exclude'
7068
+ type: 'exclude',
6657
7069
  });
6658
7070
  });
6659
7071
  } else if (this.state.isDisjunctiveFacet(facetName)) {
6660
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
7072
+ var disjunctiveRefinements =
7073
+ this.state.getDisjunctiveRefinements(facetName);
6661
7074
 
6662
- disjRefinements.forEach(function(r) {
7075
+ disjunctiveRefinements.forEach(function (r) {
6663
7076
  refinements.push({
6664
7077
  value: r,
6665
- type: 'disjunctive'
7078
+ type: 'disjunctive',
6666
7079
  });
6667
7080
  });
6668
7081
  }
6669
7082
 
6670
7083
  var numericRefinements = this.state.getNumericRefinements(facetName);
6671
7084
 
6672
- Object.keys(numericRefinements).forEach(function(operator) {
7085
+ Object.keys(numericRefinements).forEach(function (operator) {
6673
7086
  var value = numericRefinements[operator];
6674
7087
 
6675
7088
  refinements.push({
6676
7089
  value: value,
6677
7090
  operator: operator,
6678
- type: 'numeric'
7091
+ type: 'numeric',
6679
7092
  });
6680
7093
  });
6681
7094
 
@@ -6688,7 +7101,10 @@
6688
7101
  * @param {string} operator operator applied on the refined values
6689
7102
  * @return {Array.<number|number[]>} refined values
6690
7103
  */
6691
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
7104
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (
7105
+ attribute,
7106
+ operator
7107
+ ) {
6692
7108
  return this.state.getNumericRefinement(attribute, operator);
6693
7109
  };
6694
7110
 
@@ -6697,7 +7113,9 @@
6697
7113
  * @param {string} facetName Hierarchical facet name
6698
7114
  * @return {array.<string>} the path as an array of string
6699
7115
  */
6700
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
7116
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
7117
+ facetName
7118
+ ) {
6701
7119
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
6702
7120
  };
6703
7121
 
@@ -6706,12 +7124,14 @@
6706
7124
  /**
6707
7125
  * Perform the underlying queries
6708
7126
  * @private
6709
- * @return {undefined}
7127
+ * @param {object} options options for the query
7128
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
7129
+ * @return {undefined} does not return anything
6710
7130
  * @fires search
6711
7131
  * @fires result
6712
7132
  * @fires error
6713
7133
  */
6714
- AlgoliaSearchHelper.prototype._search = function(options) {
7134
+ AlgoliaSearchHelper.prototype._search = function (options) {
6715
7135
  var state = this.state;
6716
7136
  var states = [];
6717
7137
  var mainQueries = [];
@@ -6722,16 +7142,16 @@
6722
7142
  states.push({
6723
7143
  state: state,
6724
7144
  queriesCount: mainQueries.length,
6725
- helper: this
7145
+ helper: this,
6726
7146
  });
6727
7147
 
6728
7148
  this.emit('search', {
6729
7149
  state: state,
6730
- results: this.lastResults
7150
+ results: this.lastResults,
6731
7151
  });
6732
7152
  }
6733
7153
 
6734
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
7154
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
6735
7155
  var derivedState = derivedHelper.getModifiedState(state);
6736
7156
  var derivedStateQueries = derivedState.index
6737
7157
  ? requestBuilder_1._getQueries(derivedState.index, derivedState)
@@ -6740,12 +7160,12 @@
6740
7160
  states.push({
6741
7161
  state: derivedState,
6742
7162
  queriesCount: derivedStateQueries.length,
6743
- helper: derivedHelper
7163
+ helper: derivedHelper,
6744
7164
  });
6745
7165
 
6746
7166
  derivedHelper.emit('search', {
6747
7167
  state: derivedState,
6748
- results: derivedHelper.lastResults
7168
+ results: derivedHelper.lastResults,
6749
7169
  });
6750
7170
 
6751
7171
  return derivedStateQueries;
@@ -6757,21 +7177,24 @@
6757
7177
  this._currentNbQueries++;
6758
7178
 
6759
7179
  if (!queries.length) {
6760
- return Promise.resolve({results: []}).then(
7180
+ return Promise.resolve({ results: [] }).then(
6761
7181
  this._dispatchAlgoliaResponse.bind(this, states, queryId)
6762
7182
  );
6763
7183
  }
6764
7184
 
6765
7185
  try {
6766
- this.client.search(queries)
7186
+ this.client
7187
+ .search(queries)
6767
7188
  .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
6768
7189
  .catch(this._dispatchAlgoliaError.bind(this, queryId));
6769
7190
  } catch (error) {
6770
7191
  // If we reach this part, we're in an internal error state
6771
7192
  this.emit('error', {
6772
- error: error
7193
+ error: error,
6773
7194
  });
6774
7195
  }
7196
+
7197
+ return undefined;
6775
7198
  };
6776
7199
 
6777
7200
  /**
@@ -6779,28 +7202,31 @@
6779
7202
  * usable object that merge the results of all the batch requests. It will dispatch
6780
7203
  * over the different helper + derived helpers (when there are some).
6781
7204
  * @private
6782
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
6783
- * state state used for to generate the request
7205
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
6784
7206
  * @param {number} queryId id of the current request
6785
7207
  * @param {object} content content of the response
6786
7208
  * @return {undefined}
6787
7209
  */
6788
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
6789
- // FIXME remove the number of outdated queries discarded instead of just one
7210
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
7211
+ states,
7212
+ queryId,
7213
+ content
7214
+ ) {
7215
+ // @TODO remove the number of outdated queries discarded instead of just one
6790
7216
 
6791
7217
  if (queryId < this._lastQueryIdReceived) {
6792
7218
  // Outdated answer
6793
7219
  return;
6794
7220
  }
6795
7221
 
6796
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
7222
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6797
7223
  this._lastQueryIdReceived = queryId;
6798
7224
 
6799
7225
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6800
7226
 
6801
7227
  var results = content.results.slice();
6802
7228
 
6803
- states.forEach(function(s) {
7229
+ states.forEach(function (s) {
6804
7230
  var state = s.state;
6805
7231
  var queriesCount = s.queriesCount;
6806
7232
  var helper = s.helper;
@@ -6809,21 +7235,24 @@
6809
7235
  if (!state.index) {
6810
7236
  helper.emit('result', {
6811
7237
  results: null,
6812
- state: state
7238
+ state: state,
6813
7239
  });
6814
7240
  return;
6815
7241
  }
6816
7242
 
6817
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
7243
+ helper.lastResults = new SearchResults_1(state, specificResults);
6818
7244
 
6819
7245
  helper.emit('result', {
6820
- results: formattedResponse,
6821
- state: state
7246
+ results: helper.lastResults,
7247
+ state: state,
6822
7248
  });
6823
7249
  });
6824
7250
  };
6825
7251
 
6826
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
7252
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
7253
+ queryId,
7254
+ error
7255
+ ) {
6827
7256
  if (queryId < this._lastQueryIdReceived) {
6828
7257
  // Outdated answer
6829
7258
  return;
@@ -6833,31 +7262,40 @@
6833
7262
  this._lastQueryIdReceived = queryId;
6834
7263
 
6835
7264
  this.emit('error', {
6836
- error: error
7265
+ error: error,
6837
7266
  });
6838
7267
 
6839
7268
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6840
7269
  };
6841
7270
 
6842
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
6843
- return query ||
7271
+ AlgoliaSearchHelper.prototype.containsRefinement = function (
7272
+ query,
7273
+ facetFilters,
7274
+ numericFilters,
7275
+ tagFilters
7276
+ ) {
7277
+ return (
7278
+ query ||
6844
7279
  facetFilters.length !== 0 ||
6845
7280
  numericFilters.length !== 0 ||
6846
- tagFilters.length !== 0;
7281
+ tagFilters.length !== 0
7282
+ );
6847
7283
  };
6848
7284
 
6849
7285
  /**
6850
7286
  * Test if there are some disjunctive refinements on the facet
6851
7287
  * @private
6852
7288
  * @param {string} facet the attribute to test
6853
- * @return {boolean}
7289
+ * @return {boolean} true if there are refinements on this attribute
6854
7290
  */
6855
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
6856
- return this.state.disjunctiveRefinements[facet] &&
6857
- this.state.disjunctiveRefinements[facet].length > 0;
7291
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
7292
+ return (
7293
+ this.state.disjunctiveRefinements[facet] &&
7294
+ this.state.disjunctiveRefinements[facet].length > 0
7295
+ );
6858
7296
  };
6859
7297
 
6860
- AlgoliaSearchHelper.prototype._change = function(event) {
7298
+ AlgoliaSearchHelper.prototype._change = function (event) {
6861
7299
  var state = event.state;
6862
7300
  var isPageReset = event.isPageReset;
6863
7301
 
@@ -6867,17 +7305,17 @@
6867
7305
  this.emit('change', {
6868
7306
  state: this.state,
6869
7307
  results: this.lastResults,
6870
- isPageReset: isPageReset
7308
+ isPageReset: isPageReset,
6871
7309
  });
6872
7310
  }
6873
7311
  };
6874
7312
 
6875
7313
  /**
6876
7314
  * Clears the cache of the underlying Algolia client.
6877
- * @return {AlgoliaSearchHelper}
7315
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6878
7316
  */
6879
- AlgoliaSearchHelper.prototype.clearCache = function() {
6880
- this.client.clearCache && this.client.clearCache();
7317
+ AlgoliaSearchHelper.prototype.clearCache = function () {
7318
+ if (this.client.clearCache) this.client.clearCache();
6881
7319
  return this;
6882
7320
  };
6883
7321
 
@@ -6885,9 +7323,9 @@
6885
7323
  * Updates the internal client instance. If the reference of the clients
6886
7324
  * are equal then no update is actually done.
6887
7325
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
6888
- * @return {AlgoliaSearchHelper}
7326
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6889
7327
  */
6890
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
7328
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
6891
7329
  if (this.client === newClient) return this;
6892
7330
 
6893
7331
  if (typeof newClient.addAlgoliaAgent === 'function') {
@@ -6900,9 +7338,9 @@
6900
7338
 
6901
7339
  /**
6902
7340
  * Gets the instance of the currently used client.
6903
- * @return {AlgoliaSearch}
7341
+ * @return {AlgoliaSearch} the currently used client
6904
7342
  */
6905
- AlgoliaSearchHelper.prototype.getClient = function() {
7343
+ AlgoliaSearchHelper.prototype.getClient = function () {
6906
7344
  return this.client;
6907
7345
  };
6908
7346
 
@@ -6923,9 +7361,9 @@
6923
7361
  * and the SearchParameters that is returned by the call of the
6924
7362
  * parameter function.
6925
7363
  * @param {function} fn SearchParameters -> SearchParameters
6926
- * @return {DerivedHelper}
7364
+ * @return {DerivedHelper} a new DerivedHelper
6927
7365
  */
6928
- AlgoliaSearchHelper.prototype.derive = function(fn) {
7366
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
6929
7367
  var derivedHelper = new DerivedHelper_1(this, fn);
6930
7368
  this.derivedHelpers.push(derivedHelper);
6931
7369
  return derivedHelper;
@@ -6935,10 +7373,11 @@
6935
7373
  * This method detaches a derived Helper from the main one. Prefer using the one from the
6936
7374
  * derived helper itself, to remove the event listeners too.
6937
7375
  * @private
6938
- * @return {undefined}
7376
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
7377
+ * @return {undefined} nothing is returned
6939
7378
  * @throws Error
6940
7379
  */
6941
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
7380
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
6942
7381
  var pos = this.derivedHelpers.indexOf(derivedHelper);
6943
7382
  if (pos === -1) throw new Error('Derived helper already detached');
6944
7383
  this.derivedHelpers.splice(pos, 1);
@@ -6948,7 +7387,7 @@
6948
7387
  * This method returns true if there is currently at least one on-going search.
6949
7388
  * @return {boolean} true if there is a search pending
6950
7389
  */
6951
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
7390
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
6952
7391
  return this._currentNbQueries > 0;
6953
7392
  };
6954
7393
 
@@ -6999,7 +7438,7 @@
6999
7438
  * @param {AlgoliaSearch} client an AlgoliaSearch client
7000
7439
  * @param {string} index the name of the index to query
7001
7440
  * @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.
7002
- * @return {AlgoliaSearchHelper}
7441
+ * @return {AlgoliaSearchHelper} The helper instance
7003
7442
  */
7004
7443
  function algoliasearchHelper(client, index, opts) {
7005
7444
  return new algoliasearch_helper(client, index, opts);
@@ -7314,26 +7753,30 @@
7314
7753
  */
7315
7754
 
7316
7755
  var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
7756
+
7317
7757
  var ReactPropTypesSecret_1 = ReactPropTypesSecret;
7318
7758
 
7319
7759
  function emptyFunction() {}
7320
7760
  function emptyFunctionWithReset() {}
7321
7761
  emptyFunctionWithReset.resetWarningCache = emptyFunction;
7322
- var factoryWithThrowingShims = function () {
7762
+
7763
+ var factoryWithThrowingShims = function() {
7323
7764
  function shim(props, propName, componentName, location, propFullName, secret) {
7324
7765
  if (secret === ReactPropTypesSecret_1) {
7325
7766
  // It is still safe when called from React.
7326
7767
  return;
7327
7768
  }
7328
- var err = new Error('Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
7769
+ var err = new Error(
7770
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
7771
+ 'Use PropTypes.checkPropTypes() to call them. ' +
7772
+ 'Read more at http://fb.me/use-check-prop-types'
7773
+ );
7329
7774
  err.name = 'Invariant Violation';
7330
7775
  throw err;
7331
- }
7332
- shim.isRequired = shim;
7776
+ } shim.isRequired = shim;
7333
7777
  function getShim() {
7334
7778
  return shim;
7335
- }
7336
- // Important!
7779
+ } // Important!
7337
7780
  // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
7338
7781
  var ReactPropTypes = {
7339
7782
  array: shim,
@@ -7344,6 +7787,7 @@
7344
7787
  object: shim,
7345
7788
  string: shim,
7346
7789
  symbol: shim,
7790
+
7347
7791
  any: shim,
7348
7792
  arrayOf: getShim,
7349
7793
  element: shim,
@@ -7355,10 +7799,13 @@
7355
7799
  oneOfType: getShim,
7356
7800
  shape: getShim,
7357
7801
  exact: getShim,
7802
+
7358
7803
  checkPropTypes: emptyFunctionWithReset,
7359
7804
  resetWarningCache: emptyFunction
7360
7805
  };
7806
+
7361
7807
  ReactPropTypes.PropTypes = ReactPropTypes;
7808
+
7362
7809
  return ReactPropTypes;
7363
7810
  };
7364
7811
 
@@ -11776,26 +12223,30 @@
11776
12223
  */
11777
12224
 
11778
12225
  var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
12226
+
11779
12227
  var ReactPropTypesSecret_1$1 = ReactPropTypesSecret$1;
11780
12228
 
11781
12229
  function emptyFunction$1() {}
11782
12230
  function emptyFunctionWithReset$1() {}
11783
12231
  emptyFunctionWithReset$1.resetWarningCache = emptyFunction$1;
11784
- var factoryWithThrowingShims$1 = function () {
12232
+
12233
+ var factoryWithThrowingShims$1 = function() {
11785
12234
  function shim(props, propName, componentName, location, propFullName, secret) {
11786
12235
  if (secret === ReactPropTypesSecret_1$1) {
11787
12236
  // It is still safe when called from React.
11788
12237
  return;
11789
12238
  }
11790
- var err = new Error('Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
12239
+ var err = new Error(
12240
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
12241
+ 'Use PropTypes.checkPropTypes() to call them. ' +
12242
+ 'Read more at http://fb.me/use-check-prop-types'
12243
+ );
11791
12244
  err.name = 'Invariant Violation';
11792
12245
  throw err;
11793
- }
11794
- shim.isRequired = shim;
12246
+ } shim.isRequired = shim;
11795
12247
  function getShim() {
11796
12248
  return shim;
11797
- }
11798
- // Important!
12249
+ } // Important!
11799
12250
  // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
11800
12251
  var ReactPropTypes = {
11801
12252
  array: shim,
@@ -11806,6 +12257,7 @@
11806
12257
  object: shim,
11807
12258
  string: shim,
11808
12259
  symbol: shim,
12260
+
11809
12261
  any: shim,
11810
12262
  arrayOf: getShim,
11811
12263
  element: shim,
@@ -11817,10 +12269,13 @@
11817
12269
  oneOfType: getShim,
11818
12270
  shape: getShim,
11819
12271
  exact: getShim,
12272
+
11820
12273
  checkPropTypes: emptyFunctionWithReset$1,
11821
12274
  resetWarningCache: emptyFunction$1
11822
12275
  };
12276
+
11823
12277
  ReactPropTypes.PropTypes = ReactPropTypes;
12278
+
11824
12279
  return ReactPropTypes;
11825
12280
  };
11826
12281