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.
@@ -1300,12 +1300,14 @@
1300
1300
  return target;
1301
1301
  }
1302
1302
 
1303
+ // eslint-disable-next-line no-restricted-syntax
1303
1304
  for (var key in source) {
1304
1305
  if (
1305
1306
  !Object.prototype.hasOwnProperty.call(source, key) ||
1306
1307
  key === '__proto__' ||
1307
1308
  key === 'constructor'
1308
1309
  ) {
1310
+ // eslint-disable-next-line no-continue
1309
1311
  continue;
1310
1312
  }
1311
1313
 
@@ -1313,6 +1315,7 @@
1313
1315
  var targetVal = target[key];
1314
1316
 
1315
1317
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
1318
+ // eslint-disable-next-line no-continue
1316
1319
  continue;
1317
1320
  }
1318
1321
 
@@ -1339,11 +1342,10 @@
1339
1342
  * - treats sparse arrays as sparse
1340
1343
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
1341
1344
  *
1342
- * @param {Object} object The destination object.
1345
+ * @param {Object} target The destination object.
1343
1346
  * @param {...Object} [sources] The source objects.
1344
1347
  * @returns {Object} Returns `object`.
1345
1348
  */
1346
-
1347
1349
  function merge(target) {
1348
1350
  if (!isObjectOrArrayOrFunction(target)) {
1349
1351
  target = {};
@@ -1366,8 +1368,8 @@
1366
1368
  var defaultsPure = function defaultsPure() {
1367
1369
  var sources = Array.prototype.slice.call(arguments);
1368
1370
 
1369
- return sources.reduceRight(function(acc, source) {
1370
- Object.keys(Object(source)).forEach(function(key) {
1371
+ return sources.reduceRight(function (acc, source) {
1372
+ Object.keys(Object(source)).forEach(function (key) {
1371
1373
  if (source[key] === undefined) {
1372
1374
  return;
1373
1375
  }
@@ -1382,7 +1384,7 @@
1382
1384
  };
1383
1385
 
1384
1386
  function intersection(arr1, arr2) {
1385
- return arr1.filter(function(value, index) {
1387
+ return arr1.filter(function (value, index) {
1386
1388
  return (
1387
1389
  arr2.indexOf(value) > -1 &&
1388
1390
  arr1.indexOf(value) === index /* skips duplicates */
@@ -1403,6 +1405,8 @@
1403
1405
  return array[i];
1404
1406
  }
1405
1407
  }
1408
+
1409
+ return undefined;
1406
1410
  };
1407
1411
 
1408
1412
  function valToNumber(v) {
@@ -1414,7 +1418,9 @@
1414
1418
  return v.map(valToNumber);
1415
1419
  }
1416
1420
 
1417
- throw new Error('The value should be a number, a parsable string or an array of those.');
1421
+ throw new Error(
1422
+ 'The value should be a number, a parsable string or an array of those.'
1423
+ );
1418
1424
  }
1419
1425
 
1420
1426
  var valToNumber_1 = valToNumber;
@@ -1428,6 +1434,7 @@
1428
1434
  var i;
1429
1435
  for (i = 0; i < sourceKeys.length; i++) {
1430
1436
  key = sourceKeys[i];
1437
+ // eslint-disable-next-line no-continue
1431
1438
  if (excluded.indexOf(key) >= 0) continue;
1432
1439
  target[key] = source[key];
1433
1440
  }
@@ -1480,9 +1487,9 @@
1480
1487
 
1481
1488
  var valueAsString = '' + value;
1482
1489
 
1483
- var facetRefinement = !refinementList[attribute] ?
1484
- [valueAsString] :
1485
- refinementList[attribute].concat(valueAsString);
1490
+ var facetRefinement = !refinementList[attribute]
1491
+ ? [valueAsString]
1492
+ : refinementList[attribute].concat(valueAsString);
1486
1493
 
1487
1494
  var mod = {};
1488
1495
 
@@ -1499,18 +1506,22 @@
1499
1506
  * @param {string} [value] the value of the refinement
1500
1507
  * @return {RefinementList} a new and updated refinement lst
1501
1508
  */
1502
- removeRefinement: function removeRefinement(refinementList, attribute, value) {
1509
+ removeRefinement: function removeRefinement(
1510
+ refinementList,
1511
+ attribute,
1512
+ value
1513
+ ) {
1503
1514
  if (value === undefined) {
1504
1515
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
1505
1516
  // the form with a string will remove the attribute completely
1506
- return lib.clearRefinement(refinementList, function(v, f) {
1517
+ return lib.clearRefinement(refinementList, function (v, f) {
1507
1518
  return attribute === f;
1508
1519
  });
1509
1520
  }
1510
1521
 
1511
1522
  var valueAsString = '' + value;
1512
1523
 
1513
- return lib.clearRefinement(refinementList, function(v, f) {
1524
+ return lib.clearRefinement(refinementList, function (v, f) {
1514
1525
  return attribute === f && valueAsString === v;
1515
1526
  });
1516
1527
  },
@@ -1521,8 +1532,13 @@
1521
1532
  * @param {string} value the value of the refinement
1522
1533
  * @return {RefinementList} a new and updated list
1523
1534
  */
1524
- toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
1525
- if (value === undefined) throw new Error('toggleRefinement should be used with a value');
1535
+ toggleRefinement: function toggleRefinement(
1536
+ refinementList,
1537
+ attribute,
1538
+ value
1539
+ ) {
1540
+ if (value === undefined)
1541
+ throw new Error('toggleRefinement should be used with a value');
1526
1542
 
1527
1543
  if (lib.isRefined(refinementList, attribute, value)) {
1528
1544
  return lib.removeRefinement(refinementList, attribute, value);
@@ -1541,8 +1557,14 @@
1541
1557
  * @param {string} [refinementType] optional parameter to give more context to the attribute function
1542
1558
  * @return {RefinementList} a new and updated refinement list
1543
1559
  */
1544
- clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
1560
+ clearRefinement: function clearRefinement(
1561
+ refinementList,
1562
+ attribute,
1563
+ refinementType
1564
+ ) {
1545
1565
  if (attribute === undefined) {
1566
+ // return the same object if the list is already empty
1567
+ // this is mainly for tests, as it doesn't have much impact on performance
1546
1568
  if (!objectHasKeys_1(refinementList)) {
1547
1569
  return refinementList;
1548
1570
  }
@@ -1552,23 +1574,32 @@
1552
1574
  } else if (typeof attribute === 'function') {
1553
1575
  var hasChanged = false;
1554
1576
 
1555
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
1577
+ var newRefinementList = Object.keys(refinementList).reduce(function (
1578
+ memo,
1579
+ key
1580
+ ) {
1556
1581
  var values = refinementList[key] || [];
1557
- var facetList = values.filter(function(value) {
1582
+ var facetList = values.filter(function (value) {
1558
1583
  return !attribute(value, key, refinementType);
1559
1584
  });
1560
1585
 
1561
1586
  if (facetList.length !== values.length) {
1562
1587
  hasChanged = true;
1563
1588
  }
1589
+
1564
1590
  memo[key] = facetList;
1565
1591
 
1566
1592
  return memo;
1567
- }, {});
1593
+ },
1594
+ {});
1568
1595
 
1569
1596
  if (hasChanged) return newRefinementList;
1570
1597
  return refinementList;
1571
1598
  }
1599
+
1600
+ // We return nothing if the attribute is not undefined, a string or a function,
1601
+ // as it is not a valid value for a refinement
1602
+ return undefined;
1572
1603
  },
1573
1604
  /**
1574
1605
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -1577,10 +1608,11 @@
1577
1608
  * @param {RefinementList} refinementList the list of refinement
1578
1609
  * @param {string} attribute name of the attribute
1579
1610
  * @param {string} [refinementValue] value of the filter/refinement
1580
- * @return {boolean}
1611
+ * @return {boolean} true if the attribute is refined, false otherwise
1581
1612
  */
1582
1613
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
1583
- var containsRefinements = !!refinementList[attribute] &&
1614
+ var containsRefinements =
1615
+ Boolean(refinementList[attribute]) &&
1584
1616
  refinementList[attribute].length > 0;
1585
1617
 
1586
1618
  if (refinementValue === undefined || !containsRefinements) {
@@ -1590,7 +1622,7 @@
1590
1622
  var refinementValueAsString = '' + refinementValue;
1591
1623
 
1592
1624
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
1593
- }
1625
+ },
1594
1626
  };
1595
1627
 
1596
1628
  var RefinementList = lib;
@@ -1601,12 +1633,15 @@
1601
1633
  * - [5]
1602
1634
  * - [[5]]
1603
1635
  * - [[5,5],[4]]
1636
+ * @param {any} a numeric refinement value
1637
+ * @param {any} b numeric refinement value
1638
+ * @return {boolean} true if the values are equal
1604
1639
  */
1605
1640
  function isEqualNumericRefinement(a, b) {
1606
1641
  if (Array.isArray(a) && Array.isArray(b)) {
1607
1642
  return (
1608
1643
  a.length === b.length &&
1609
- a.every(function(el, i) {
1644
+ a.every(function (el, i) {
1610
1645
  return isEqualNumericRefinement(b[i], el);
1611
1646
  })
1612
1647
  );
@@ -1623,7 +1658,7 @@
1623
1658
  * @return {any} the searched value or undefined
1624
1659
  */
1625
1660
  function findArray(array, searchedValue) {
1626
- return find$1(array, function(currentValue) {
1661
+ return find$1(array, function (currentValue) {
1627
1662
  return isEqualNumericRefinement(currentValue, searchedValue);
1628
1663
  });
1629
1664
  }
@@ -1676,10 +1711,15 @@
1676
1711
  }
1677
1712
  */
1678
1713
  function SearchParameters(newParameters) {
1679
- var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
1714
+ var params = newParameters
1715
+ ? SearchParameters._parseNumbers(newParameters)
1716
+ : {};
1680
1717
 
1681
1718
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
1682
- console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
1719
+ // eslint-disable-next-line no-console
1720
+ console.warn(
1721
+ '[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}'
1722
+ );
1683
1723
  }
1684
1724
  /**
1685
1725
  * This attribute contains the list of all the conjunctive facets
@@ -1779,10 +1819,12 @@
1779
1819
  * be translated into the `facetFilters` attribute.
1780
1820
  * @member {Object.<string, SearchParameters.FacetList>}
1781
1821
  */
1782
- this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
1822
+ this.hierarchicalFacetsRefinements =
1823
+ params.hierarchicalFacetsRefinements || {};
1783
1824
 
1825
+ // eslint-disable-next-line consistent-this
1784
1826
  var self = this;
1785
- Object.keys(params).forEach(function(paramName) {
1827
+ Object.keys(params).forEach(function (paramName) {
1786
1828
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
1787
1829
  var isValueDefined = params[paramName] !== undefined;
1788
1830
 
@@ -1804,8 +1846,8 @@
1804
1846
  * @param {object} partialState full or part of a state
1805
1847
  * @return {object} a new object with the number keys as number
1806
1848
  */
1807
- SearchParameters._parseNumbers = function(partialState) {
1808
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
1849
+ SearchParameters._parseNumbers = function (partialState) {
1850
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
1809
1851
  if (partialState instanceof SearchParameters) return partialState;
1810
1852
 
1811
1853
  var numbers = {};
@@ -1821,10 +1863,10 @@
1821
1863
  'distinct',
1822
1864
  'minimumAroundRadius',
1823
1865
  'hitsPerPage',
1824
- 'minProximity'
1866
+ 'minProximity',
1825
1867
  ];
1826
1868
 
1827
- numberKeys.forEach(function(k) {
1869
+ numberKeys.forEach(function (k) {
1828
1870
  var value = partialState[k];
1829
1871
  if (typeof value === 'string') {
1830
1872
  var parsedValue = parseFloat(value);
@@ -1836,9 +1878,11 @@
1836
1878
  // there's two formats of insideBoundingBox, we need to parse
1837
1879
  // the one which is an array of float geo rectangles
1838
1880
  if (Array.isArray(partialState.insideBoundingBox)) {
1839
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
1881
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (
1882
+ geoRect
1883
+ ) {
1840
1884
  if (Array.isArray(geoRect)) {
1841
- return geoRect.map(function(value) {
1885
+ return geoRect.map(function (value) {
1842
1886
  return parseFloat(value);
1843
1887
  });
1844
1888
  }
@@ -1848,14 +1892,14 @@
1848
1892
 
1849
1893
  if (partialState.numericRefinements) {
1850
1894
  var numericRefinements = {};
1851
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
1895
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
1852
1896
  var operators = partialState.numericRefinements[attribute] || {};
1853
1897
  numericRefinements[attribute] = {};
1854
- Object.keys(operators).forEach(function(operator) {
1898
+ Object.keys(operators).forEach(function (operator) {
1855
1899
  var values = operators[operator];
1856
- var parsedValues = values.map(function(v) {
1900
+ var parsedValues = values.map(function (v) {
1857
1901
  if (Array.isArray(v)) {
1858
- return v.map(function(vPrime) {
1902
+ return v.map(function (vPrime) {
1859
1903
  if (typeof vPrime === 'string') {
1860
1904
  return parseFloat(vPrime);
1861
1905
  }
@@ -1885,18 +1929,24 @@
1885
1929
  var instance = new SearchParameters(newParameters);
1886
1930
 
1887
1931
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
1888
- hierarchicalFacets.forEach(function(facet) {
1932
+ hierarchicalFacets.forEach(function (facet) {
1889
1933
  if (facet.rootPath) {
1890
1934
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
1891
1935
 
1892
- if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
1936
+ if (
1937
+ currentRefinement.length > 0 &&
1938
+ currentRefinement[0].indexOf(facet.rootPath) !== 0
1939
+ ) {
1893
1940
  instance = instance.clearRefinements(facet.name);
1894
1941
  }
1895
1942
 
1896
1943
  // get it again in case it has been cleared
1897
1944
  currentRefinement = instance.getHierarchicalRefinement(facet.name);
1898
1945
  if (currentRefinement.length === 0) {
1899
- instance = instance.toggleHierarchicalFacetRefinement(facet.name, facet.rootPath);
1946
+ instance = instance.toggleHierarchicalFacetRefinement(
1947
+ facet.name,
1948
+ facet.rootPath
1949
+ );
1900
1950
  }
1901
1951
  }
1902
1952
  });
@@ -1910,19 +1960,25 @@
1910
1960
  * @param {object|SearchParameters} parameters the new parameters to set
1911
1961
  * @return {Error|null} Error if the modification is invalid, null otherwise
1912
1962
  */
1913
- SearchParameters.validate = function(currentState, parameters) {
1963
+ SearchParameters.validate = function (currentState, parameters) {
1914
1964
  var params = parameters || {};
1915
1965
 
1916
- if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
1966
+ if (
1967
+ currentState.tagFilters &&
1968
+ params.tagRefinements &&
1969
+ params.tagRefinements.length > 0
1970
+ ) {
1917
1971
  return new Error(
1918
1972
  '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
1919
- 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
1973
+ 'an error, if it is really what you want, you should first clear the tags with clearTags method.'
1974
+ );
1920
1975
  }
1921
1976
 
1922
1977
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
1923
1978
  return new Error(
1924
1979
  '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
1925
- 'an error, if it is not, you should first clear the tags with clearTags method.');
1980
+ 'an error, if it is not, you should first clear the tags with clearTags method.'
1981
+ );
1926
1982
  }
1927
1983
 
1928
1984
  if (
@@ -1940,8 +1996,9 @@
1940
1996
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
1941
1997
  return new Error(
1942
1998
  "[Numeric filters] Can't switch from the managed API to the advanced. It" +
1943
- ' is probably an error, if this is really what you want, you have to first' +
1944
- ' clear the numeric filters.');
1999
+ ' is probably an error, if this is really what you want, you have to first' +
2000
+ ' clear the numeric filters.'
2001
+ );
1945
2002
  }
1946
2003
 
1947
2004
  return null;
@@ -1957,7 +2014,7 @@
1957
2014
  * - If not given, means to clear all the filters.
1958
2015
  * - If `string`, means to clear all refinements for the `attribute` named filter.
1959
2016
  * - If `function`, means to clear all the refinements that return truthy values.
1960
- * @return {SearchParameters}
2017
+ * @return {SearchParameters} new instance with filters cleared
1961
2018
  */
1962
2019
  clearRefinements: function clearRefinements(attribute) {
1963
2020
  var patch = {
@@ -1981,13 +2038,14 @@
1981
2038
  this.hierarchicalFacetsRefinements,
1982
2039
  attribute,
1983
2040
  'hierarchicalFacet'
1984
- )
2041
+ ),
1985
2042
  };
1986
2043
  if (
1987
2044
  patch.numericRefinements === this.numericRefinements &&
1988
2045
  patch.facetsRefinements === this.facetsRefinements &&
1989
2046
  patch.facetsExcludes === this.facetsExcludes &&
1990
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
2047
+ patch.disjunctiveFacetsRefinements ===
2048
+ this.disjunctiveFacetsRefinements &&
1991
2049
  patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
1992
2050
  ) {
1993
2051
  return this;
@@ -1997,53 +2055,54 @@
1997
2055
  /**
1998
2056
  * Remove all the refined tags from the SearchParameters
1999
2057
  * @method
2000
- * @return {SearchParameters}
2058
+ * @return {SearchParameters} new instance with tags cleared
2001
2059
  */
2002
2060
  clearTags: function clearTags() {
2003
- if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
2061
+ if (this.tagFilters === undefined && this.tagRefinements.length === 0)
2062
+ return this;
2004
2063
 
2005
2064
  return this.setQueryParameters({
2006
2065
  tagFilters: undefined,
2007
- tagRefinements: []
2066
+ tagRefinements: [],
2008
2067
  });
2009
2068
  },
2010
2069
  /**
2011
2070
  * Set the index.
2012
2071
  * @method
2013
2072
  * @param {string} index the index name
2014
- * @return {SearchParameters}
2073
+ * @return {SearchParameters} new instance
2015
2074
  */
2016
2075
  setIndex: function setIndex(index) {
2017
2076
  if (index === this.index) return this;
2018
2077
 
2019
2078
  return this.setQueryParameters({
2020
- index: index
2079
+ index: index,
2021
2080
  });
2022
2081
  },
2023
2082
  /**
2024
2083
  * Query setter
2025
2084
  * @method
2026
2085
  * @param {string} newQuery value for the new query
2027
- * @return {SearchParameters}
2086
+ * @return {SearchParameters} new instance
2028
2087
  */
2029
2088
  setQuery: function setQuery(newQuery) {
2030
2089
  if (newQuery === this.query) return this;
2031
2090
 
2032
2091
  return this.setQueryParameters({
2033
- query: newQuery
2092
+ query: newQuery,
2034
2093
  });
2035
2094
  },
2036
2095
  /**
2037
2096
  * Page setter
2038
2097
  * @method
2039
2098
  * @param {number} newPage new page number
2040
- * @return {SearchParameters}
2099
+ * @return {SearchParameters} new instance
2041
2100
  */
2042
2101
  setPage: function setPage(newPage) {
2043
2102
  if (newPage === this.page) return this;
2044
2103
 
2045
2104
  return this.setQueryParameters({
2046
- page: newPage
2105
+ page: newPage,
2047
2106
  });
2048
2107
  },
2049
2108
  /**
@@ -2051,11 +2110,11 @@
2051
2110
  * The facets are the simple facets, used for conjunctive (and) faceting.
2052
2111
  * @method
2053
2112
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
2054
- * @return {SearchParameters}
2113
+ * @return {SearchParameters} new instance
2055
2114
  */
2056
2115
  setFacets: function setFacets(facets) {
2057
2116
  return this.setQueryParameters({
2058
- facets: facets
2117
+ facets: facets,
2059
2118
  });
2060
2119
  },
2061
2120
  /**
@@ -2063,11 +2122,11 @@
2063
2122
  * Change the list of disjunctive (or) facets the helper chan handle.
2064
2123
  * @method
2065
2124
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
2066
- * @return {SearchParameters}
2125
+ * @return {SearchParameters} new instance
2067
2126
  */
2068
2127
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
2069
2128
  return this.setQueryParameters({
2070
- disjunctiveFacets: facets
2129
+ disjunctiveFacets: facets,
2071
2130
  });
2072
2131
  },
2073
2132
  /**
@@ -2075,13 +2134,13 @@
2075
2134
  * Hits per page represents the number of hits retrieved for this query
2076
2135
  * @method
2077
2136
  * @param {number} n number of hits retrieved per page of results
2078
- * @return {SearchParameters}
2137
+ * @return {SearchParameters} new instance
2079
2138
  */
2080
2139
  setHitsPerPage: function setHitsPerPage(n) {
2081
2140
  if (this.hitsPerPage === n) return this;
2082
2141
 
2083
2142
  return this.setQueryParameters({
2084
- hitsPerPage: n
2143
+ hitsPerPage: n,
2085
2144
  });
2086
2145
  },
2087
2146
  /**
@@ -2089,13 +2148,13 @@
2089
2148
  * Set the value of typoTolerance
2090
2149
  * @method
2091
2150
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
2092
- * @return {SearchParameters}
2151
+ * @return {SearchParameters} new instance
2093
2152
  */
2094
2153
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
2095
2154
  if (this.typoTolerance === typoTolerance) return this;
2096
2155
 
2097
2156
  return this.setQueryParameters({
2098
- typoTolerance: typoTolerance
2157
+ typoTolerance: typoTolerance,
2099
2158
  });
2100
2159
  },
2101
2160
  /**
@@ -2106,19 +2165,19 @@
2106
2165
  * @param {string} attribute attribute to set the filter on
2107
2166
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
2108
2167
  * @param {number | number[]} value value of the filter
2109
- * @return {SearchParameters}
2168
+ * @return {SearchParameters} new instance
2110
2169
  * @example
2111
2170
  * // for price = 50 or 40
2112
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
2171
+ * state.addNumericRefinement('price', '=', [50, 40]);
2113
2172
  * @example
2114
2173
  * // for size = 38 and 40
2115
- * searchparameter.addNumericRefinement('size', '=', 38);
2116
- * searchparameter.addNumericRefinement('size', '=', 40);
2174
+ * state.addNumericRefinement('size', '=', 38);
2175
+ * state.addNumericRefinement('size', '=', 40);
2117
2176
  */
2118
- addNumericRefinement: function(attribute, operator, v) {
2119
- var value = valToNumber_1(v);
2177
+ addNumericRefinement: function (attribute, operator, value) {
2178
+ var val = valToNumber_1(value);
2120
2179
 
2121
- if (this.isNumericRefined(attribute, operator, value)) return this;
2180
+ if (this.isNumericRefined(attribute, operator, val)) return this;
2122
2181
 
2123
2182
  var mod = merge_1({}, this.numericRefinements);
2124
2183
 
@@ -2128,13 +2187,13 @@
2128
2187
  // Array copy
2129
2188
  mod[attribute][operator] = mod[attribute][operator].slice();
2130
2189
  // Add the element. Concat can't be used here because value can be an array.
2131
- mod[attribute][operator].push(value);
2190
+ mod[attribute][operator].push(val);
2132
2191
  } else {
2133
- mod[attribute][operator] = [value];
2192
+ mod[attribute][operator] = [val];
2134
2193
  }
2135
2194
 
2136
2195
  return this.setQueryParameters({
2137
- numericRefinements: mod
2196
+ numericRefinements: mod,
2138
2197
  });
2139
2198
  },
2140
2199
  /**
@@ -2142,7 +2201,7 @@
2142
2201
  * @param {string} facetName name of the attribute used for faceting
2143
2202
  * @return {string[]} list of refinements
2144
2203
  */
2145
- getConjunctiveRefinements: function(facetName) {
2204
+ getConjunctiveRefinements: function (facetName) {
2146
2205
  if (!this.isConjunctiveFacet(facetName)) {
2147
2206
  return [];
2148
2207
  }
@@ -2153,7 +2212,7 @@
2153
2212
  * @param {string} facetName name of the attribute used for faceting
2154
2213
  * @return {string[]} list of refinements
2155
2214
  */
2156
- getDisjunctiveRefinements: function(facetName) {
2215
+ getDisjunctiveRefinements: function (facetName) {
2157
2216
  if (!this.isDisjunctiveFacet(facetName)) {
2158
2217
  return [];
2159
2218
  }
@@ -2164,7 +2223,7 @@
2164
2223
  * @param {string} facetName name of the attribute used for faceting
2165
2224
  * @return {string[]} list of refinements
2166
2225
  */
2167
- getHierarchicalRefinement: function(facetName) {
2226
+ getHierarchicalRefinement: function (facetName) {
2168
2227
  // we send an array but we currently do not support multiple
2169
2228
  // hierarchicalRefinements for a hierarchicalFacet
2170
2229
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -2174,7 +2233,7 @@
2174
2233
  * @param {string} facetName name of the attribute used for faceting
2175
2234
  * @return {string[]} list of refinements
2176
2235
  */
2177
- getExcludeRefinements: function(facetName) {
2236
+ getExcludeRefinements: function (facetName) {
2178
2237
  if (!this.isConjunctiveFacet(facetName)) {
2179
2238
  return [];
2180
2239
  }
@@ -2187,36 +2246,43 @@
2187
2246
  * @param {string} attribute attribute to set the filter on
2188
2247
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
2189
2248
  * @param {number} [number] the value to be removed
2190
- * @return {SearchParameters}
2249
+ * @return {SearchParameters} new instance
2191
2250
  */
2192
- removeNumericRefinement: function(attribute, operator, paramValue) {
2251
+ removeNumericRefinement: function (attribute, operator, number) {
2252
+ var paramValue = number;
2193
2253
  if (paramValue !== undefined) {
2194
2254
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
2195
2255
  return this;
2196
2256
  }
2197
2257
  return this.setQueryParameters({
2198
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2258
+ numericRefinements: this._clearNumericRefinements(function (
2259
+ value,
2260
+ key
2261
+ ) {
2199
2262
  return (
2200
2263
  key === attribute &&
2201
2264
  value.op === operator &&
2202
2265
  isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
2203
2266
  );
2204
- })
2267
+ }),
2205
2268
  });
2206
2269
  } else if (operator !== undefined) {
2207
2270
  if (!this.isNumericRefined(attribute, operator)) return this;
2208
2271
  return this.setQueryParameters({
2209
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2272
+ numericRefinements: this._clearNumericRefinements(function (
2273
+ value,
2274
+ key
2275
+ ) {
2210
2276
  return key === attribute && value.op === operator;
2211
- })
2277
+ }),
2212
2278
  });
2213
2279
  }
2214
2280
 
2215
2281
  if (!this.isNumericRefined(attribute)) return this;
2216
2282
  return this.setQueryParameters({
2217
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2283
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2218
2284
  return key === attribute;
2219
- })
2285
+ }),
2220
2286
  });
2221
2287
  },
2222
2288
  /**
@@ -2224,7 +2290,7 @@
2224
2290
  * @param {string} facetName name of the attribute used for faceting
2225
2291
  * @return {SearchParameters.OperatorList} list of refinements
2226
2292
  */
2227
- getNumericRefinements: function(facetName) {
2293
+ getNumericRefinements: function (facetName) {
2228
2294
  return this.numericRefinements[facetName] || {};
2229
2295
  },
2230
2296
  /**
@@ -2233,8 +2299,11 @@
2233
2299
  * @param {string} operator operator applied on the refined values
2234
2300
  * @return {Array.<number|number[]>} refined values
2235
2301
  */
2236
- getNumericRefinement: function(attribute, operator) {
2237
- return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
2302
+ getNumericRefinement: function (attribute, operator) {
2303
+ return (
2304
+ this.numericRefinements[attribute] &&
2305
+ this.numericRefinements[attribute][operator]
2306
+ );
2238
2307
  },
2239
2308
  /**
2240
2309
  * Clear numeric filters.
@@ -2244,7 +2313,7 @@
2244
2313
  * - If not given, means to clear all the filters.
2245
2314
  * - If `string`, means to clear all refinements for the `attribute` named filter.
2246
2315
  * - If `function`, means to clear all the refinements that return truthy values.
2247
- * @return {Object.<string, OperatorList>}
2316
+ * @return {Object.<string, OperatorList>} new numeric refinements
2248
2317
  */
2249
2318
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
2250
2319
  if (attribute === undefined) {
@@ -2257,39 +2326,50 @@
2257
2326
  } else if (typeof attribute === 'function') {
2258
2327
  var hasChanged = false;
2259
2328
  var numericRefinements = this.numericRefinements;
2260
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
2261
- var operators = numericRefinements[key];
2262
- var operatorList = {};
2263
-
2264
- operators = operators || {};
2265
- Object.keys(operators).forEach(function(operator) {
2266
- var values = operators[operator] || [];
2267
- var outValues = [];
2268
- values.forEach(function(value) {
2269
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
2270
- if (!predicateResult) outValues.push(value);
2329
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(
2330
+ function (memo, key) {
2331
+ var operators = numericRefinements[key];
2332
+ var operatorList = {};
2333
+
2334
+ operators = operators || {};
2335
+ Object.keys(operators).forEach(function (operator) {
2336
+ var values = operators[operator] || [];
2337
+ var outValues = [];
2338
+ values.forEach(function (value) {
2339
+ var predicateResult = attribute(
2340
+ { val: value, op: operator },
2341
+ key,
2342
+ 'numeric'
2343
+ );
2344
+ if (!predicateResult) outValues.push(value);
2345
+ });
2346
+ if (outValues.length !== values.length) {
2347
+ hasChanged = true;
2348
+ }
2349
+ operatorList[operator] = outValues;
2271
2350
  });
2272
- if (outValues.length !== values.length) {
2273
- hasChanged = true;
2274
- }
2275
- operatorList[operator] = outValues;
2276
- });
2277
2351
 
2278
- memo[key] = operatorList;
2352
+ memo[key] = operatorList;
2279
2353
 
2280
- return memo;
2281
- }, {});
2354
+ return memo;
2355
+ },
2356
+ {}
2357
+ );
2282
2358
 
2283
2359
  if (hasChanged) return newNumericRefinements;
2284
2360
  return this.numericRefinements;
2285
2361
  }
2362
+
2363
+ // We return nothing if the attribute is not undefined, a string or a function,
2364
+ // as it is not a valid value for a refinement
2365
+ return undefined;
2286
2366
  },
2287
2367
  /**
2288
2368
  * Add a facet to the facets attribute of the helper configuration, if it
2289
2369
  * isn't already present.
2290
2370
  * @method
2291
2371
  * @param {string} facet facet name to add
2292
- * @return {SearchParameters}
2372
+ * @return {SearchParameters} new instance
2293
2373
  */
2294
2374
  addFacet: function addFacet(facet) {
2295
2375
  if (this.isConjunctiveFacet(facet)) {
@@ -2297,7 +2377,7 @@
2297
2377
  }
2298
2378
 
2299
2379
  return this.setQueryParameters({
2300
- facets: this.facets.concat([facet])
2380
+ facets: this.facets.concat([facet]),
2301
2381
  });
2302
2382
  },
2303
2383
  /**
@@ -2305,7 +2385,7 @@
2305
2385
  * configuration, if it isn't already present.
2306
2386
  * @method
2307
2387
  * @param {string} facet disjunctive facet name to add
2308
- * @return {SearchParameters}
2388
+ * @return {SearchParameters} new instance
2309
2389
  */
2310
2390
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
2311
2391
  if (this.isDisjunctiveFacet(facet)) {
@@ -2313,7 +2393,7 @@
2313
2393
  }
2314
2394
 
2315
2395
  return this.setQueryParameters({
2316
- disjunctiveFacets: this.disjunctiveFacets.concat([facet])
2396
+ disjunctiveFacets: this.disjunctiveFacets.concat([facet]),
2317
2397
  });
2318
2398
  },
2319
2399
  /**
@@ -2321,17 +2401,20 @@
2321
2401
  * configuration.
2322
2402
  * @method
2323
2403
  * @param {object} hierarchicalFacet hierarchical facet to add
2324
- * @return {SearchParameters}
2404
+ * @return {SearchParameters} new instance
2325
2405
  * @throws will throw an error if a hierarchical facet with the same name was already declared
2326
2406
  */
2327
2407
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
2328
2408
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
2329
2409
  throw new Error(
2330
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2410
+ 'Cannot declare two hierarchical facets with the same name: `' +
2411
+ hierarchicalFacet.name +
2412
+ '`'
2413
+ );
2331
2414
  }
2332
2415
 
2333
2416
  return this.setQueryParameters({
2334
- hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
2417
+ hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet]),
2335
2418
  });
2336
2419
  },
2337
2420
  /**
@@ -2339,16 +2422,24 @@
2339
2422
  * @method
2340
2423
  * @param {string} facet attribute to apply the faceting on
2341
2424
  * @param {string} value value of the attribute (will be converted to string)
2342
- * @return {SearchParameters}
2425
+ * @return {SearchParameters} new instance
2343
2426
  */
2344
2427
  addFacetRefinement: function addFacetRefinement(facet, value) {
2345
2428
  if (!this.isConjunctiveFacet(facet)) {
2346
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2429
+ throw new Error(
2430
+ facet +
2431
+ ' is not defined in the facets attribute of the helper configuration'
2432
+ );
2347
2433
  }
2348
- if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2434
+ if (RefinementList.isRefined(this.facetsRefinements, facet, value))
2435
+ return this;
2349
2436
 
2350
2437
  return this.setQueryParameters({
2351
- facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
2438
+ facetsRefinements: RefinementList.addRefinement(
2439
+ this.facetsRefinements,
2440
+ facet,
2441
+ value
2442
+ ),
2352
2443
  });
2353
2444
  },
2354
2445
  /**
@@ -2356,16 +2447,24 @@
2356
2447
  * @method
2357
2448
  * @param {string} facet attribute to apply the exclusion on
2358
2449
  * @param {string} value value of the attribute (will be converted to string)
2359
- * @return {SearchParameters}
2450
+ * @return {SearchParameters} new instance
2360
2451
  */
2361
2452
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
2362
2453
  if (!this.isConjunctiveFacet(facet)) {
2363
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2454
+ throw new Error(
2455
+ facet +
2456
+ ' is not defined in the facets attribute of the helper configuration'
2457
+ );
2364
2458
  }
2365
- if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2459
+ if (RefinementList.isRefined(this.facetsExcludes, facet, value))
2460
+ return this;
2366
2461
 
2367
2462
  return this.setQueryParameters({
2368
- facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
2463
+ facetsExcludes: RefinementList.addRefinement(
2464
+ this.facetsExcludes,
2465
+ facet,
2466
+ value
2467
+ ),
2369
2468
  });
2370
2469
  },
2371
2470
  /**
@@ -2373,31 +2472,42 @@
2373
2472
  * @method
2374
2473
  * @param {string} facet attribute to apply the faceting on
2375
2474
  * @param {string} value value of the attribute (will be converted to string)
2376
- * @return {SearchParameters}
2475
+ * @return {SearchParameters} new instance
2377
2476
  */
2378
- addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
2477
+ addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(
2478
+ facet,
2479
+ value
2480
+ ) {
2379
2481
  if (!this.isDisjunctiveFacet(facet)) {
2380
2482
  throw new Error(
2381
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2483
+ facet +
2484
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2485
+ );
2382
2486
  }
2383
2487
 
2384
- if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2488
+ if (
2489
+ RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
2490
+ )
2491
+ return this;
2385
2492
 
2386
2493
  return this.setQueryParameters({
2387
2494
  disjunctiveFacetsRefinements: RefinementList.addRefinement(
2388
- this.disjunctiveFacetsRefinements, facet, value)
2495
+ this.disjunctiveFacetsRefinements,
2496
+ facet,
2497
+ value
2498
+ ),
2389
2499
  });
2390
2500
  },
2391
2501
  /**
2392
2502
  * addTagRefinement adds a tag to the list used to filter the results
2393
2503
  * @param {string} tag tag to be added
2394
- * @return {SearchParameters}
2504
+ * @return {SearchParameters} new instance
2395
2505
  */
2396
2506
  addTagRefinement: function addTagRefinement(tag) {
2397
2507
  if (this.isTagRefined(tag)) return this;
2398
2508
 
2399
2509
  var modification = {
2400
- tagRefinements: this.tagRefinements.concat(tag)
2510
+ tagRefinements: this.tagRefinements.concat(tag),
2401
2511
  };
2402
2512
 
2403
2513
  return this.setQueryParameters(modification);
@@ -2407,7 +2517,7 @@
2407
2517
  * is present.
2408
2518
  * @method
2409
2519
  * @param {string} facet facet name to remove
2410
- * @return {SearchParameters}
2520
+ * @return {SearchParameters} new instance
2411
2521
  */
2412
2522
  removeFacet: function removeFacet(facet) {
2413
2523
  if (!this.isConjunctiveFacet(facet)) {
@@ -2415,9 +2525,9 @@
2415
2525
  }
2416
2526
 
2417
2527
  return this.clearRefinements(facet).setQueryParameters({
2418
- facets: this.facets.filter(function(f) {
2528
+ facets: this.facets.filter(function (f) {
2419
2529
  return f !== facet;
2420
- })
2530
+ }),
2421
2531
  });
2422
2532
  },
2423
2533
  /**
@@ -2425,7 +2535,7 @@
2425
2535
  * helper configuration, if it is present.
2426
2536
  * @method
2427
2537
  * @param {string} facet disjunctive facet name to remove
2428
- * @return {SearchParameters}
2538
+ * @return {SearchParameters} new instance
2429
2539
  */
2430
2540
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
2431
2541
  if (!this.isDisjunctiveFacet(facet)) {
@@ -2433,9 +2543,9 @@
2433
2543
  }
2434
2544
 
2435
2545
  return this.clearRefinements(facet).setQueryParameters({
2436
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
2546
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
2437
2547
  return f !== facet;
2438
- })
2548
+ }),
2439
2549
  });
2440
2550
  },
2441
2551
  /**
@@ -2443,7 +2553,7 @@
2443
2553
  * helper configuration, if it is present.
2444
2554
  * @method
2445
2555
  * @param {string} facet hierarchical facet name to remove
2446
- * @return {SearchParameters}
2556
+ * @return {SearchParameters} new instance
2447
2557
  */
2448
2558
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
2449
2559
  if (!this.isHierarchicalFacet(facet)) {
@@ -2451,9 +2561,9 @@
2451
2561
  }
2452
2562
 
2453
2563
  return this.clearRefinements(facet).setQueryParameters({
2454
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
2564
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
2455
2565
  return f.name !== facet;
2456
- })
2566
+ }),
2457
2567
  });
2458
2568
  },
2459
2569
  /**
@@ -2463,16 +2573,24 @@
2463
2573
  * @method
2464
2574
  * @param {string} facet name of the attribute used for faceting
2465
2575
  * @param {string} [value] value used to filter
2466
- * @return {SearchParameters}
2576
+ * @return {SearchParameters} new instance
2467
2577
  */
2468
2578
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
2469
2579
  if (!this.isConjunctiveFacet(facet)) {
2470
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2580
+ throw new Error(
2581
+ facet +
2582
+ ' is not defined in the facets attribute of the helper configuration'
2583
+ );
2471
2584
  }
2472
- if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2585
+ if (!RefinementList.isRefined(this.facetsRefinements, facet, value))
2586
+ return this;
2473
2587
 
2474
2588
  return this.setQueryParameters({
2475
- facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
2589
+ facetsRefinements: RefinementList.removeRefinement(
2590
+ this.facetsRefinements,
2591
+ facet,
2592
+ value
2593
+ ),
2476
2594
  });
2477
2595
  },
2478
2596
  /**
@@ -2480,16 +2598,24 @@
2480
2598
  * @method
2481
2599
  * @param {string} facet name of the attribute used for faceting
2482
2600
  * @param {string} value value used to filter
2483
- * @return {SearchParameters}
2601
+ * @return {SearchParameters} new instance
2484
2602
  */
2485
2603
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
2486
2604
  if (!this.isConjunctiveFacet(facet)) {
2487
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2605
+ throw new Error(
2606
+ facet +
2607
+ ' is not defined in the facets attribute of the helper configuration'
2608
+ );
2488
2609
  }
2489
- if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2610
+ if (!RefinementList.isRefined(this.facetsExcludes, facet, value))
2611
+ return this;
2490
2612
 
2491
2613
  return this.setQueryParameters({
2492
- facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
2614
+ facetsExcludes: RefinementList.removeRefinement(
2615
+ this.facetsExcludes,
2616
+ facet,
2617
+ value
2618
+ ),
2493
2619
  });
2494
2620
  },
2495
2621
  /**
@@ -2497,33 +2623,44 @@
2497
2623
  * @method
2498
2624
  * @param {string} facet name of the attribute used for faceting
2499
2625
  * @param {string} value value used to filter
2500
- * @return {SearchParameters}
2626
+ * @return {SearchParameters} new instance
2501
2627
  */
2502
- removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
2628
+ removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(
2629
+ facet,
2630
+ value
2631
+ ) {
2503
2632
  if (!this.isDisjunctiveFacet(facet)) {
2504
2633
  throw new Error(
2505
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2634
+ facet +
2635
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2636
+ );
2506
2637
  }
2507
- if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2638
+ if (
2639
+ !RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)
2640
+ )
2641
+ return this;
2508
2642
 
2509
2643
  return this.setQueryParameters({
2510
2644
  disjunctiveFacetsRefinements: RefinementList.removeRefinement(
2511
- this.disjunctiveFacetsRefinements, facet, value)
2645
+ this.disjunctiveFacetsRefinements,
2646
+ facet,
2647
+ value
2648
+ ),
2512
2649
  });
2513
2650
  },
2514
2651
  /**
2515
2652
  * Remove a tag from the list of tag refinements
2516
2653
  * @method
2517
2654
  * @param {string} tag the tag to remove
2518
- * @return {SearchParameters}
2655
+ * @return {SearchParameters} new instance
2519
2656
  */
2520
2657
  removeTagRefinement: function removeTagRefinement(tag) {
2521
2658
  if (!this.isTagRefined(tag)) return this;
2522
2659
 
2523
2660
  var modification = {
2524
- tagRefinements: this.tagRefinements.filter(function(t) {
2661
+ tagRefinements: this.tagRefinements.filter(function (t) {
2525
2662
  return t !== tag;
2526
- })
2663
+ }),
2527
2664
  };
2528
2665
 
2529
2666
  return this.setQueryParameters(modification);
@@ -2533,7 +2670,7 @@
2533
2670
  * and hierarchical facets
2534
2671
  * @param {string} facet the facet to refine
2535
2672
  * @param {string} value the associated value
2536
- * @return {SearchParameters}
2673
+ * @return {SearchParameters} new instance
2537
2674
  * @throws will throw an error if the facet is not declared in the settings of the helper
2538
2675
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
2539
2676
  */
@@ -2545,7 +2682,7 @@
2545
2682
  * and hierarchical facets
2546
2683
  * @param {string} facet the facet to refine
2547
2684
  * @param {string} value the associated value
2548
- * @return {SearchParameters}
2685
+ * @return {SearchParameters} new instance
2549
2686
  * @throws will throw an error if the facet is not declared in the settings of the helper
2550
2687
  */
2551
2688
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -2557,23 +2694,36 @@
2557
2694
  return this.toggleDisjunctiveFacetRefinement(facet, value);
2558
2695
  }
2559
2696
 
2560
- throw new Error('Cannot refine the undeclared facet ' + facet +
2561
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2697
+ throw new Error(
2698
+ 'Cannot refine the undeclared facet ' +
2699
+ facet +
2700
+ '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets'
2701
+ );
2562
2702
  },
2563
2703
  /**
2564
2704
  * Switch the refinement applied over a facet/value
2565
2705
  * @method
2566
2706
  * @param {string} facet name of the attribute used for faceting
2567
2707
  * @param {value} value value used for filtering
2568
- * @return {SearchParameters}
2708
+ * @return {SearchParameters} new instance
2569
2709
  */
2570
- toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
2710
+ toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(
2711
+ facet,
2712
+ value
2713
+ ) {
2571
2714
  if (!this.isConjunctiveFacet(facet)) {
2572
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2715
+ throw new Error(
2716
+ facet +
2717
+ ' is not defined in the facets attribute of the helper configuration'
2718
+ );
2573
2719
  }
2574
2720
 
2575
2721
  return this.setQueryParameters({
2576
- facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
2722
+ facetsRefinements: RefinementList.toggleRefinement(
2723
+ this.facetsRefinements,
2724
+ facet,
2725
+ value
2726
+ ),
2577
2727
  });
2578
2728
  },
2579
2729
  /**
@@ -2581,15 +2731,25 @@
2581
2731
  * @method
2582
2732
  * @param {string} facet name of the attribute used for faceting
2583
2733
  * @param {value} value value used for filtering
2584
- * @return {SearchParameters}
2734
+ * @return {SearchParameters} new instance
2585
2735
  */
2586
- toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
2736
+ toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(
2737
+ facet,
2738
+ value
2739
+ ) {
2587
2740
  if (!this.isConjunctiveFacet(facet)) {
2588
- throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2741
+ throw new Error(
2742
+ facet +
2743
+ ' is not defined in the facets attribute of the helper configuration'
2744
+ );
2589
2745
  }
2590
2746
 
2591
2747
  return this.setQueryParameters({
2592
- facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
2748
+ facetsExcludes: RefinementList.toggleRefinement(
2749
+ this.facetsExcludes,
2750
+ facet,
2751
+ value
2752
+ ),
2593
2753
  });
2594
2754
  },
2595
2755
  /**
@@ -2597,17 +2757,25 @@
2597
2757
  * @method
2598
2758
  * @param {string} facet name of the attribute used for faceting
2599
2759
  * @param {value} value value used for filtering
2600
- * @return {SearchParameters}
2760
+ * @return {SearchParameters} new instance
2601
2761
  */
2602
- toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
2762
+ toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(
2763
+ facet,
2764
+ value
2765
+ ) {
2603
2766
  if (!this.isDisjunctiveFacet(facet)) {
2604
2767
  throw new Error(
2605
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2768
+ facet +
2769
+ ' is not defined in the disjunctiveFacets attribute of the helper configuration'
2770
+ );
2606
2771
  }
2607
2772
 
2608
2773
  return this.setQueryParameters({
2609
2774
  disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
2610
- this.disjunctiveFacetsRefinements, facet, value)
2775
+ this.disjunctiveFacetsRefinements,
2776
+ facet,
2777
+ value
2778
+ ),
2611
2779
  });
2612
2780
  },
2613
2781
  /**
@@ -2615,29 +2783,38 @@
2615
2783
  * @method
2616
2784
  * @param {string} facet name of the attribute used for faceting
2617
2785
  * @param {value} value value used for filtering
2618
- * @return {SearchParameters}
2786
+ * @return {SearchParameters} new instance
2619
2787
  */
2620
- toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
2788
+ toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(
2789
+ facet,
2790
+ value
2791
+ ) {
2621
2792
  if (!this.isHierarchicalFacet(facet)) {
2622
2793
  throw new Error(
2623
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
2794
+ facet +
2795
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration'
2796
+ );
2624
2797
  }
2625
2798
 
2626
- var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
2799
+ var separator = this._getHierarchicalFacetSeparator(
2800
+ this.getHierarchicalFacetByName(facet)
2801
+ );
2627
2802
 
2628
2803
  var mod = {};
2629
2804
 
2630
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
2631
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
2805
+ var upOneOrMultipleLevel =
2806
+ this.hierarchicalFacetsRefinements[facet] !== undefined &&
2807
+ this.hierarchicalFacetsRefinements[facet].length > 0 &&
2632
2808
  // remove current refinement:
2633
2809
  // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2634
- this.hierarchicalFacetsRefinements[facet][0] === value ||
2635
- // remove a parent refinement of the current refinement:
2636
- // - refinement was 'beer > IPA > Flying dog'
2637
- // - call is toggleRefine('beer > IPA')
2638
- // - refinement should be `beer`
2639
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
2640
- );
2810
+ (this.hierarchicalFacetsRefinements[facet][0] === value ||
2811
+ // remove a parent refinement of the current refinement:
2812
+ // - refinement was 'beer > IPA > Flying dog'
2813
+ // - call is toggleRefine('beer > IPA')
2814
+ // - refinement should be `beer`
2815
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(
2816
+ value + separator
2817
+ ) === 0);
2641
2818
 
2642
2819
  if (upOneOrMultipleLevel) {
2643
2820
  if (value.indexOf(separator) === -1) {
@@ -2651,7 +2828,11 @@
2651
2828
  }
2652
2829
 
2653
2830
  return this.setQueryParameters({
2654
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2831
+ hierarchicalFacetsRefinements: defaultsPure(
2832
+ {},
2833
+ mod,
2834
+ this.hierarchicalFacetsRefinements
2835
+ ),
2655
2836
  });
2656
2837
  },
2657
2838
 
@@ -2662,17 +2843,24 @@
2662
2843
  * @return {SearchParameter} the new state
2663
2844
  * @throws Error if the facet is not defined or if the facet is refined
2664
2845
  */
2665
- addHierarchicalFacetRefinement: function(facet, path) {
2846
+ addHierarchicalFacetRefinement: function (facet, path) {
2666
2847
  if (this.isHierarchicalFacetRefined(facet)) {
2667
2848
  throw new Error(facet + ' is already refined.');
2668
2849
  }
2669
2850
  if (!this.isHierarchicalFacet(facet)) {
2670
- throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration.');
2851
+ throw new Error(
2852
+ facet +
2853
+ ' is not defined in the hierarchicalFacets attribute of the helper configuration.'
2854
+ );
2671
2855
  }
2672
2856
  var mod = {};
2673
2857
  mod[facet] = [path];
2674
2858
  return this.setQueryParameters({
2675
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2859
+ hierarchicalFacetsRefinements: defaultsPure(
2860
+ {},
2861
+ mod,
2862
+ this.hierarchicalFacetsRefinements
2863
+ ),
2676
2864
  });
2677
2865
  },
2678
2866
 
@@ -2682,21 +2870,25 @@
2682
2870
  * @return {SearchParameter} the new state
2683
2871
  * @throws Error if the facet is not defined or if the facet is not refined
2684
2872
  */
2685
- removeHierarchicalFacetRefinement: function(facet) {
2873
+ removeHierarchicalFacetRefinement: function (facet) {
2686
2874
  if (!this.isHierarchicalFacetRefined(facet)) {
2687
2875
  return this;
2688
2876
  }
2689
2877
  var mod = {};
2690
2878
  mod[facet] = [];
2691
2879
  return this.setQueryParameters({
2692
- hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2880
+ hierarchicalFacetsRefinements: defaultsPure(
2881
+ {},
2882
+ mod,
2883
+ this.hierarchicalFacetsRefinements
2884
+ ),
2693
2885
  });
2694
2886
  },
2695
2887
  /**
2696
2888
  * Switch the tag refinement
2697
2889
  * @method
2698
2890
  * @param {string} tag the tag to remove or add
2699
- * @return {SearchParameters}
2891
+ * @return {SearchParameters} new instance
2700
2892
  */
2701
2893
  toggleTagRefinement: function toggleTagRefinement(tag) {
2702
2894
  if (this.isTagRefined(tag)) {
@@ -2709,27 +2901,27 @@
2709
2901
  * Test if the facet name is from one of the disjunctive facets
2710
2902
  * @method
2711
2903
  * @param {string} facet facet name to test
2712
- * @return {boolean}
2904
+ * @return {boolean} true if facet is a disjunctive facet
2713
2905
  */
2714
- isDisjunctiveFacet: function(facet) {
2906
+ isDisjunctiveFacet: function (facet) {
2715
2907
  return this.disjunctiveFacets.indexOf(facet) > -1;
2716
2908
  },
2717
2909
  /**
2718
2910
  * Test if the facet name is from one of the hierarchical facets
2719
2911
  * @method
2720
2912
  * @param {string} facetName facet name to test
2721
- * @return {boolean}
2913
+ * @return {boolean} true if facetName is a hierarchical facet
2722
2914
  */
2723
- isHierarchicalFacet: function(facetName) {
2915
+ isHierarchicalFacet: function (facetName) {
2724
2916
  return this.getHierarchicalFacetByName(facetName) !== undefined;
2725
2917
  },
2726
2918
  /**
2727
2919
  * Test if the facet name is from one of the conjunctive/normal facets
2728
2920
  * @method
2729
2921
  * @param {string} facet facet name to test
2730
- * @return {boolean}
2922
+ * @return {boolean} true if facet is a conjunctive facet
2731
2923
  */
2732
- isConjunctiveFacet: function(facet) {
2924
+ isConjunctiveFacet: function (facet) {
2733
2925
  return this.facets.indexOf(facet) > -1;
2734
2926
  },
2735
2927
  /**
@@ -2770,13 +2962,17 @@
2770
2962
  * @param {string} facet name of the attribute for used for faceting
2771
2963
  * @param {string} value optional, will test if the value is used for refinement
2772
2964
  * if there is one, otherwise will test if the facet contains any refinement
2773
- * @return {boolean}
2965
+ * @return {boolean} true if the facet is refined
2774
2966
  */
2775
2967
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
2776
2968
  if (!this.isDisjunctiveFacet(facet)) {
2777
2969
  return false;
2778
2970
  }
2779
- return RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value);
2971
+ return RefinementList.isRefined(
2972
+ this.disjunctiveFacetsRefinements,
2973
+ facet,
2974
+ value
2975
+ );
2780
2976
  },
2781
2977
  /**
2782
2978
  * Returns true if the facet contains a refinement, or if a value passed is a
@@ -2785,9 +2981,12 @@
2785
2981
  * @param {string} facet name of the attribute for used for faceting
2786
2982
  * @param {string} value optional, will test if the value is used for refinement
2787
2983
  * if there is one, otherwise will test if the facet contains any refinement
2788
- * @return {boolean}
2984
+ * @return {boolean} true if the facet is refined
2789
2985
  */
2790
- isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
2986
+ isHierarchicalFacetRefined: function isHierarchicalFacetRefined(
2987
+ facet,
2988
+ value
2989
+ ) {
2791
2990
  if (!this.isHierarchicalFacet(facet)) {
2792
2991
  return false;
2793
2992
  }
@@ -2812,7 +3011,7 @@
2812
3011
  */
2813
3012
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
2814
3013
  if (value === undefined && operator === undefined) {
2815
- return !!this.numericRefinements[attribute];
3014
+ return Boolean(this.numericRefinements[attribute]);
2816
3015
  }
2817
3016
 
2818
3017
  var isOperatorDefined =
@@ -2834,7 +3033,7 @@
2834
3033
  * Returns true if the tag refined, false otherwise
2835
3034
  * @method
2836
3035
  * @param {string} tag the tag to check
2837
- * @return {boolean}
3036
+ * @return {boolean} true if tag is refined
2838
3037
  */
2839
3038
  isTagRefined: function isTagRefined(tag) {
2840
3039
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -2844,22 +3043,24 @@
2844
3043
  * @method
2845
3044
  * @param {string} facet name of the attribute used for faceting
2846
3045
  * @param {value} value value used for filtering
2847
- * @return {string[]}
3046
+ * @return {string[]} returns the list of refinements
2848
3047
  */
2849
3048
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
3049
+ // eslint-disable-next-line consistent-this
2850
3050
  var self = this;
2851
3051
 
2852
3052
  // attributes used for numeric filter can also be disjunctive
2853
3053
  var disjunctiveNumericRefinedFacets = intersection_1(
2854
- Object.keys(this.numericRefinements).filter(function(facet) {
3054
+ Object.keys(this.numericRefinements).filter(function (facet) {
2855
3055
  return Object.keys(self.numericRefinements[facet]).length > 0;
2856
3056
  }),
2857
3057
  this.disjunctiveFacets
2858
3058
  );
2859
3059
 
2860
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
2861
- return self.disjunctiveFacetsRefinements[facet].length > 0;
2862
- })
3060
+ return Object.keys(this.disjunctiveFacetsRefinements)
3061
+ .filter(function (facet) {
3062
+ return self.disjunctiveFacetsRefinements[facet].length > 0;
3063
+ })
2863
3064
  .concat(disjunctiveNumericRefinedFacets)
2864
3065
  .concat(this.getRefinedHierarchicalFacets());
2865
3066
  },
@@ -2868,15 +3069,18 @@
2868
3069
  * @method
2869
3070
  * @param {string} facet name of the attribute used for faceting
2870
3071
  * @param {value} value value used for filtering
2871
- * @return {string[]}
3072
+ * @return {string[]} returns the list of refinements
2872
3073
  */
2873
3074
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
3075
+ // eslint-disable-next-line consistent-this
2874
3076
  var self = this;
2875
3077
  return intersection_1(
2876
3078
  // enforce the order between the two arrays,
2877
3079
  // so that refinement name index === hierarchical facet index
2878
- this.hierarchicalFacets.map(function(facet) { return facet.name; }),
2879
- Object.keys(this.hierarchicalFacetsRefinements).filter(function(facet) {
3080
+ this.hierarchicalFacets.map(function (facet) {
3081
+ return facet.name;
3082
+ }),
3083
+ Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
2880
3084
  return self.hierarchicalFacetsRefinements[facet].length > 0;
2881
3085
  })
2882
3086
  );
@@ -2884,12 +3088,12 @@
2884
3088
  /**
2885
3089
  * Returned the list of all disjunctive facets not refined
2886
3090
  * @method
2887
- * @return {string[]}
3091
+ * @return {string[]} returns the list of facets that are not refined
2888
3092
  */
2889
- getUnrefinedDisjunctiveFacets: function() {
3093
+ getUnrefinedDisjunctiveFacets: function () {
2890
3094
  var refinedFacets = this.getRefinedDisjunctiveFacets();
2891
3095
 
2892
- return this.disjunctiveFacets.filter(function(f) {
3096
+ return this.disjunctiveFacets.filter(function (f) {
2893
3097
  return refinedFacets.indexOf(f) === -1;
2894
3098
  });
2895
3099
  },
@@ -2906,17 +3110,22 @@
2906
3110
  'disjunctiveFacetsRefinements',
2907
3111
  'numericRefinements',
2908
3112
  'tagRefinements',
2909
- 'hierarchicalFacetsRefinements'
3113
+ 'hierarchicalFacetsRefinements',
2910
3114
  ],
3115
+
2911
3116
  getQueryParams: function getQueryParams() {
2912
3117
  var managedParameters = this.managedParameters;
2913
3118
 
2914
3119
  var queryParams = {};
2915
3120
 
3121
+ // eslint-disable-next-line consistent-this
2916
3122
  var self = this;
2917
- Object.keys(this).forEach(function(paramName) {
3123
+ Object.keys(this).forEach(function (paramName) {
2918
3124
  var paramValue = self[paramName];
2919
- if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
3125
+ if (
3126
+ managedParameters.indexOf(paramName) === -1 &&
3127
+ paramValue !== undefined
3128
+ ) {
2920
3129
  queryParams[paramName] = paramValue;
2921
3130
  }
2922
3131
  });
@@ -2957,30 +3166,32 @@
2957
3166
  throw error;
2958
3167
  }
2959
3168
 
3169
+ // eslint-disable-next-line consistent-this
2960
3170
  var self = this;
2961
3171
  var nextWithNumbers = SearchParameters._parseNumbers(params);
2962
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
3172
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
2963
3173
  acc[key] = self[key];
2964
3174
  return acc;
2965
3175
  }, {});
2966
3176
 
2967
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
2968
- function(previous, key) {
2969
- var isPreviousValueDefined = previous[key] !== undefined;
2970
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
3177
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (
3178
+ previous,
3179
+ key
3180
+ ) {
3181
+ var isPreviousValueDefined = previous[key] !== undefined;
3182
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
2971
3183
 
2972
- if (isPreviousValueDefined && !isNextValueDefined) {
2973
- return omit$1(previous, [key]);
2974
- }
3184
+ if (isPreviousValueDefined && !isNextValueDefined) {
3185
+ return omit$1(previous, [key]);
3186
+ }
2975
3187
 
2976
- if (isNextValueDefined) {
2977
- previous[key] = nextWithNumbers[key];
2978
- }
3188
+ if (isNextValueDefined) {
3189
+ previous[key] = nextWithNumbers[key];
3190
+ }
2979
3191
 
2980
- return previous;
2981
- },
2982
- previousPlainObject
2983
- );
3192
+ return previous;
3193
+ },
3194
+ previousPlainObject);
2984
3195
 
2985
3196
  return new this.constructor(nextPlainObject);
2986
3197
  },
@@ -2991,7 +3202,7 @@
2991
3202
  * the page is set -> return a new instance with a page of 0
2992
3203
  * @return {SearchParameters} a new updated instance
2993
3204
  */
2994
- resetPage: function() {
3205
+ resetPage: function () {
2995
3206
  if (this.page === undefined) {
2996
3207
  return this;
2997
3208
  }
@@ -3001,40 +3212,40 @@
3001
3212
 
3002
3213
  /**
3003
3214
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
3004
- * @param {object} hierarchicalFacet
3215
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3005
3216
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
3006
3217
  */
3007
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
3218
+ _getHierarchicalFacetSortBy: function (hierarchicalFacet) {
3008
3219
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
3009
3220
  },
3010
3221
 
3011
3222
  /**
3012
3223
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
3013
3224
  * @private
3014
- * @param {object} hierarchicalFacet
3225
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3015
3226
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
3016
3227
  */
3017
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
3228
+ _getHierarchicalFacetSeparator: function (hierarchicalFacet) {
3018
3229
  return hierarchicalFacet.separator || ' > ';
3019
3230
  },
3020
3231
 
3021
3232
  /**
3022
3233
  * Helper function to get the hierarchicalFacet prefix path or null
3023
3234
  * @private
3024
- * @param {object} hierarchicalFacet
3235
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3025
3236
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
3026
3237
  */
3027
- _getHierarchicalRootPath: function(hierarchicalFacet) {
3238
+ _getHierarchicalRootPath: function (hierarchicalFacet) {
3028
3239
  return hierarchicalFacet.rootPath || null;
3029
3240
  },
3030
3241
 
3031
3242
  /**
3032
3243
  * Helper function to check if we show the parent level of the hierarchicalFacet
3033
3244
  * @private
3034
- * @param {object} hierarchicalFacet
3245
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
3035
3246
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
3036
3247
  */
3037
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
3248
+ _getHierarchicalShowParentLevel: function (hierarchicalFacet) {
3038
3249
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
3039
3250
  return hierarchicalFacet.showParentLevel;
3040
3251
  }
@@ -3043,16 +3254,13 @@
3043
3254
 
3044
3255
  /**
3045
3256
  * Helper function to get the hierarchicalFacet by it's name
3046
- * @param {string} hierarchicalFacetName
3257
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
3047
3258
  * @return {object} a hierarchicalFacet
3048
3259
  */
3049
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
3050
- return find$1(
3051
- this.hierarchicalFacets,
3052
- function(f) {
3053
- return f.name === hierarchicalFacetName;
3054
- }
3055
- );
3260
+ getHierarchicalFacetByName: function (hierarchicalFacetName) {
3261
+ return find$1(this.hierarchicalFacets, function (f) {
3262
+ return f.name === hierarchicalFacetName;
3263
+ });
3056
3264
  },
3057
3265
 
3058
3266
  /**
@@ -3060,7 +3268,7 @@
3060
3268
  * @param {string} facetName Hierarchical facet name
3061
3269
  * @return {array.<string>} the path as an array of string
3062
3270
  */
3063
- getHierarchicalFacetBreadcrumb: function(facetName) {
3271
+ getHierarchicalFacetBreadcrumb: function (facetName) {
3064
3272
  if (!this.isHierarchicalFacet(facetName)) {
3065
3273
  return [];
3066
3274
  }
@@ -3072,14 +3280,14 @@
3072
3280
  this.getHierarchicalFacetByName(facetName)
3073
3281
  );
3074
3282
  var path = refinement.split(separator);
3075
- return path.map(function(part) {
3283
+ return path.map(function (part) {
3076
3284
  return part.trim();
3077
3285
  });
3078
3286
  },
3079
3287
 
3080
- toString: function() {
3288
+ toString: function () {
3081
3289
  return JSON.stringify(this, null, 2);
3082
- }
3290
+ },
3083
3291
  };
3084
3292
 
3085
3293
  /**
@@ -3123,6 +3331,7 @@
3123
3331
  * @param {Array<object>} collection object with keys in attributes
3124
3332
  * @param {Array<string>} iteratees attributes
3125
3333
  * @param {Array<string>} orders asc | desc
3334
+ * @return {Array<object>} sorted collection
3126
3335
  */
3127
3336
  function orderBy(collection, iteratees, orders) {
3128
3337
  if (!Array.isArray(collection)) {
@@ -3133,13 +3342,13 @@
3133
3342
  orders = [];
3134
3343
  }
3135
3344
 
3136
- var result = collection.map(function(value, index) {
3345
+ var result = collection.map(function (value, index) {
3137
3346
  return {
3138
- criteria: iteratees.map(function(iteratee) {
3347
+ criteria: iteratees.map(function (iteratee) {
3139
3348
  return value[iteratee];
3140
3349
  }),
3141
3350
  index: index,
3142
- value: value
3351
+ value: value,
3143
3352
  };
3144
3353
  });
3145
3354
 
@@ -3164,7 +3373,7 @@
3164
3373
  return object.index - other.index;
3165
3374
  });
3166
3375
 
3167
- return result.map(function(res) {
3376
+ return result.map(function (res) {
3168
3377
  return res.value;
3169
3378
  });
3170
3379
  }
@@ -3200,7 +3409,7 @@
3200
3409
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
3201
3410
  */
3202
3411
  var formatSort = function formatSort(sortBy, defaults) {
3203
- var defaultInstructions = (defaults || []).map(function(sort) {
3412
+ var defaultInstructions = (defaults || []).map(function (sort) {
3204
3413
  return sort.split(':');
3205
3414
  });
3206
3415
 
@@ -3208,11 +3417,12 @@
3208
3417
  function preparePredicate(out, sort) {
3209
3418
  var sortInstruction = sort.split(':');
3210
3419
 
3211
- var matchingDefault = find$1(defaultInstructions, function(
3212
- defaultInstruction
3213
- ) {
3214
- return defaultInstruction[0] === sortInstruction[0];
3215
- });
3420
+ var matchingDefault = find$1(
3421
+ defaultInstructions,
3422
+ function (defaultInstruction) {
3423
+ return defaultInstruction[0] === sortInstruction[0];
3424
+ }
3425
+ );
3216
3426
 
3217
3427
  if (sortInstruction.length > 1 || !matchingDefault) {
3218
3428
  out[0].push(sortInstruction[0]);
@@ -3232,7 +3442,7 @@
3232
3442
  * Replaces a leading - with \-
3233
3443
  * @private
3234
3444
  * @param {any} value the facet value to replace
3235
- * @returns any
3445
+ * @returns {any} the escaped facet value or the value if it was not a string
3236
3446
  */
3237
3447
  function escapeFacetValue(value) {
3238
3448
  if (typeof value !== 'string') return value;
@@ -3244,7 +3454,7 @@
3244
3454
  * Replaces a leading \- with -
3245
3455
  * @private
3246
3456
  * @param {any} value the escaped facet value
3247
- * @returns any
3457
+ * @returns {any} the unescaped facet value or the value if it was not a string
3248
3458
  */
3249
3459
  function unescapeFacetValue$1(value) {
3250
3460
  if (typeof value !== 'string') return value;
@@ -3254,7 +3464,7 @@
3254
3464
 
3255
3465
  var escapeFacetValue_1 = {
3256
3466
  escapeFacetValue: escapeFacetValue,
3257
- unescapeFacetValue: unescapeFacetValue$1
3467
+ unescapeFacetValue: unescapeFacetValue$1,
3258
3468
  };
3259
3469
 
3260
3470
  var generateHierarchicalTree_1 = generateTrees;
@@ -3273,20 +3483,17 @@
3273
3483
  (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
3274
3484
  state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
3275
3485
  '';
3276
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
3277
- hierarchicalFacet
3278
- );
3279
- var hierarchicalRootPath = state._getHierarchicalRootPath(
3280
- hierarchicalFacet
3281
- );
3282
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
3283
- hierarchicalFacet
3284
- );
3486
+ var hierarchicalSeparator =
3487
+ state._getHierarchicalFacetSeparator(hierarchicalFacet);
3488
+ var hierarchicalRootPath =
3489
+ state._getHierarchicalRootPath(hierarchicalFacet);
3490
+ var hierarchicalShowParentLevel =
3491
+ state._getHierarchicalShowParentLevel(hierarchicalFacet);
3285
3492
  var sortBy = formatSort(
3286
3493
  state._getHierarchicalFacetSortBy(hierarchicalFacet)
3287
3494
  );
3288
3495
 
3289
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
3496
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
3290
3497
  return facetResult.exhaustive;
3291
3498
  });
3292
3499
 
@@ -3313,7 +3520,7 @@
3313
3520
  path: null, // root level, no path
3314
3521
  escapedValue: null,
3315
3522
  exhaustive: rootExhaustive,
3316
- data: null
3523
+ data: null,
3317
3524
  });
3318
3525
  };
3319
3526
  }
@@ -3342,7 +3549,7 @@
3342
3549
  * @type {object[]]} hierarchical data
3343
3550
  */
3344
3551
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
3345
- parent = find$1(data, function(subtree) {
3552
+ parent = find$1(data, function (subtree) {
3346
3553
  return subtree.isRefined;
3347
3554
  });
3348
3555
  level++;
@@ -3363,10 +3570,10 @@
3363
3570
  // showing up
3364
3571
 
3365
3572
  var picked = Object.keys(hierarchicalFacetResult.data)
3366
- .map(function(facetValue) {
3573
+ .map(function (facetValue) {
3367
3574
  return [facetValue, hierarchicalFacetResult.data[facetValue]];
3368
3575
  })
3369
- .filter(function(tuple) {
3576
+ .filter(function (tuple) {
3370
3577
  var facetValue = tuple[0];
3371
3578
  return onlyMatchingTree(
3372
3579
  facetValue,
@@ -3379,7 +3586,7 @@
3379
3586
  });
3380
3587
 
3381
3588
  parent.data = orderBy_1(
3382
- picked.map(function(tuple) {
3589
+ picked.map(function (tuple) {
3383
3590
  var facetValue = tuple[0];
3384
3591
  var facetCount = tuple[1];
3385
3592
 
@@ -3400,6 +3607,7 @@
3400
3607
  };
3401
3608
  }
3402
3609
 
3610
+ // eslint-disable-next-line max-params
3403
3611
  function onlyMatchingTree(
3404
3612
  facetValue,
3405
3613
  parentPath,
@@ -3456,7 +3664,7 @@
3456
3664
  currentRefinement === facetValue ||
3457
3665
  currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3458
3666
  exhaustive: exhaustive,
3459
- data: null
3667
+ data: null,
3460
3668
  };
3461
3669
  }
3462
3670
 
@@ -3507,12 +3715,14 @@
3507
3715
  */
3508
3716
 
3509
3717
  /**
3510
- * @param {string[]} attributes
3718
+ * Turn an array of attributes in an object of attributes with their position in the array as value
3719
+ * @param {string[]} attributes the list of attributes in the record
3720
+ * @return {object} the list of attributes indexed by attribute name
3511
3721
  */
3512
3722
  function getIndices(attributes) {
3513
3723
  var indices = {};
3514
3724
 
3515
- attributes.forEach(function(val, idx) {
3725
+ attributes.forEach(function (val, idx) {
3516
3726
  indices[val] = idx;
3517
3727
  });
3518
3728
 
@@ -3532,22 +3742,24 @@
3532
3742
  */
3533
3743
 
3534
3744
  /**
3535
- * @param {HierarchicalFacet[]} hierarchicalFacets
3536
- * @param {string} hierarchicalAttributeName
3745
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
3746
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
3747
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
3537
3748
  */
3538
3749
  function findMatchingHierarchicalFacetFromAttributeName(
3539
3750
  hierarchicalFacets,
3540
3751
  hierarchicalAttributeName
3541
3752
  ) {
3542
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
3543
- hierarchicalFacet
3544
- ) {
3545
- var facetNames = hierarchicalFacet.attributes || [];
3546
- return facetNames.indexOf(hierarchicalAttributeName) > -1;
3547
- });
3753
+ return find$1(
3754
+ hierarchicalFacets,
3755
+ function facetKeyMatchesAttribute(hierarchicalFacet) {
3756
+ var facetNames = hierarchicalFacet.attributes || [];
3757
+ return facetNames.indexOf(hierarchicalAttributeName) > -1;
3758
+ }
3759
+ );
3548
3760
  }
3549
3761
 
3550
- /*eslint-disable */
3762
+ // eslint-disable-next-line valid-jsdoc
3551
3763
  /**
3552
3764
  * Constructor for SearchResults
3553
3765
  * @class
@@ -3678,21 +3890,21 @@
3678
3890
  "index": "bestbuy"
3679
3891
  }
3680
3892
  **/
3681
- /*eslint-enable */
3682
3893
  function SearchResults(state, results, options) {
3683
3894
  var mainSubResponse = results[0];
3684
3895
 
3685
3896
  this._rawResults = results;
3686
3897
 
3898
+ // eslint-disable-next-line consistent-this
3687
3899
  var self = this;
3688
3900
 
3689
3901
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
3690
- Object.keys(mainSubResponse).forEach(function(key) {
3902
+ Object.keys(mainSubResponse).forEach(function (key) {
3691
3903
  self[key] = mainSubResponse[key];
3692
3904
  });
3693
3905
 
3694
3906
  // Make every key of the result options reachable from the instance
3695
- Object.keys(options || {}).forEach(function(key) {
3907
+ Object.keys(options || {}).forEach(function (key) {
3696
3908
  self[key] = options[key];
3697
3909
  });
3698
3910
 
@@ -3714,8 +3926,8 @@
3714
3926
  * all the records that match the search parameters. Each record is
3715
3927
  * augmented with a new attribute `_highlightResult`
3716
3928
  * which is an object keyed by attribute and with the following properties:
3717
- * - `value` : the value of the facet highlighted (html)
3718
- * - `matchLevel`: full, partial or none depending on how the query terms match
3929
+ * - `value` : the value of the facet highlighted (html)
3930
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
3719
3931
  * @name hits
3720
3932
  * @member {object[]}
3721
3933
  * @memberof SearchResults
@@ -3836,7 +4048,7 @@
3836
4048
  * @memberof SearchResults
3837
4049
  * @instance
3838
4050
  */
3839
- this.processingTimeMS = results.reduce(function(sum, result) {
4051
+ this.processingTimeMS = results.reduce(function (sum, result) {
3840
4052
  return result.processingTimeMS === undefined
3841
4053
  ? sum
3842
4054
  : sum + result.processingTimeMS;
@@ -3851,9 +4063,11 @@
3851
4063
  * disjunctive facets results
3852
4064
  * @member {SearchResults.HierarchicalFacet[]}
3853
4065
  */
3854
- this.hierarchicalFacets = state.hierarchicalFacets.map(function initFutureTree() {
3855
- return [];
3856
- });
4066
+ this.hierarchicalFacets = state.hierarchicalFacets.map(
4067
+ function initFutureTree() {
4068
+ return [];
4069
+ }
4070
+ );
3857
4071
  /**
3858
4072
  * other facets results
3859
4073
  * @member {SearchResults.Facet[]}
@@ -3871,7 +4085,7 @@
3871
4085
 
3872
4086
  var mainFacets = mainSubResponse.facets || {};
3873
4087
 
3874
- Object.keys(mainFacets).forEach(function(facetKey) {
4088
+ Object.keys(mainFacets).forEach(function (facetKey) {
3875
4089
  var facetValueObject = mainFacets[facetKey];
3876
4090
 
3877
4091
  var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
@@ -3883,13 +4097,13 @@
3883
4097
  // Place the hierarchicalFacet data at the correct index depending on
3884
4098
  // the attributes order that was defined at the helper initialization
3885
4099
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
3886
- var idxAttributeName = findIndex(state.hierarchicalFacets, function(f) {
4100
+ var idxAttributeName = findIndex(state.hierarchicalFacets, function (f) {
3887
4101
  return f.name === hierarchicalFacet.name;
3888
4102
  });
3889
4103
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
3890
4104
  attribute: facetKey,
3891
4105
  data: facetValueObject,
3892
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4106
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
3893
4107
  };
3894
4108
  } else {
3895
4109
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
@@ -3901,18 +4115,26 @@
3901
4115
  self.disjunctiveFacets[position] = {
3902
4116
  name: facetKey,
3903
4117
  data: facetValueObject,
3904
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4118
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
3905
4119
  };
3906
- assignFacetStats(self.disjunctiveFacets[position], mainSubResponse.facets_stats, facetKey);
4120
+ assignFacetStats(
4121
+ self.disjunctiveFacets[position],
4122
+ mainSubResponse.facets_stats,
4123
+ facetKey
4124
+ );
3907
4125
  }
3908
4126
  if (isFacetConjunctive) {
3909
4127
  position = facetsIndices[facetKey];
3910
4128
  self.facets[position] = {
3911
4129
  name: facetKey,
3912
4130
  data: facetValueObject,
3913
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4131
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
3914
4132
  };
3915
- assignFacetStats(self.facets[position], mainSubResponse.facets_stats, facetKey);
4133
+ assignFacetStats(
4134
+ self.facets[position],
4135
+ mainSubResponse.facets_stats,
4136
+ facetKey
4137
+ );
3916
4138
  }
3917
4139
  }
3918
4140
  });
@@ -3921,24 +4143,27 @@
3921
4143
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
3922
4144
 
3923
4145
  // aggregate the refined disjunctive facets
3924
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
4146
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
3925
4147
  var result = results[nextDisjunctiveResult];
3926
4148
  var facets = result && result.facets ? result.facets : {};
3927
4149
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
3928
4150
 
3929
4151
  // There should be only item in facets.
3930
- Object.keys(facets).forEach(function(dfacet) {
4152
+ Object.keys(facets).forEach(function (dfacet) {
3931
4153
  var facetResults = facets[dfacet];
3932
4154
 
3933
4155
  var position;
3934
4156
 
3935
4157
  if (hierarchicalFacet) {
3936
- position = findIndex(state.hierarchicalFacets, function(f) {
4158
+ position = findIndex(state.hierarchicalFacets, function (f) {
3937
4159
  return f.name === hierarchicalFacet.name;
3938
4160
  });
3939
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3940
- return f.attribute === dfacet;
3941
- });
4161
+ var attributeIndex = findIndex(
4162
+ self.hierarchicalFacets[position],
4163
+ function (f) {
4164
+ return f.attribute === dfacet;
4165
+ }
4166
+ );
3942
4167
 
3943
4168
  // previous refinements and no results so not able to find it
3944
4169
  if (attributeIndex === -1) {
@@ -3953,20 +4178,31 @@
3953
4178
  } else {
3954
4179
  position = disjunctiveFacetsIndices[dfacet];
3955
4180
 
3956
- var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
4181
+ var dataFromMainRequest =
4182
+ (mainSubResponse.facets && mainSubResponse.facets[dfacet]) || {};
3957
4183
 
3958
4184
  self.disjunctiveFacets[position] = {
3959
4185
  name: dfacet,
3960
4186
  data: defaultsPure({}, facetResults, dataFromMainRequest),
3961
- exhaustive: result.exhaustiveFacetsCount
4187
+ exhaustive: result.exhaustiveFacetsCount,
3962
4188
  };
3963
- assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
4189
+ assignFacetStats(
4190
+ self.disjunctiveFacets[position],
4191
+ result.facets_stats,
4192
+ dfacet
4193
+ );
3964
4194
 
3965
4195
  if (state.disjunctiveFacetsRefinements[dfacet]) {
3966
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
4196
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (
4197
+ refinementValue
4198
+ ) {
3967
4199
  // add the disjunctive refinements if it is no more retrieved
3968
- if (!self.disjunctiveFacets[position].data[refinementValue] &&
3969
- state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
4200
+ if (
4201
+ !self.disjunctiveFacets[position].data[refinementValue] &&
4202
+ state.disjunctiveFacetsRefinements[dfacet].indexOf(
4203
+ unescapeFacetValue$3(refinementValue)
4204
+ ) > -1
4205
+ ) {
3970
4206
  self.disjunctiveFacets[position].data[refinementValue] = 0;
3971
4207
  }
3972
4208
  });
@@ -3977,30 +4213,34 @@
3977
4213
  });
3978
4214
 
3979
4215
  // if we have some parent level values for hierarchical facets, merge them
3980
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
4216
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
3981
4217
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
3982
4218
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
3983
4219
 
3984
4220
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
3985
4221
  // if we are already at a root refinement (or no refinement at all), there is no
3986
4222
  // root level values request
3987
- if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
4223
+ if (
4224
+ currentRefinement.length === 0 ||
4225
+ currentRefinement[0].split(separator).length < 2
4226
+ ) {
3988
4227
  return;
3989
4228
  }
3990
4229
 
3991
- results.slice(nextDisjunctiveResult).forEach(function(result) {
3992
- var facets = result && result.facets
3993
- ? result.facets
3994
- : {};
4230
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
4231
+ var facets = result && result.facets ? result.facets : {};
3995
4232
 
3996
- Object.keys(facets).forEach(function(dfacet) {
4233
+ Object.keys(facets).forEach(function (dfacet) {
3997
4234
  var facetResults = facets[dfacet];
3998
- var position = findIndex(state.hierarchicalFacets, function(f) {
4235
+ var position = findIndex(state.hierarchicalFacets, function (f) {
3999
4236
  return f.name === hierarchicalFacet.name;
4000
4237
  });
4001
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
4002
- return f.attribute === dfacet;
4003
- });
4238
+ var attributeIndex = findIndex(
4239
+ self.hierarchicalFacets[position],
4240
+ function (f) {
4241
+ return f.attribute === dfacet;
4242
+ }
4243
+ );
4004
4244
 
4005
4245
  // previous refinements and no results so not able to find it
4006
4246
  if (attributeIndex === -1) {
@@ -4019,7 +4259,8 @@
4019
4259
 
4020
4260
  if (currentRefinement.length > 0) {
4021
4261
  var root = currentRefinement[0].split(separator)[0];
4022
- defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
4262
+ defaultData[root] =
4263
+ self.hierarchicalFacets[position][attributeIndex].data[root];
4023
4264
  }
4024
4265
 
4025
4266
  self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
@@ -4034,17 +4275,17 @@
4034
4275
  });
4035
4276
 
4036
4277
  // add the excludes
4037
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
4278
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
4038
4279
  var excludes = state.facetsExcludes[facetName];
4039
4280
  var position = facetsIndices[facetName];
4040
4281
 
4041
4282
  self.facets[position] = {
4042
4283
  name: facetName,
4043
4284
  data: mainFacets[facetName],
4044
- exhaustive: mainSubResponse.exhaustiveFacetsCount
4285
+ exhaustive: mainSubResponse.exhaustiveFacetsCount,
4045
4286
  };
4046
- excludes.forEach(function(facetValue) {
4047
- self.facets[position] = self.facets[position] || {name: facetName};
4287
+ excludes.forEach(function (facetValue) {
4288
+ self.facets[position] = self.facets[position] || { name: facetName };
4048
4289
  self.facets[position].data = self.facets[position].data || {};
4049
4290
  self.facets[position].data[facetValue] = 0;
4050
4291
  });
@@ -4053,7 +4294,9 @@
4053
4294
  /**
4054
4295
  * @type {Array}
4055
4296
  */
4056
- this.hierarchicalFacets = this.hierarchicalFacets.map(generateHierarchicalTree_1(state));
4297
+ this.hierarchicalFacets = this.hierarchicalFacets.map(
4298
+ generateHierarchicalTree_1(state)
4299
+ );
4057
4300
 
4058
4301
  /**
4059
4302
  * @type {Array}
@@ -4073,14 +4316,16 @@
4073
4316
  * @param {string} name name of the faceted attribute
4074
4317
  * @return {SearchResults.Facet} the facet object
4075
4318
  */
4076
- SearchResults.prototype.getFacetByName = function(name) {
4319
+ SearchResults.prototype.getFacetByName = function (name) {
4077
4320
  function predicate(facet) {
4078
4321
  return facet.name === name;
4079
4322
  }
4080
4323
 
4081
- return find$1(this.facets, predicate) ||
4324
+ return (
4325
+ find$1(this.facets, predicate) ||
4082
4326
  find$1(this.disjunctiveFacets, predicate) ||
4083
- find$1(this.hierarchicalFacets, predicate);
4327
+ find$1(this.hierarchicalFacets, predicate)
4328
+ );
4084
4329
  };
4085
4330
 
4086
4331
  /**
@@ -4099,55 +4344,70 @@
4099
4344
  var facet = find$1(results.facets, predicate);
4100
4345
  if (!facet) return [];
4101
4346
 
4102
- return Object.keys(facet.data).map(function(name) {
4347
+ return Object.keys(facet.data).map(function (name) {
4103
4348
  var value = escapeFacetValue$2(name);
4104
4349
  return {
4105
4350
  name: name,
4106
4351
  escapedValue: value,
4107
4352
  count: facet.data[name],
4108
4353
  isRefined: results._state.isFacetRefined(attribute, value),
4109
- isExcluded: results._state.isExcludeRefined(attribute, name)
4354
+ isExcluded: results._state.isExcludeRefined(attribute, name),
4110
4355
  };
4111
4356
  });
4112
4357
  } else if (results._state.isDisjunctiveFacet(attribute)) {
4113
4358
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
4114
4359
  if (!disjunctiveFacet) return [];
4115
4360
 
4116
- return Object.keys(disjunctiveFacet.data).map(function(name) {
4361
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
4117
4362
  var value = escapeFacetValue$2(name);
4118
4363
  return {
4119
4364
  name: name,
4120
4365
  escapedValue: value,
4121
4366
  count: disjunctiveFacet.data[name],
4122
- isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
4367
+ isRefined: results._state.isDisjunctiveFacetRefined(attribute, value),
4123
4368
  };
4124
4369
  });
4125
4370
  } else if (results._state.isHierarchicalFacet(attribute)) {
4126
4371
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
4127
4372
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
4128
4373
 
4129
- var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
4130
- var currentRefinementSplit = unescapeFacetValue$3(
4374
+ var hierarchicalFacet =
4375
+ results._state.getHierarchicalFacetByName(attribute);
4376
+ var separator =
4377
+ results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
4378
+ var currentRefinement = unescapeFacetValue$3(
4131
4379
  results._state.getHierarchicalRefinement(attribute)[0] || ''
4132
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
4380
+ );
4381
+
4382
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
4383
+ currentRefinement = currentRefinement.replace(
4384
+ hierarchicalFacet.rootPath + separator,
4385
+ ''
4386
+ );
4387
+ }
4388
+
4389
+ var currentRefinementSplit = currentRefinement.split(separator);
4133
4390
  currentRefinementSplit.unshift(attribute);
4134
4391
 
4135
4392
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
4136
4393
 
4137
4394
  return hierarchicalFacetValues;
4138
4395
  }
4396
+
4397
+ return undefined;
4139
4398
  }
4140
4399
 
4141
4400
  /**
4142
4401
  * Set the isRefined of a hierarchical facet result based on the current state.
4143
4402
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
4144
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
4403
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
4145
4404
  * @param {number} depth recursion depth in the currentRefinement
4405
+ * @return {undefined} function mutates the item
4146
4406
  */
4147
4407
  function setIsRefined(item, currentRefinement, depth) {
4148
4408
  item.isRefined = item.name === currentRefinement[depth];
4149
4409
  if (item.data) {
4150
- item.data.forEach(function(child) {
4410
+ item.data.forEach(function (child) {
4151
4411
  setIsRefined(child, currentRefinement, depth + 1);
4152
4412
  });
4153
4413
  }
@@ -4156,10 +4416,11 @@
4156
4416
  /**
4157
4417
  * Sort nodes of a hierarchical or disjunctive facet results
4158
4418
  * @private
4159
- * @param {function} sortFn
4419
+ * @param {function} sortFn sort function to apply
4160
4420
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
4161
4421
  * @param {string[]} names attribute names
4162
4422
  * @param {number} [level=0] current index in the names array
4423
+ * @return {HierarchicalFacet|Array} sorted node
4163
4424
  */
4164
4425
  function recSort(sortFn, node, names, level) {
4165
4426
  level = level || 0;
@@ -4172,11 +4433,11 @@
4172
4433
  return node;
4173
4434
  }
4174
4435
 
4175
- var children = node.data.map(function(childNode) {
4436
+ var children = node.data.map(function (childNode) {
4176
4437
  return recSort(sortFn, childNode, names, level + 1);
4177
4438
  });
4178
4439
  var sortedChildren = sortFn(children, names[level]);
4179
- var newNode = defaultsPure({data: sortedChildren}, node);
4440
+ var newNode = defaultsPure({ data: sortedChildren }, node);
4180
4441
  return newNode;
4181
4442
  }
4182
4443
 
@@ -4197,7 +4458,7 @@
4197
4458
  * Sorts facet arrays via their facet ordering
4198
4459
  * @param {Array} facetValues the values
4199
4460
  * @param {FacetOrdering} facetOrdering the ordering
4200
- * @returns {Array}
4461
+ * @returns {Array} the sorted facet values
4201
4462
  */
4202
4463
  function sortViaFacetOrdering(facetValues, facetOrdering) {
4203
4464
  var orderedFacets = [];
@@ -4208,12 +4469,12 @@
4208
4469
  * an object with the keys being the values in order, the values their index:
4209
4470
  * ['one', 'two'] -> { one: 0, two: 1 }
4210
4471
  */
4211
- var reverseOrder = order.reduce(function(acc, name, i) {
4472
+ var reverseOrder = order.reduce(function (acc, name, i) {
4212
4473
  acc[name] = i;
4213
4474
  return acc;
4214
4475
  }, {});
4215
4476
 
4216
- facetValues.forEach(function(item) {
4477
+ facetValues.forEach(function (item) {
4217
4478
  // hierarchical facets get sorted using their raw name
4218
4479
  var name = item.path || item.name;
4219
4480
  if (reverseOrder[name] !== undefined) {
@@ -4223,7 +4484,7 @@
4223
4484
  }
4224
4485
  });
4225
4486
 
4226
- orderedFacets = orderedFacets.filter(function(facet) {
4487
+ orderedFacets = orderedFacets.filter(function (facet) {
4227
4488
  return facet;
4228
4489
  });
4229
4490
 
@@ -4232,7 +4493,10 @@
4232
4493
  if (sortRemainingBy === 'hidden') {
4233
4494
  return orderedFacets;
4234
4495
  } else if (sortRemainingBy === 'alpha') {
4235
- ordering = [['path', 'name'], ['asc', 'asc']];
4496
+ ordering = [
4497
+ ['path', 'name'],
4498
+ ['asc', 'asc'],
4499
+ ];
4236
4500
  } else {
4237
4501
  ordering = [['count'], ['desc']];
4238
4502
  }
@@ -4245,7 +4509,7 @@
4245
4509
  /**
4246
4510
  * @param {SearchResults} results the search results class
4247
4511
  * @param {string} attribute the attribute to retrieve ordering of
4248
- * @returns {FacetOrdering=}
4512
+ * @returns {FacetOrdering | undefined} the facet ordering
4249
4513
  */
4250
4514
  function getFacetOrdering(results, attribute) {
4251
4515
  return (
@@ -4304,7 +4568,7 @@
4304
4568
  * });
4305
4569
  * });
4306
4570
  */
4307
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
4571
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
4308
4572
  var facetValues = extractNormalizedFacetValues(this, attribute);
4309
4573
  if (!facetValues) {
4310
4574
  return undefined;
@@ -4314,9 +4578,10 @@
4314
4578
  sortBy: SearchResults.DEFAULT_SORT,
4315
4579
  // if no sortBy is given, attempt to sort based on facetOrdering
4316
4580
  // if it is given, we still allow to sort via facet ordering first
4317
- facetOrdering: !(opts && opts.sortBy)
4581
+ facetOrdering: !(opts && opts.sortBy),
4318
4582
  });
4319
4583
 
4584
+ // eslint-disable-next-line consistent-this
4320
4585
  var results = this;
4321
4586
  var attributes;
4322
4587
  if (Array.isArray(facetValues)) {
@@ -4326,25 +4591,29 @@
4326
4591
  attributes = config.attributes;
4327
4592
  }
4328
4593
 
4329
- return recSort(function(data, facetName) {
4330
- if (options.facetOrdering) {
4331
- var facetOrdering = getFacetOrdering(results, facetName);
4332
- if (Boolean(facetOrdering)) {
4333
- return sortViaFacetOrdering(data, facetOrdering);
4594
+ return recSort(
4595
+ function (data, facetName) {
4596
+ if (options.facetOrdering) {
4597
+ var facetOrdering = getFacetOrdering(results, facetName);
4598
+ if (facetOrdering) {
4599
+ return sortViaFacetOrdering(data, facetOrdering);
4600
+ }
4334
4601
  }
4335
- }
4336
4602
 
4337
- if (Array.isArray(options.sortBy)) {
4338
- var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4339
- return orderBy_1(data, order[0], order[1]);
4340
- } else if (typeof options.sortBy === 'function') {
4341
- return vanillaSortFn(options.sortBy, data);
4342
- }
4343
- throw new Error(
4344
- 'options.sortBy is optional but if defined it must be ' +
4345
- 'either an array of string (predicates) or a sorting function'
4346
- );
4347
- }, facetValues, attributes);
4603
+ if (Array.isArray(options.sortBy)) {
4604
+ var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4605
+ return orderBy_1(data, order[0], order[1]);
4606
+ } else if (typeof options.sortBy === 'function') {
4607
+ return vanillaSortFn(options.sortBy, data);
4608
+ }
4609
+ throw new Error(
4610
+ 'options.sortBy is optional but if defined it must be ' +
4611
+ 'either an array of string (predicates) or a sorting function'
4612
+ );
4613
+ },
4614
+ facetValues,
4615
+ attributes
4616
+ );
4348
4617
  };
4349
4618
 
4350
4619
  /**
@@ -4353,7 +4622,7 @@
4353
4622
  * @param {string} attribute name of the faceted attribute
4354
4623
  * @return {object} The stats of the facet
4355
4624
  */
4356
- SearchResults.prototype.getFacetStats = function(attribute) {
4625
+ SearchResults.prototype.getFacetStats = function (attribute) {
4357
4626
  if (this._state.isConjunctiveFacet(attribute)) {
4358
4627
  return getFacetStatsIfAvailable(this.facets, attribute);
4359
4628
  } else if (this._state.isDisjunctiveFacet(attribute)) {
@@ -4370,10 +4639,11 @@
4370
4639
 
4371
4640
  /**
4372
4641
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
4373
- * @param {string} facetName
4642
+ * @param {string} facetName The attribute to look for
4643
+ * @return {object|undefined} The stats of the facet
4374
4644
  */
4375
4645
  function getFacetStatsIfAvailable(facetList, facetName) {
4376
- var data = find$1(facetList, function(facet) {
4646
+ var data = find$1(facetList, function (facet) {
4377
4647
  return facet.name === facetName;
4378
4648
  });
4379
4649
  return data && data.stats;
@@ -4391,53 +4661,76 @@
4391
4661
  *
4392
4662
  * @return {Array.<Refinement>} all the refinements
4393
4663
  */
4394
- SearchResults.prototype.getRefinements = function() {
4664
+ SearchResults.prototype.getRefinements = function () {
4395
4665
  var state = this._state;
4666
+ // eslint-disable-next-line consistent-this
4396
4667
  var results = this;
4397
4668
  var res = [];
4398
4669
 
4399
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
4400
- state.facetsRefinements[attributeName].forEach(function(name) {
4401
- res.push(getRefinement(state, 'facet', attributeName, name, results.facets));
4670
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
4671
+ state.facetsRefinements[attributeName].forEach(function (name) {
4672
+ res.push(
4673
+ getRefinement(state, 'facet', attributeName, name, results.facets)
4674
+ );
4402
4675
  });
4403
4676
  });
4404
4677
 
4405
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
4406
- state.facetsExcludes[attributeName].forEach(function(name) {
4407
- res.push(getRefinement(state, 'exclude', attributeName, name, results.facets));
4678
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
4679
+ state.facetsExcludes[attributeName].forEach(function (name) {
4680
+ res.push(
4681
+ getRefinement(state, 'exclude', attributeName, name, results.facets)
4682
+ );
4408
4683
  });
4409
4684
  });
4410
4685
 
4411
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
4412
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
4413
- res.push(getRefinement(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
4686
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (
4687
+ attributeName
4688
+ ) {
4689
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
4690
+ res.push(
4691
+ getRefinement(
4692
+ state,
4693
+ 'disjunctive',
4694
+ attributeName,
4695
+ name,
4696
+ results.disjunctiveFacets
4697
+ )
4698
+ );
4414
4699
  });
4415
4700
  });
4416
4701
 
4417
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
4418
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
4419
- res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
4702
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (
4703
+ attributeName
4704
+ ) {
4705
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
4706
+ res.push(
4707
+ getHierarchicalRefinement(
4708
+ state,
4709
+ attributeName,
4710
+ name,
4711
+ results.hierarchicalFacets
4712
+ )
4713
+ );
4420
4714
  });
4421
4715
  });
4422
4716
 
4423
-
4424
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
4717
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
4425
4718
  var operators = state.numericRefinements[attributeName];
4426
- Object.keys(operators).forEach(function(operator) {
4427
- operators[operator].forEach(function(value) {
4719
+ Object.keys(operators).forEach(function (operator) {
4720
+ operators[operator].forEach(function (value) {
4428
4721
  res.push({
4429
4722
  type: 'numeric',
4430
4723
  attributeName: attributeName,
4431
4724
  name: value,
4432
4725
  numericValue: value,
4433
- operator: operator
4726
+ operator: operator,
4434
4727
  });
4435
4728
  });
4436
4729
  });
4437
4730
  });
4438
4731
 
4439
- state.tagRefinements.forEach(function(name) {
4440
- res.push({type: 'tag', attributeName: '_tags', name: name});
4732
+ state.tagRefinements.forEach(function (name) {
4733
+ res.push({ type: 'tag', attributeName: '_tags', name: name });
4441
4734
  });
4442
4735
 
4443
4736
  return res;
@@ -4451,14 +4744,15 @@
4451
4744
  */
4452
4745
 
4453
4746
  /**
4454
- * @param {*} state
4455
- * @param {*} type
4456
- * @param {string} attributeName
4457
- * @param {*} name
4458
- * @param {Facet[]} resultsFacets
4747
+ * @param {SearchParameters} state the current state
4748
+ * @param {string} type the type of the refinement
4749
+ * @param {string} attributeName The attribute of the facet
4750
+ * @param {*} name The name of the facet
4751
+ * @param {Facet[]} resultsFacets facets from the results
4752
+ * @return {Refinement} the refinement
4459
4753
  */
4460
4754
  function getRefinement(state, type, attributeName, name, resultsFacets) {
4461
- var facet = find$1(resultsFacets, function(f) {
4755
+ var facet = find$1(resultsFacets, function (f) {
4462
4756
  return f.name === attributeName;
4463
4757
  });
4464
4758
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
@@ -4469,27 +4763,29 @@
4469
4763
  attributeName: attributeName,
4470
4764
  name: name,
4471
4765
  count: count,
4472
- exhaustive: exhaustive
4766
+ exhaustive: exhaustive,
4473
4767
  };
4474
4768
  }
4475
4769
 
4476
4770
  /**
4477
- * @param {*} state
4478
- * @param {string} attributeName
4479
- * @param {*} name
4480
- * @param {Facet[]} resultsFacets
4771
+ * @param {SearchParameters} state the current state
4772
+ * @param {string} attributeName the attribute of the hierarchical facet
4773
+ * @param {string} name the name of the facet
4774
+ * @param {Facet[]} resultsFacets facets from the results
4775
+ * @return {HierarchicalFacet} the hierarchical facet
4481
4776
  */
4482
4777
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
4483
4778
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
4484
4779
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
4485
4780
  var split = name.split(separator);
4486
- var rootFacet = find$1(resultsFacets, function(facet) {
4781
+ var rootFacet = find$1(resultsFacets, function (facet) {
4487
4782
  return facet.name === attributeName;
4488
4783
  });
4489
4784
 
4490
- var facet = split.reduce(function(intermediateFacet, part) {
4785
+ var facet = split.reduce(function (intermediateFacet, part) {
4491
4786
  var newFacet =
4492
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
4787
+ intermediateFacet &&
4788
+ find$1(intermediateFacet.data, function (f) {
4493
4789
  return f.name === part;
4494
4790
  });
4495
4791
  return newFacet !== undefined ? newFacet : intermediateFacet;
@@ -4504,7 +4800,7 @@
4504
4800
  attributeName: attributeName,
4505
4801
  name: path,
4506
4802
  count: count,
4507
- exhaustive: exhaustive
4803
+ exhaustive: exhaustive,
4508
4804
  };
4509
4805
  }
4510
4806
 
@@ -4819,8 +5115,8 @@
4819
5115
  value: ctor,
4820
5116
  enumerable: false,
4821
5117
  writable: true,
4822
- configurable: true
4823
- }
5118
+ configurable: true,
5119
+ },
4824
5120
  });
4825
5121
  }
4826
5122
 
@@ -4835,6 +5131,8 @@
4835
5131
  * - result: when the response is retrieved from Algolia and is processed.
4836
5132
  * This event contains a {@link SearchResults} object and the
4837
5133
  * {@link SearchParameters} corresponding to this answer.
5134
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
5135
+ * @param {function} fn the function to create the derived state
4838
5136
  */
4839
5137
  function DerivedHelper(mainHelper, fn) {
4840
5138
  this.main = mainHelper;
@@ -4849,12 +5147,12 @@
4849
5147
  * @return {undefined}
4850
5148
  * @throws Error if the derived helper is already detached
4851
5149
  */
4852
- DerivedHelper.prototype.detach = function() {
5150
+ DerivedHelper.prototype.detach = function () {
4853
5151
  this.removeAllListeners();
4854
5152
  this.main.detachDerivedHelper(this);
4855
5153
  };
4856
5154
 
4857
- DerivedHelper.prototype.getModifiedState = function(parameters) {
5155
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
4858
5156
  return this.fn(parameters);
4859
5157
  };
4860
5158
 
@@ -4862,10 +5160,10 @@
4862
5160
 
4863
5161
  function sortObject(obj) {
4864
5162
  return Object.keys(obj)
4865
- .sort(function(a, b) {
5163
+ .sort(function (a, b) {
4866
5164
  return a.localeCompare(b);
4867
5165
  })
4868
- .reduce(function(acc, curr) {
5166
+ .reduce(function (acc, curr) {
4869
5167
  acc[curr] = obj[curr];
4870
5168
  return acc;
4871
5169
  }, {});
@@ -4876,6 +5174,8 @@
4876
5174
  * Get all the queries to send to the client, those queries can used directly
4877
5175
  * with the Algolia client.
4878
5176
  * @private
5177
+ * @param {string} index The name of the index
5178
+ * @param {SearchParameters} state The state from which to get the queries
4879
5179
  * @return {object[]} The queries
4880
5180
  */
4881
5181
  _getQueries: function getQueries(index, state) {
@@ -4884,39 +5184,47 @@
4884
5184
  // One query for the hits
4885
5185
  queries.push({
4886
5186
  indexName: index,
4887
- params: requestBuilder._getHitsSearchParams(state)
5187
+ params: requestBuilder._getHitsSearchParams(state),
4888
5188
  });
4889
5189
 
4890
5190
  // One for each disjunctive facets
4891
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
5191
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
4892
5192
  queries.push({
4893
5193
  indexName: index,
4894
- params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
5194
+ params: requestBuilder._getDisjunctiveFacetSearchParams(
5195
+ state,
5196
+ refinedFacet
5197
+ ),
4895
5198
  });
4896
5199
  });
4897
5200
 
4898
5201
  // More to get the parent levels of the hierarchical facets when refined
4899
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
5202
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
4900
5203
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
4901
5204
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
4902
5205
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
4903
5206
 
4904
5207
  // If we are deeper than level 0 (starting from `beer > IPA`)
4905
5208
  // we want to get all parent values
4906
- if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
5209
+ if (
5210
+ currentRefinement.length > 0 &&
5211
+ currentRefinement[0].split(separator).length > 1
5212
+ ) {
4907
5213
  // We generate a map of the filters we will use for our facet values queries
4908
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
4909
- function createFiltersMap(map, segment, level) {
5214
+ var filtersMap = currentRefinement[0]
5215
+ .split(separator)
5216
+ .slice(0, -1)
5217
+ .reduce(function createFiltersMap(map, segment, level) {
4910
5218
  return map.concat({
4911
5219
  attribute: hierarchicalFacet.attributes[level],
4912
- value: level === 0
4913
- ? segment
4914
- : [map[map.length - 1].value, segment].join(separator)
5220
+ value:
5221
+ level === 0
5222
+ ? segment
5223
+ : [map[map.length - 1].value, segment].join(separator),
4915
5224
  });
4916
- }
4917
- , []);
5225
+ }, []);
4918
5226
 
4919
- filtersMap.forEach(function(filter, level) {
5227
+ filtersMap.forEach(function (filter, level) {
4920
5228
  var params = requestBuilder._getDisjunctiveFacetSearchParams(
4921
5229
  state,
4922
5230
  filter.attribute,
@@ -4925,37 +5233,48 @@
4925
5233
 
4926
5234
  // Keep facet filters unrelated to current hierarchical attributes
4927
5235
  function hasHierarchicalFacetFilter(value) {
4928
- return hierarchicalFacet.attributes.some(function(attribute) {
5236
+ return hierarchicalFacet.attributes.some(function (attribute) {
4929
5237
  return attribute === value.split(':')[0];
4930
5238
  });
4931
5239
  }
4932
5240
 
4933
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
4934
- if (Array.isArray(facetFilter)) {
4935
- var filtered = facetFilter.filter(function(filterValue) {
4936
- return !hasHierarchicalFacetFilter(filterValue);
4937
- });
5241
+ var filteredFacetFilters = (params.facetFilters || []).reduce(
5242
+ function (acc, facetFilter) {
5243
+ if (Array.isArray(facetFilter)) {
5244
+ var filtered = facetFilter.filter(function (filterValue) {
5245
+ return !hasHierarchicalFacetFilter(filterValue);
5246
+ });
4938
5247
 
4939
- if (filtered.length > 0) {
4940
- acc.push(filtered);
5248
+ if (filtered.length > 0) {
5249
+ acc.push(filtered);
5250
+ }
4941
5251
  }
4942
- }
4943
5252
 
4944
- if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
4945
- acc.push(facetFilter);
4946
- }
5253
+ if (
5254
+ typeof facetFilter === 'string' &&
5255
+ !hasHierarchicalFacetFilter(facetFilter)
5256
+ ) {
5257
+ acc.push(facetFilter);
5258
+ }
4947
5259
 
4948
- return acc;
4949
- }, []);
5260
+ return acc;
5261
+ },
5262
+ []
5263
+ );
4950
5264
 
4951
5265
  var parent = filtersMap[level - 1];
4952
5266
  if (level > 0) {
4953
- params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
5267
+ params.facetFilters = filteredFacetFilters.concat(
5268
+ parent.attribute + ':' + parent.value
5269
+ );
4954
5270
  } else {
4955
- params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
5271
+ params.facetFilters =
5272
+ filteredFacetFilters.length > 0
5273
+ ? filteredFacetFilters
5274
+ : undefined;
4956
5275
  }
4957
5276
 
4958
- queries.push({indexName: index, params: params});
5277
+ queries.push({ indexName: index, params: params });
4959
5278
  });
4960
5279
  }
4961
5280
  });
@@ -4966,20 +5285,20 @@
4966
5285
  /**
4967
5286
  * Build search parameters used to fetch hits
4968
5287
  * @private
4969
- * @return {object.<string, any>}
5288
+ * @param {SearchParameters} state The state from which to get the queries
5289
+ * @return {object.<string, any>} The search parameters for hits
4970
5290
  */
4971
- _getHitsSearchParams: function(state) {
5291
+ _getHitsSearchParams: function (state) {
4972
5292
  var facets = state.facets
4973
5293
  .concat(state.disjunctiveFacets)
4974
5294
  .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
4975
5295
 
4976
-
4977
5296
  var facetFilters = requestBuilder._getFacetFilters(state);
4978
5297
  var numericFilters = requestBuilder._getNumericFilters(state);
4979
5298
  var tagFilters = requestBuilder._getTagFilters(state);
4980
5299
  var additionalParams = {
4981
5300
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
4982
- tagFilters: tagFilters
5301
+ tagFilters: tagFilters,
4983
5302
  };
4984
5303
 
4985
5304
  if (facetFilters.length > 0) {
@@ -4996,19 +5315,28 @@
4996
5315
  /**
4997
5316
  * Build search parameters used to fetch a disjunctive facet
4998
5317
  * @private
5318
+ * @param {SearchParameters} state The state from which to get the queries
4999
5319
  * @param {string} facet the associated facet name
5000
5320
  * @param {boolean} hierarchicalRootLevel ?? FIXME
5001
- * @return {object}
5321
+ * @return {object} The search parameters for a disjunctive facet
5002
5322
  */
5003
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
5004
- var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
5323
+ _getDisjunctiveFacetSearchParams: function (
5324
+ state,
5325
+ facet,
5326
+ hierarchicalRootLevel
5327
+ ) {
5328
+ var facetFilters = requestBuilder._getFacetFilters(
5329
+ state,
5330
+ facet,
5331
+ hierarchicalRootLevel
5332
+ );
5005
5333
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
5006
5334
  var tagFilters = requestBuilder._getTagFilters(state);
5007
5335
  var additionalParams = {
5008
5336
  hitsPerPage: 0,
5009
5337
  page: 0,
5010
5338
  analytics: false,
5011
- clickAnalytics: false
5339
+ clickAnalytics: false,
5012
5340
  };
5013
5341
 
5014
5342
  if (tagFilters.length > 0) {
@@ -5018,11 +5346,12 @@
5018
5346
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
5019
5347
 
5020
5348
  if (hierarchicalFacet) {
5021
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
5022
- state,
5023
- hierarchicalFacet,
5024
- hierarchicalRootLevel
5025
- );
5349
+ additionalParams.facets =
5350
+ requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
5351
+ state,
5352
+ hierarchicalFacet,
5353
+ hierarchicalRootLevel
5354
+ );
5026
5355
  } else {
5027
5356
  additionalParams.facets = facet;
5028
5357
  }
@@ -5041,24 +5370,25 @@
5041
5370
  /**
5042
5371
  * Return the numeric filters in an algolia request fashion
5043
5372
  * @private
5373
+ * @param {SearchParameters} state the state from which to get the filters
5044
5374
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
5045
5375
  * @return {string[]} the numeric filters in the algolia format
5046
5376
  */
5047
- _getNumericFilters: function(state, facetName) {
5377
+ _getNumericFilters: function (state, facetName) {
5048
5378
  if (state.numericFilters) {
5049
5379
  return state.numericFilters;
5050
5380
  }
5051
5381
 
5052
5382
  var numericFilters = [];
5053
5383
 
5054
- Object.keys(state.numericRefinements).forEach(function(attribute) {
5384
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
5055
5385
  var operators = state.numericRefinements[attribute] || {};
5056
- Object.keys(operators).forEach(function(operator) {
5386
+ Object.keys(operators).forEach(function (operator) {
5057
5387
  var values = operators[operator] || [];
5058
5388
  if (facetName !== attribute) {
5059
- values.forEach(function(value) {
5389
+ values.forEach(function (value) {
5060
5390
  if (Array.isArray(value)) {
5061
- var vs = value.map(function(v) {
5391
+ var vs = value.map(function (v) {
5062
5392
  return attribute + operator + v;
5063
5393
  });
5064
5394
  numericFilters.push(vs);
@@ -5074,11 +5404,12 @@
5074
5404
  },
5075
5405
 
5076
5406
  /**
5077
- * Return the tags filters depending
5407
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
5078
5408
  * @private
5079
- * @return {string}
5409
+ * @param {SearchParameters} state the state from which to get the filters
5410
+ * @return {string} Tag filters in a single string
5080
5411
  */
5081
- _getTagFilters: function(state) {
5412
+ _getTagFilters: function (state) {
5082
5413
  if (state.tagFilters) {
5083
5414
  return state.tagFilters;
5084
5415
  }
@@ -5086,50 +5417,52 @@
5086
5417
  return state.tagRefinements.join(',');
5087
5418
  },
5088
5419
 
5089
-
5090
5420
  /**
5091
5421
  * Build facetFilters parameter based on current refinements. The array returned
5092
5422
  * contains strings representing the facet filters in the algolia format.
5093
5423
  * @private
5424
+ * @param {SearchParameters} state The state from which to get the queries
5094
5425
  * @param {string} [facet] if set, the current disjunctive facet
5095
- * @return {array.<string>}
5426
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
5427
+ * @return {array.<string>} The facet filters in the algolia format
5096
5428
  */
5097
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
5429
+ _getFacetFilters: function (state, facet, hierarchicalRootLevel) {
5098
5430
  var facetFilters = [];
5099
5431
 
5100
5432
  var facetsRefinements = state.facetsRefinements || {};
5101
- Object.keys(facetsRefinements).forEach(function(facetName) {
5433
+ Object.keys(facetsRefinements).forEach(function (facetName) {
5102
5434
  var facetValues = facetsRefinements[facetName] || [];
5103
- facetValues.forEach(function(facetValue) {
5435
+ facetValues.forEach(function (facetValue) {
5104
5436
  facetFilters.push(facetName + ':' + facetValue);
5105
5437
  });
5106
5438
  });
5107
5439
 
5108
5440
  var facetsExcludes = state.facetsExcludes || {};
5109
- Object.keys(facetsExcludes).forEach(function(facetName) {
5441
+ Object.keys(facetsExcludes).forEach(function (facetName) {
5110
5442
  var facetValues = facetsExcludes[facetName] || [];
5111
- facetValues.forEach(function(facetValue) {
5443
+ facetValues.forEach(function (facetValue) {
5112
5444
  facetFilters.push(facetName + ':-' + facetValue);
5113
5445
  });
5114
5446
  });
5115
5447
 
5116
5448
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
5117
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
5449
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
5118
5450
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
5119
5451
  if (facetName === facet || !facetValues || facetValues.length === 0) {
5120
5452
  return;
5121
5453
  }
5122
5454
  var orFilters = [];
5123
5455
 
5124
- facetValues.forEach(function(facetValue) {
5456
+ facetValues.forEach(function (facetValue) {
5125
5457
  orFilters.push(facetName + ':' + facetValue);
5126
5458
  });
5127
5459
 
5128
5460
  facetFilters.push(orFilters);
5129
5461
  });
5130
5462
 
5131
- var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
5132
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
5463
+ var hierarchicalFacetsRefinements =
5464
+ state.hierarchicalFacetsRefinements || {};
5465
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
5133
5466
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
5134
5467
  var facetValue = facetValues[0];
5135
5468
 
@@ -5147,8 +5480,13 @@
5147
5480
  if (facet === facetName) {
5148
5481
  // if we are at the root level already, no need to ask for facet values, we get them from
5149
5482
  // the hits query
5150
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
5151
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
5483
+ if (
5484
+ facetValue.indexOf(separator) === -1 ||
5485
+ (!rootPath && hierarchicalRootLevel === true) ||
5486
+ (rootPath &&
5487
+ rootPath.split(separator).length ===
5488
+ facetValue.split(separator).length)
5489
+ ) {
5152
5490
  return;
5153
5491
  }
5154
5492
 
@@ -5175,13 +5513,18 @@
5175
5513
  return facetFilters;
5176
5514
  },
5177
5515
 
5178
- _getHitsHierarchicalFacetsAttributes: function(state) {
5516
+ _getHitsHierarchicalFacetsAttributes: function (state) {
5179
5517
  var out = [];
5180
5518
 
5181
5519
  return state.hierarchicalFacets.reduce(
5182
5520
  // ask for as much levels as there's hierarchical refinements
5183
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
5184
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
5521
+ function getHitsAttributesForHierarchicalFacet(
5522
+ allAttributes,
5523
+ hierarchicalFacet
5524
+ ) {
5525
+ var hierarchicalRefinement = state.getHierarchicalRefinement(
5526
+ hierarchicalFacet.name
5527
+ )[0];
5185
5528
 
5186
5529
  // if no refinement, ask for root level
5187
5530
  if (!hierarchicalRefinement) {
@@ -5194,10 +5537,16 @@
5194
5537
  var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
5195
5538
 
5196
5539
  return allAttributes.concat(newAttributes);
5197
- }, out);
5540
+ },
5541
+ out
5542
+ );
5198
5543
  },
5199
5544
 
5200
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
5545
+ _getDisjunctiveHierarchicalFacetAttribute: function (
5546
+ state,
5547
+ hierarchicalFacet,
5548
+ rootLevel
5549
+ ) {
5201
5550
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5202
5551
  if (rootLevel === true) {
5203
5552
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -5209,7 +5558,8 @@
5209
5558
  return [hierarchicalFacet.attributes[attributeIndex]];
5210
5559
  }
5211
5560
 
5212
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5561
+ var hierarchicalRefinement =
5562
+ state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5213
5563
  // if refinement is 'beers > IPA > Flying dog',
5214
5564
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
5215
5565
 
@@ -5217,28 +5567,30 @@
5217
5567
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
5218
5568
  },
5219
5569
 
5220
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
5221
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
5222
- state.clearRefinements(facetName) :
5223
- state;
5570
+ getSearchForFacetQuery: function (facetName, query, maxFacetHits, state) {
5571
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName)
5572
+ ? state.clearRefinements(facetName)
5573
+ : state;
5224
5574
  var searchForFacetSearchParameters = {
5225
5575
  facetQuery: query,
5226
- facetName: facetName
5576
+ facetName: facetName,
5227
5577
  };
5228
5578
  if (typeof maxFacetHits === 'number') {
5229
5579
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
5230
5580
  }
5231
- return sortObject(merge_1(
5232
- {},
5233
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5234
- searchForFacetSearchParameters
5235
- ));
5236
- }
5581
+ return sortObject(
5582
+ merge_1(
5583
+ {},
5584
+ requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5585
+ searchForFacetSearchParameters
5586
+ )
5587
+ );
5588
+ },
5237
5589
  };
5238
5590
 
5239
5591
  var requestBuilder_1 = requestBuilder;
5240
5592
 
5241
- var version = '3.13.2';
5593
+ var version = '3.13.5';
5242
5594
 
5243
5595
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
5244
5596
 
@@ -5368,19 +5720,19 @@
5368
5720
  * method is called, it triggers a `search` event. The results will
5369
5721
  * be available through the `result` event. If an error occurs, an
5370
5722
  * `error` will be fired instead.
5371
- * @return {AlgoliaSearchHelper}
5723
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5372
5724
  * @fires search
5373
5725
  * @fires result
5374
5726
  * @fires error
5375
5727
  * @chainable
5376
5728
  */
5377
- AlgoliaSearchHelper.prototype.search = function() {
5378
- this._search({onlyWithDerivedHelpers: false});
5729
+ AlgoliaSearchHelper.prototype.search = function () {
5730
+ this._search({ onlyWithDerivedHelpers: false });
5379
5731
  return this;
5380
5732
  };
5381
5733
 
5382
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
5383
- this._search({onlyWithDerivedHelpers: true});
5734
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
5735
+ this._search({ onlyWithDerivedHelpers: true });
5384
5736
  return this;
5385
5737
  };
5386
5738
 
@@ -5389,7 +5741,7 @@
5389
5741
  * for the hits
5390
5742
  * @return {object} Query Parameters
5391
5743
  */
5392
- AlgoliaSearchHelper.prototype.getQuery = function() {
5744
+ AlgoliaSearchHelper.prototype.getQuery = function () {
5393
5745
  var state = this.state;
5394
5746
  return requestBuilder_1._getHitsSearchParams(state);
5395
5747
  };
@@ -5401,7 +5753,7 @@
5401
5753
  * same as a search call before calling searchOnce.
5402
5754
  * @param {object} options can contain all the parameters that can be set to SearchParameters
5403
5755
  * plus the index
5404
- * @param {function} [callback] optional callback executed when the response from the
5756
+ * @param {function} [cb] optional callback executed when the response from the
5405
5757
  * server is back.
5406
5758
  * @return {promise|undefined} if a callback is passed the method returns undefined
5407
5759
  * otherwise it returns a promise containing an object with two keys :
@@ -5430,21 +5782,24 @@
5430
5782
  * // }
5431
5783
  * }
5432
5784
  */
5433
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
5434
- var tempState = !options ? this.state : this.state.setQueryParameters(options);
5785
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
5786
+ var tempState = !options
5787
+ ? this.state
5788
+ : this.state.setQueryParameters(options);
5435
5789
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
5790
+ // eslint-disable-next-line consistent-this
5436
5791
  var self = this;
5437
5792
 
5438
5793
  this._currentNbQueries++;
5439
5794
 
5440
5795
  this.emit('searchOnce', {
5441
- state: tempState
5796
+ state: tempState,
5442
5797
  });
5443
5798
 
5444
5799
  if (cb) {
5445
5800
  this.client
5446
5801
  .search(queries)
5447
- .then(function(content) {
5802
+ .then(function (content) {
5448
5803
  self._currentNbQueries--;
5449
5804
  if (self._currentNbQueries === 0) {
5450
5805
  self.emit('searchQueueEmpty');
@@ -5452,7 +5807,7 @@
5452
5807
 
5453
5808
  cb(null, new SearchResults_1(tempState, content.results), tempState);
5454
5809
  })
5455
- .catch(function(err) {
5810
+ .catch(function (err) {
5456
5811
  self._currentNbQueries--;
5457
5812
  if (self._currentNbQueries === 0) {
5458
5813
  self.emit('searchQueueEmpty');
@@ -5464,22 +5819,25 @@
5464
5819
  return undefined;
5465
5820
  }
5466
5821
 
5467
- return this.client.search(queries).then(function(content) {
5468
- self._currentNbQueries--;
5469
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5470
- return {
5471
- content: new SearchResults_1(tempState, content.results),
5472
- state: tempState,
5473
- _originalResponse: content
5474
- };
5475
- }, function(e) {
5476
- self._currentNbQueries--;
5477
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5478
- throw e;
5479
- });
5822
+ return this.client.search(queries).then(
5823
+ function (content) {
5824
+ self._currentNbQueries--;
5825
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5826
+ return {
5827
+ content: new SearchResults_1(tempState, content.results),
5828
+ state: tempState,
5829
+ _originalResponse: content,
5830
+ };
5831
+ },
5832
+ function (e) {
5833
+ self._currentNbQueries--;
5834
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5835
+ throw e;
5836
+ }
5837
+ );
5480
5838
  };
5481
5839
 
5482
- /**
5840
+ /**
5483
5841
  * Start the search for answers with the parameters set in the state.
5484
5842
  * This method returns a promise.
5485
5843
  * @param {Object} options - the options for answers API call
@@ -5490,7 +5848,8 @@
5490
5848
  * @return {promise} the answer results
5491
5849
  * @deprecated answers is deprecated and will be replaced with new initiatives
5492
5850
  */
5493
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
5851
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
5852
+ // eslint-disable-next-line no-console
5494
5853
  console.warn('[algoliasearch-helper] answers is no longer supported');
5495
5854
  var state = this.state;
5496
5855
  var derivedHelper = this.derivedHelpers[0];
@@ -5501,19 +5860,20 @@
5501
5860
  var data = merge_1(
5502
5861
  {
5503
5862
  attributesForPrediction: options.attributesForPrediction,
5504
- nbHits: options.nbHits
5863
+ nbHits: options.nbHits,
5505
5864
  },
5506
5865
  {
5507
5866
  params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
5508
5867
  'attributesToSnippet',
5509
5868
  'hitsPerPage',
5510
5869
  'restrictSearchableAttributes',
5511
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
5512
- ])
5870
+ 'snippetEllipsisText',
5871
+ ]),
5513
5872
  }
5514
5873
  );
5515
5874
 
5516
- var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
5875
+ var errorMessage =
5876
+ 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
5517
5877
  if (typeof this.client.initIndex !== 'function') {
5518
5878
  throw new Error(errorMessage);
5519
5879
  }
@@ -5558,7 +5918,12 @@
5558
5918
  * it in the generated query.
5559
5919
  * @return {promise.<FacetSearchResult>} the results of the search
5560
5920
  */
5561
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
5921
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
5922
+ facet,
5923
+ query,
5924
+ maxFacetHits,
5925
+ userState
5926
+ ) {
5562
5927
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
5563
5928
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
5564
5929
  if (
@@ -5573,15 +5938,21 @@
5573
5938
 
5574
5939
  var state = this.state.setQueryParameters(userState || {});
5575
5940
  var isDisjunctive = state.isDisjunctiveFacet(facet);
5576
- var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
5941
+ var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(
5942
+ facet,
5943
+ query,
5944
+ maxFacetHits,
5945
+ state
5946
+ );
5577
5947
 
5578
5948
  this._currentNbQueries++;
5949
+ // eslint-disable-next-line consistent-this
5579
5950
  var self = this;
5580
5951
  var searchForFacetValuesPromise;
5581
5952
  // newer algoliasearch ^3.27.1 - ~4.0.0
5582
5953
  if (clientHasSFFV) {
5583
5954
  searchForFacetValuesPromise = this.client.searchForFacetValues([
5584
- {indexName: state.index, params: algoliaQuery}
5955
+ { indexName: state.index, params: algoliaQuery },
5585
5956
  ]);
5586
5957
  // algoliasearch < 3.27.1
5587
5958
  } else if (clientHasInitIndex) {
@@ -5598,8 +5969,8 @@
5598
5969
  type: 'facet',
5599
5970
  facet: facet,
5600
5971
  indexName: state.index,
5601
- params: algoliaQuery
5602
- }
5972
+ params: algoliaQuery,
5973
+ },
5603
5974
  ])
5604
5975
  .then(function processResponse(response) {
5605
5976
  return response.results[0];
@@ -5609,28 +5980,31 @@
5609
5980
  this.emit('searchForFacetValues', {
5610
5981
  state: state,
5611
5982
  facet: facet,
5612
- query: query
5983
+ query: query,
5613
5984
  });
5614
5985
 
5615
- return searchForFacetValuesPromise.then(function addIsRefined(content) {
5616
- self._currentNbQueries--;
5617
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5986
+ return searchForFacetValuesPromise.then(
5987
+ function addIsRefined(content) {
5988
+ self._currentNbQueries--;
5989
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5618
5990
 
5619
- content = Array.isArray(content) ? content[0] : content;
5991
+ content = Array.isArray(content) ? content[0] : content;
5620
5992
 
5621
- content.facetHits.forEach(function(f) {
5622
- f.escapedValue = escapeFacetValue$3(f.value);
5623
- f.isRefined = isDisjunctive
5624
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
5625
- : state.isFacetRefined(facet, f.escapedValue);
5626
- });
5993
+ content.facetHits.forEach(function (f) {
5994
+ f.escapedValue = escapeFacetValue$3(f.value);
5995
+ f.isRefined = isDisjunctive
5996
+ ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
5997
+ : state.isFacetRefined(facet, f.escapedValue);
5998
+ });
5627
5999
 
5628
- return content;
5629
- }, function(e) {
5630
- self._currentNbQueries--;
5631
- if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5632
- throw e;
5633
- });
6000
+ return content;
6001
+ },
6002
+ function (e) {
6003
+ self._currentNbQueries--;
6004
+ if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
6005
+ throw e;
6006
+ }
6007
+ );
5634
6008
  };
5635
6009
 
5636
6010
  /**
@@ -5638,14 +6012,14 @@
5638
6012
  *
5639
6013
  * This method resets the current page to 0.
5640
6014
  * @param {string} q the user query
5641
- * @return {AlgoliaSearchHelper}
6015
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5642
6016
  * @fires change
5643
6017
  * @chainable
5644
6018
  */
5645
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
6019
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
5646
6020
  this._change({
5647
6021
  state: this.state.resetPage().setQuery(q),
5648
- isPageReset: true
6022
+ isPageReset: true,
5649
6023
  });
5650
6024
 
5651
6025
  return this;
@@ -5659,7 +6033,7 @@
5659
6033
  *
5660
6034
  * This method resets the current page to 0.
5661
6035
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
5662
- * @return {AlgoliaSearchHelper}
6036
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5663
6037
  * @fires change
5664
6038
  * @chainable
5665
6039
  * @example
@@ -5674,10 +6048,10 @@
5674
6048
  * return type === 'exclude' && attribute === 'category';
5675
6049
  * }).search();
5676
6050
  */
5677
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
6051
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
5678
6052
  this._change({
5679
6053
  state: this.state.resetPage().clearRefinements(name),
5680
- isPageReset: true
6054
+ isPageReset: true,
5681
6055
  });
5682
6056
 
5683
6057
  return this;
@@ -5687,14 +6061,14 @@
5687
6061
  * Remove all the tag filters.
5688
6062
  *
5689
6063
  * This method resets the current page to 0.
5690
- * @return {AlgoliaSearchHelper}
6064
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5691
6065
  * @fires change
5692
6066
  * @chainable
5693
6067
  */
5694
- AlgoliaSearchHelper.prototype.clearTags = function() {
6068
+ AlgoliaSearchHelper.prototype.clearTags = function () {
5695
6069
  this._change({
5696
6070
  state: this.state.resetPage().clearTags(),
5697
- isPageReset: true
6071
+ isPageReset: true,
5698
6072
  });
5699
6073
 
5700
6074
  return this;
@@ -5707,23 +6081,27 @@
5707
6081
  * This method resets the current page to 0.
5708
6082
  * @param {string} facet the facet to refine
5709
6083
  * @param {string} value the associated value (will be converted to string)
5710
- * @return {AlgoliaSearchHelper}
6084
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5711
6085
  * @fires change
5712
6086
  * @chainable
5713
6087
  */
5714
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
6088
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (
6089
+ facet,
6090
+ value
6091
+ ) {
5715
6092
  this._change({
5716
6093
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
5717
- isPageReset: true
6094
+ isPageReset: true,
5718
6095
  });
5719
6096
 
5720
6097
  return this;
5721
6098
  };
5722
6099
 
6100
+ // eslint-disable-next-line valid-jsdoc
5723
6101
  /**
5724
6102
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
5725
6103
  */
5726
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
6104
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
5727
6105
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
5728
6106
  };
5729
6107
 
@@ -5735,15 +6113,18 @@
5735
6113
  * This method resets the current page to 0.
5736
6114
  * @param {string} facet the facet name
5737
6115
  * @param {string} path the hierarchical facet path
5738
- * @return {AlgoliaSearchHelper}
6116
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5739
6117
  * @throws Error if the facet is not defined or if the facet is refined
5740
6118
  * @chainable
5741
6119
  * @fires change
5742
6120
  */
5743
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
6121
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (
6122
+ facet,
6123
+ path
6124
+ ) {
5744
6125
  this._change({
5745
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
5746
- isPageReset: true
6126
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
6127
+ isPageReset: true,
5747
6128
  });
5748
6129
 
5749
6130
  return this;
@@ -5757,14 +6138,20 @@
5757
6138
  * @param {string} attribute the attribute on which the numeric filter applies
5758
6139
  * @param {string} operator the operator of the filter
5759
6140
  * @param {number} value the value of the filter
5760
- * @return {AlgoliaSearchHelper}
6141
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5761
6142
  * @fires change
5762
6143
  * @chainable
5763
6144
  */
5764
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
6145
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (
6146
+ attribute,
6147
+ operator,
6148
+ value
6149
+ ) {
5765
6150
  this._change({
5766
- state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
5767
- isPageReset: true
6151
+ state: this.state
6152
+ .resetPage()
6153
+ .addNumericRefinement(attribute, operator, value),
6154
+ isPageReset: true,
5768
6155
  });
5769
6156
 
5770
6157
  return this;
@@ -5777,27 +6164,27 @@
5777
6164
  * This method resets the current page to 0.
5778
6165
  * @param {string} facet the facet to refine
5779
6166
  * @param {string} value the associated value (will be converted to string)
5780
- * @return {AlgoliaSearchHelper}
6167
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5781
6168
  * @fires change
5782
6169
  * @chainable
5783
6170
  */
5784
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
6171
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
5785
6172
  this._change({
5786
6173
  state: this.state.resetPage().addFacetRefinement(facet, value),
5787
- isPageReset: true
6174
+ isPageReset: true,
5788
6175
  });
5789
6176
 
5790
6177
  return this;
5791
6178
  };
5792
6179
 
6180
+ // eslint-disable-next-line valid-jsdoc
5793
6181
  /**
5794
6182
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
5795
6183
  */
5796
- AlgoliaSearchHelper.prototype.addRefine = function() {
6184
+ AlgoliaSearchHelper.prototype.addRefine = function () {
5797
6185
  return this.addFacetRefinement.apply(this, arguments);
5798
6186
  };
5799
6187
 
5800
-
5801
6188
  /**
5802
6189
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
5803
6190
  * filter is already set, it doesn't change the filters.
@@ -5805,23 +6192,24 @@
5805
6192
  * This method resets the current page to 0.
5806
6193
  * @param {string} facet the facet to refine
5807
6194
  * @param {string} value the associated value (will be converted to string)
5808
- * @return {AlgoliaSearchHelper}
6195
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5809
6196
  * @fires change
5810
6197
  * @chainable
5811
6198
  */
5812
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
6199
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
5813
6200
  this._change({
5814
6201
  state: this.state.resetPage().addExcludeRefinement(facet, value),
5815
- isPageReset: true
6202
+ isPageReset: true,
5816
6203
  });
5817
6204
 
5818
6205
  return this;
5819
6206
  };
5820
6207
 
6208
+ // eslint-disable-next-line valid-jsdoc
5821
6209
  /**
5822
6210
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
5823
6211
  */
5824
- AlgoliaSearchHelper.prototype.addExclude = function() {
6212
+ AlgoliaSearchHelper.prototype.addExclude = function () {
5825
6213
  return this.addFacetExclusion.apply(this, arguments);
5826
6214
  };
5827
6215
 
@@ -5831,14 +6219,14 @@
5831
6219
  *
5832
6220
  * This method resets the current page to 0.
5833
6221
  * @param {string} tag the tag to add to the filter
5834
- * @return {AlgoliaSearchHelper}
6222
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5835
6223
  * @fires change
5836
6224
  * @chainable
5837
6225
  */
5838
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
6226
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
5839
6227
  this._change({
5840
6228
  state: this.state.resetPage().addTagRefinement(tag),
5841
- isPageReset: true
6229
+ isPageReset: true,
5842
6230
  });
5843
6231
 
5844
6232
  return this;
@@ -5858,14 +6246,20 @@
5858
6246
  * @param {string} attribute the attribute on which the numeric filter applies
5859
6247
  * @param {string} [operator] the operator of the filter
5860
6248
  * @param {number} [value] the value of the filter
5861
- * @return {AlgoliaSearchHelper}
6249
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5862
6250
  * @fires change
5863
6251
  * @chainable
5864
6252
  */
5865
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
6253
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (
6254
+ attribute,
6255
+ operator,
6256
+ value
6257
+ ) {
5866
6258
  this._change({
5867
- state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
5868
- isPageReset: true
6259
+ state: this.state
6260
+ .resetPage()
6261
+ .removeNumericRefinement(attribute, operator, value),
6262
+ isPageReset: true,
5869
6263
  });
5870
6264
 
5871
6265
  return this;
@@ -5881,38 +6275,46 @@
5881
6275
  * This method resets the current page to 0.
5882
6276
  * @param {string} facet the facet to refine
5883
6277
  * @param {string} [value] the associated value
5884
- * @return {AlgoliaSearchHelper}
6278
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5885
6279
  * @fires change
5886
6280
  * @chainable
5887
6281
  */
5888
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
6282
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (
6283
+ facet,
6284
+ value
6285
+ ) {
5889
6286
  this._change({
5890
- state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
5891
- isPageReset: true
6287
+ state: this.state
6288
+ .resetPage()
6289
+ .removeDisjunctiveFacetRefinement(facet, value),
6290
+ isPageReset: true,
5892
6291
  });
5893
6292
 
5894
6293
  return this;
5895
6294
  };
5896
6295
 
6296
+ // eslint-disable-next-line valid-jsdoc
5897
6297
  /**
5898
6298
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
5899
6299
  */
5900
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
6300
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
5901
6301
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
5902
6302
  };
5903
6303
 
5904
6304
  /**
5905
6305
  * Removes the refinement set on a hierarchical facet.
5906
6306
  * @param {string} facet the facet name
5907
- * @return {AlgoliaSearchHelper}
6307
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5908
6308
  * @throws Error if the facet is not defined or if the facet is not refined
5909
6309
  * @fires change
5910
6310
  * @chainable
5911
6311
  */
5912
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
6312
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (
6313
+ facet
6314
+ ) {
5913
6315
  this._change({
5914
6316
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
5915
- isPageReset: true
6317
+ isPageReset: true,
5916
6318
  });
5917
6319
 
5918
6320
  return this;
@@ -5928,23 +6330,24 @@
5928
6330
  * This method resets the current page to 0.
5929
6331
  * @param {string} facet the facet to refine
5930
6332
  * @param {string} [value] the associated value
5931
- * @return {AlgoliaSearchHelper}
6333
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5932
6334
  * @fires change
5933
6335
  * @chainable
5934
6336
  */
5935
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
6337
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
5936
6338
  this._change({
5937
6339
  state: this.state.resetPage().removeFacetRefinement(facet, value),
5938
- isPageReset: true
6340
+ isPageReset: true,
5939
6341
  });
5940
6342
 
5941
6343
  return this;
5942
6344
  };
5943
6345
 
6346
+ // eslint-disable-next-line valid-jsdoc
5944
6347
  /**
5945
6348
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
5946
6349
  */
5947
- AlgoliaSearchHelper.prototype.removeRefine = function() {
6350
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
5948
6351
  return this.removeFacetRefinement.apply(this, arguments);
5949
6352
  };
5950
6353
 
@@ -5958,23 +6361,24 @@
5958
6361
  * This method resets the current page to 0.
5959
6362
  * @param {string} facet the facet to refine
5960
6363
  * @param {string} [value] the associated value
5961
- * @return {AlgoliaSearchHelper}
6364
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5962
6365
  * @fires change
5963
6366
  * @chainable
5964
6367
  */
5965
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
6368
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
5966
6369
  this._change({
5967
6370
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
5968
- isPageReset: true
6371
+ isPageReset: true,
5969
6372
  });
5970
6373
 
5971
6374
  return this;
5972
6375
  };
5973
6376
 
6377
+ // eslint-disable-next-line valid-jsdoc
5974
6378
  /**
5975
6379
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
5976
6380
  */
5977
- AlgoliaSearchHelper.prototype.removeExclude = function() {
6381
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
5978
6382
  return this.removeFacetExclusion.apply(this, arguments);
5979
6383
  };
5980
6384
 
@@ -5984,14 +6388,14 @@
5984
6388
  *
5985
6389
  * This method resets the current page to 0.
5986
6390
  * @param {string} tag tag to remove from the filter
5987
- * @return {AlgoliaSearchHelper}
6391
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5988
6392
  * @fires change
5989
6393
  * @chainable
5990
6394
  */
5991
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
6395
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
5992
6396
  this._change({
5993
6397
  state: this.state.resetPage().removeTagRefinement(tag),
5994
- isPageReset: true
6398
+ isPageReset: true,
5995
6399
  });
5996
6400
 
5997
6401
  return this;
@@ -6004,23 +6408,24 @@
6004
6408
  * This method resets the current page to 0.
6005
6409
  * @param {string} facet the facet to refine
6006
6410
  * @param {string} value the associated value
6007
- * @return {AlgoliaSearchHelper}
6411
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6008
6412
  * @fires change
6009
6413
  * @chainable
6010
6414
  */
6011
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
6415
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
6012
6416
  this._change({
6013
6417
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
6014
- isPageReset: true
6418
+ isPageReset: true,
6015
6419
  });
6016
6420
 
6017
6421
  return this;
6018
6422
  };
6019
6423
 
6424
+ // eslint-disable-next-line valid-jsdoc
6020
6425
  /**
6021
6426
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
6022
6427
  */
6023
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
6428
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
6024
6429
  return this.toggleFacetExclusion.apply(this, arguments);
6025
6430
  };
6026
6431
 
@@ -6033,13 +6438,13 @@
6033
6438
  * This method resets the current page to 0.
6034
6439
  * @param {string} facet the facet to refine
6035
6440
  * @param {string} value the associated value
6036
- * @return {AlgoliaSearchHelper}
6441
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6037
6442
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
6038
6443
  * @fires change
6039
6444
  * @chainable
6040
6445
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6041
6446
  */
6042
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
6447
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
6043
6448
  return this.toggleFacetRefinement(facet, value);
6044
6449
  };
6045
6450
 
@@ -6052,24 +6457,25 @@
6052
6457
  * This method resets the current page to 0.
6053
6458
  * @param {string} facet the facet to refine
6054
6459
  * @param {string} value the associated value
6055
- * @return {AlgoliaSearchHelper}
6460
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6056
6461
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
6057
6462
  * @fires change
6058
6463
  * @chainable
6059
6464
  */
6060
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
6465
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
6061
6466
  this._change({
6062
6467
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
6063
- isPageReset: true
6468
+ isPageReset: true,
6064
6469
  });
6065
6470
 
6066
6471
  return this;
6067
6472
  };
6068
6473
 
6474
+ // eslint-disable-next-line valid-jsdoc
6069
6475
  /**
6070
6476
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6071
6477
  */
6072
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
6478
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
6073
6479
  return this.toggleFacetRefinement.apply(this, arguments);
6074
6480
  };
6075
6481
 
@@ -6079,14 +6485,14 @@
6079
6485
  *
6080
6486
  * This method resets the current page to 0.
6081
6487
  * @param {string} tag tag to remove or add
6082
- * @return {AlgoliaSearchHelper}
6488
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6083
6489
  * @fires change
6084
6490
  * @chainable
6085
6491
  */
6086
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
6492
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
6087
6493
  this._change({
6088
6494
  state: this.state.resetPage().toggleTagRefinement(tag),
6089
- isPageReset: true
6495
+ isPageReset: true,
6090
6496
  });
6091
6497
 
6092
6498
  return this;
@@ -6094,14 +6500,14 @@
6094
6500
 
6095
6501
  /**
6096
6502
  * Increments the page number by one.
6097
- * @return {AlgoliaSearchHelper}
6503
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6098
6504
  * @fires change
6099
6505
  * @chainable
6100
6506
  * @example
6101
6507
  * helper.setPage(0).nextPage().getPage();
6102
6508
  * // returns 1
6103
6509
  */
6104
- AlgoliaSearchHelper.prototype.nextPage = function() {
6510
+ AlgoliaSearchHelper.prototype.nextPage = function () {
6105
6511
  var page = this.state.page || 0;
6106
6512
  return this.setPage(page + 1);
6107
6513
  };
@@ -6109,26 +6515,30 @@
6109
6515
  /**
6110
6516
  * Decrements the page number by one.
6111
6517
  * @fires change
6112
- * @return {AlgoliaSearchHelper}
6518
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6113
6519
  * @chainable
6114
6520
  * @example
6115
6521
  * helper.setPage(1).previousPage().getPage();
6116
6522
  * // returns 0
6117
6523
  */
6118
- AlgoliaSearchHelper.prototype.previousPage = function() {
6524
+ AlgoliaSearchHelper.prototype.previousPage = function () {
6119
6525
  var page = this.state.page || 0;
6120
6526
  return this.setPage(page - 1);
6121
6527
  };
6122
6528
 
6123
6529
  /**
6124
6530
  * @private
6531
+ * @param {number} page The page number
6532
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6533
+ * @chainable
6534
+ * @fires change
6125
6535
  */
6126
6536
  function setCurrentPage(page) {
6127
6537
  if (page < 0) throw new Error('Page requested below 0.');
6128
6538
 
6129
6539
  this._change({
6130
6540
  state: this.state.setPage(page),
6131
- isPageReset: false
6541
+ isPageReset: false,
6132
6542
  });
6133
6543
 
6134
6544
  return this;
@@ -6138,7 +6548,7 @@
6138
6548
  * Change the current page
6139
6549
  * @deprecated
6140
6550
  * @param {number} page The page number
6141
- * @return {AlgoliaSearchHelper}
6551
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6142
6552
  * @fires change
6143
6553
  * @chainable
6144
6554
  */
@@ -6148,7 +6558,7 @@
6148
6558
  * Updates the current page.
6149
6559
  * @function
6150
6560
  * @param {number} page The page number
6151
- * @return {AlgoliaSearchHelper}
6561
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6152
6562
  * @fires change
6153
6563
  * @chainable
6154
6564
  */
@@ -6159,14 +6569,14 @@
6159
6569
  *
6160
6570
  * This method resets the current page to 0.
6161
6571
  * @param {string} name the index name
6162
- * @return {AlgoliaSearchHelper}
6572
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6163
6573
  * @fires change
6164
6574
  * @chainable
6165
6575
  */
6166
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
6576
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
6167
6577
  this._change({
6168
6578
  state: this.state.resetPage().setIndex(name),
6169
- isPageReset: true
6579
+ isPageReset: true,
6170
6580
  });
6171
6581
 
6172
6582
  return this;
@@ -6183,16 +6593,16 @@
6183
6593
  * This method resets the current page to 0.
6184
6594
  * @param {string} parameter name of the parameter to update
6185
6595
  * @param {any} value new value of the parameter
6186
- * @return {AlgoliaSearchHelper}
6596
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6187
6597
  * @fires change
6188
6598
  * @chainable
6189
6599
  * @example
6190
6600
  * helper.setQueryParameter('hitsPerPage', 20).search();
6191
6601
  */
6192
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
6602
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
6193
6603
  this._change({
6194
6604
  state: this.state.resetPage().setQueryParameter(parameter, value),
6195
- isPageReset: true
6605
+ isPageReset: true,
6196
6606
  });
6197
6607
 
6198
6608
  return this;
@@ -6201,14 +6611,14 @@
6201
6611
  /**
6202
6612
  * Set the whole state (warning: will erase previous state)
6203
6613
  * @param {SearchParameters} newState the whole new state
6204
- * @return {AlgoliaSearchHelper}
6614
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6205
6615
  * @fires change
6206
6616
  * @chainable
6207
6617
  */
6208
- AlgoliaSearchHelper.prototype.setState = function(newState) {
6618
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
6209
6619
  this._change({
6210
6620
  state: SearchParameters_1.make(newState),
6211
- isPageReset: false
6621
+ isPageReset: false,
6212
6622
  });
6213
6623
 
6214
6624
  return this;
@@ -6219,7 +6629,7 @@
6219
6629
  * Do not use this method unless you know what you are doing. (see the example
6220
6630
  * for a legit use case)
6221
6631
  * @param {SearchParameters} newState the whole new state
6222
- * @return {AlgoliaSearchHelper}
6632
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6223
6633
  * @example
6224
6634
  * helper.on('change', function(state){
6225
6635
  * // In this function you might want to find a way to store the state in the url/history
@@ -6231,10 +6641,11 @@
6231
6641
  * }
6232
6642
  * @chainable
6233
6643
  */
6234
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
6235
- this.state = new SearchParameters_1(newState);
6236
- return this;
6237
- };
6644
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent =
6645
+ function (newState) {
6646
+ this.state = new SearchParameters_1(newState);
6647
+ return this;
6648
+ };
6238
6649
 
6239
6650
  /**
6240
6651
  * Check if an attribute has any numeric, conjunctive, disjunctive or hierarchical filters.
@@ -6259,7 +6670,7 @@
6259
6670
  * helper.hasRefinements('categories'); // true
6260
6671
  *
6261
6672
  */
6262
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
6673
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
6263
6674
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
6264
6675
  return true;
6265
6676
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -6284,7 +6695,7 @@
6284
6695
  *
6285
6696
  * @param {string} facet name of the attribute for used for faceting
6286
6697
  * @param {string} [value] optional value. If passed will test that this value
6287
- * is filtering the given facet.
6698
+ * is filtering the given facet.
6288
6699
  * @return {boolean} true if refined
6289
6700
  * @example
6290
6701
  * helper.isExcludeRefined('color'); // false
@@ -6297,42 +6708,43 @@
6297
6708
  * helper.isExcludeRefined('color', 'blue') // false
6298
6709
  * helper.isExcludeRefined('color', 'red') // true
6299
6710
  */
6300
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
6711
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
6301
6712
  return this.state.isExcludeRefined(facet, value);
6302
6713
  };
6303
6714
 
6715
+ // eslint-disable-next-line valid-jsdoc
6304
6716
  /**
6305
6717
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
6306
6718
  */
6307
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
6719
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
6308
6720
  return this.state.isDisjunctiveFacetRefined(facet, value);
6309
6721
  };
6310
6722
 
6311
6723
  /**
6312
6724
  * Check if the string is a currently filtering tag.
6313
6725
  * @param {string} tag tag to check
6314
- * @return {boolean}
6726
+ * @return {boolean} true if the tag is currently refined
6315
6727
  */
6316
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
6728
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
6317
6729
  return this.state.isTagRefined(tag);
6318
6730
  };
6319
6731
 
6732
+ // eslint-disable-next-line valid-jsdoc
6320
6733
  /**
6321
6734
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
6322
6735
  */
6323
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
6736
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
6324
6737
  return this.hasTagRefinements.apply(this, arguments);
6325
6738
  };
6326
6739
 
6327
-
6328
6740
  /**
6329
6741
  * Get the name of the currently used index.
6330
- * @return {string}
6742
+ * @return {string} name of the index
6331
6743
  * @example
6332
6744
  * helper.setIndex('highestPrice_products').getIndex();
6333
6745
  * // returns 'highestPrice_products'
6334
6746
  */
6335
- AlgoliaSearchHelper.prototype.getIndex = function() {
6747
+ AlgoliaSearchHelper.prototype.getIndex = function () {
6336
6748
  return this.state.index;
6337
6749
  };
6338
6750
 
@@ -6358,7 +6770,7 @@
6358
6770
  *
6359
6771
  * @return {string[]} The list of tags currently set.
6360
6772
  */
6361
- AlgoliaSearchHelper.prototype.getTags = function() {
6773
+ AlgoliaSearchHelper.prototype.getTags = function () {
6362
6774
  return this.state.tagRefinements;
6363
6775
  };
6364
6776
 
@@ -6406,47 +6818,48 @@
6406
6818
  * // }
6407
6819
  * // ]
6408
6820
  */
6409
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
6821
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
6410
6822
  var refinements = [];
6411
6823
 
6412
6824
  if (this.state.isConjunctiveFacet(facetName)) {
6413
6825
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
6414
6826
 
6415
- conjRefinements.forEach(function(r) {
6827
+ conjRefinements.forEach(function (r) {
6416
6828
  refinements.push({
6417
6829
  value: r,
6418
- type: 'conjunctive'
6830
+ type: 'conjunctive',
6419
6831
  });
6420
6832
  });
6421
6833
 
6422
6834
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
6423
6835
 
6424
- excludeRefinements.forEach(function(r) {
6836
+ excludeRefinements.forEach(function (r) {
6425
6837
  refinements.push({
6426
6838
  value: r,
6427
- type: 'exclude'
6839
+ type: 'exclude',
6428
6840
  });
6429
6841
  });
6430
6842
  } else if (this.state.isDisjunctiveFacet(facetName)) {
6431
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
6843
+ var disjunctiveRefinements =
6844
+ this.state.getDisjunctiveRefinements(facetName);
6432
6845
 
6433
- disjRefinements.forEach(function(r) {
6846
+ disjunctiveRefinements.forEach(function (r) {
6434
6847
  refinements.push({
6435
6848
  value: r,
6436
- type: 'disjunctive'
6849
+ type: 'disjunctive',
6437
6850
  });
6438
6851
  });
6439
6852
  }
6440
6853
 
6441
6854
  var numericRefinements = this.state.getNumericRefinements(facetName);
6442
6855
 
6443
- Object.keys(numericRefinements).forEach(function(operator) {
6856
+ Object.keys(numericRefinements).forEach(function (operator) {
6444
6857
  var value = numericRefinements[operator];
6445
6858
 
6446
6859
  refinements.push({
6447
6860
  value: value,
6448
6861
  operator: operator,
6449
- type: 'numeric'
6862
+ type: 'numeric',
6450
6863
  });
6451
6864
  });
6452
6865
 
@@ -6459,7 +6872,10 @@
6459
6872
  * @param {string} operator operator applied on the refined values
6460
6873
  * @return {Array.<number|number[]>} refined values
6461
6874
  */
6462
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
6875
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (
6876
+ attribute,
6877
+ operator
6878
+ ) {
6463
6879
  return this.state.getNumericRefinement(attribute, operator);
6464
6880
  };
6465
6881
 
@@ -6468,7 +6884,9 @@
6468
6884
  * @param {string} facetName Hierarchical facet name
6469
6885
  * @return {array.<string>} the path as an array of string
6470
6886
  */
6471
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
6887
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (
6888
+ facetName
6889
+ ) {
6472
6890
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
6473
6891
  };
6474
6892
 
@@ -6477,12 +6895,14 @@
6477
6895
  /**
6478
6896
  * Perform the underlying queries
6479
6897
  * @private
6480
- * @return {undefined}
6898
+ * @param {object} options options for the query
6899
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
6900
+ * @return {undefined} does not return anything
6481
6901
  * @fires search
6482
6902
  * @fires result
6483
6903
  * @fires error
6484
6904
  */
6485
- AlgoliaSearchHelper.prototype._search = function(options) {
6905
+ AlgoliaSearchHelper.prototype._search = function (options) {
6486
6906
  var state = this.state;
6487
6907
  var states = [];
6488
6908
  var mainQueries = [];
@@ -6493,16 +6913,16 @@
6493
6913
  states.push({
6494
6914
  state: state,
6495
6915
  queriesCount: mainQueries.length,
6496
- helper: this
6916
+ helper: this,
6497
6917
  });
6498
6918
 
6499
6919
  this.emit('search', {
6500
6920
  state: state,
6501
- results: this.lastResults
6921
+ results: this.lastResults,
6502
6922
  });
6503
6923
  }
6504
6924
 
6505
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
6925
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
6506
6926
  var derivedState = derivedHelper.getModifiedState(state);
6507
6927
  var derivedStateQueries = derivedState.index
6508
6928
  ? requestBuilder_1._getQueries(derivedState.index, derivedState)
@@ -6511,12 +6931,12 @@
6511
6931
  states.push({
6512
6932
  state: derivedState,
6513
6933
  queriesCount: derivedStateQueries.length,
6514
- helper: derivedHelper
6934
+ helper: derivedHelper,
6515
6935
  });
6516
6936
 
6517
6937
  derivedHelper.emit('search', {
6518
6938
  state: derivedState,
6519
- results: derivedHelper.lastResults
6939
+ results: derivedHelper.lastResults,
6520
6940
  });
6521
6941
 
6522
6942
  return derivedStateQueries;
@@ -6528,21 +6948,24 @@
6528
6948
  this._currentNbQueries++;
6529
6949
 
6530
6950
  if (!queries.length) {
6531
- return Promise.resolve({results: []}).then(
6951
+ return Promise.resolve({ results: [] }).then(
6532
6952
  this._dispatchAlgoliaResponse.bind(this, states, queryId)
6533
6953
  );
6534
6954
  }
6535
6955
 
6536
6956
  try {
6537
- this.client.search(queries)
6957
+ this.client
6958
+ .search(queries)
6538
6959
  .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
6539
6960
  .catch(this._dispatchAlgoliaError.bind(this, queryId));
6540
6961
  } catch (error) {
6541
6962
  // If we reach this part, we're in an internal error state
6542
6963
  this.emit('error', {
6543
- error: error
6964
+ error: error,
6544
6965
  });
6545
6966
  }
6967
+
6968
+ return undefined;
6546
6969
  };
6547
6970
 
6548
6971
  /**
@@ -6550,28 +6973,31 @@
6550
6973
  * usable object that merge the results of all the batch requests. It will dispatch
6551
6974
  * over the different helper + derived helpers (when there are some).
6552
6975
  * @private
6553
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
6554
- * state state used for to generate the request
6976
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
6555
6977
  * @param {number} queryId id of the current request
6556
6978
  * @param {object} content content of the response
6557
6979
  * @return {undefined}
6558
6980
  */
6559
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
6560
- // FIXME remove the number of outdated queries discarded instead of just one
6981
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (
6982
+ states,
6983
+ queryId,
6984
+ content
6985
+ ) {
6986
+ // @TODO remove the number of outdated queries discarded instead of just one
6561
6987
 
6562
6988
  if (queryId < this._lastQueryIdReceived) {
6563
6989
  // Outdated answer
6564
6990
  return;
6565
6991
  }
6566
6992
 
6567
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
6993
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6568
6994
  this._lastQueryIdReceived = queryId;
6569
6995
 
6570
6996
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6571
6997
 
6572
6998
  var results = content.results.slice();
6573
6999
 
6574
- states.forEach(function(s) {
7000
+ states.forEach(function (s) {
6575
7001
  var state = s.state;
6576
7002
  var queriesCount = s.queriesCount;
6577
7003
  var helper = s.helper;
@@ -6580,21 +7006,24 @@
6580
7006
  if (!state.index) {
6581
7007
  helper.emit('result', {
6582
7008
  results: null,
6583
- state: state
7009
+ state: state,
6584
7010
  });
6585
7011
  return;
6586
7012
  }
6587
7013
 
6588
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
7014
+ helper.lastResults = new SearchResults_1(state, specificResults);
6589
7015
 
6590
7016
  helper.emit('result', {
6591
- results: formattedResponse,
6592
- state: state
7017
+ results: helper.lastResults,
7018
+ state: state,
6593
7019
  });
6594
7020
  });
6595
7021
  };
6596
7022
 
6597
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
7023
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (
7024
+ queryId,
7025
+ error
7026
+ ) {
6598
7027
  if (queryId < this._lastQueryIdReceived) {
6599
7028
  // Outdated answer
6600
7029
  return;
@@ -6604,31 +7033,40 @@
6604
7033
  this._lastQueryIdReceived = queryId;
6605
7034
 
6606
7035
  this.emit('error', {
6607
- error: error
7036
+ error: error,
6608
7037
  });
6609
7038
 
6610
7039
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6611
7040
  };
6612
7041
 
6613
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
6614
- return query ||
7042
+ AlgoliaSearchHelper.prototype.containsRefinement = function (
7043
+ query,
7044
+ facetFilters,
7045
+ numericFilters,
7046
+ tagFilters
7047
+ ) {
7048
+ return (
7049
+ query ||
6615
7050
  facetFilters.length !== 0 ||
6616
7051
  numericFilters.length !== 0 ||
6617
- tagFilters.length !== 0;
7052
+ tagFilters.length !== 0
7053
+ );
6618
7054
  };
6619
7055
 
6620
7056
  /**
6621
7057
  * Test if there are some disjunctive refinements on the facet
6622
7058
  * @private
6623
7059
  * @param {string} facet the attribute to test
6624
- * @return {boolean}
7060
+ * @return {boolean} true if there are refinements on this attribute
6625
7061
  */
6626
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
6627
- return this.state.disjunctiveRefinements[facet] &&
6628
- this.state.disjunctiveRefinements[facet].length > 0;
7062
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
7063
+ return (
7064
+ this.state.disjunctiveRefinements[facet] &&
7065
+ this.state.disjunctiveRefinements[facet].length > 0
7066
+ );
6629
7067
  };
6630
7068
 
6631
- AlgoliaSearchHelper.prototype._change = function(event) {
7069
+ AlgoliaSearchHelper.prototype._change = function (event) {
6632
7070
  var state = event.state;
6633
7071
  var isPageReset = event.isPageReset;
6634
7072
 
@@ -6638,17 +7076,17 @@
6638
7076
  this.emit('change', {
6639
7077
  state: this.state,
6640
7078
  results: this.lastResults,
6641
- isPageReset: isPageReset
7079
+ isPageReset: isPageReset,
6642
7080
  });
6643
7081
  }
6644
7082
  };
6645
7083
 
6646
7084
  /**
6647
7085
  * Clears the cache of the underlying Algolia client.
6648
- * @return {AlgoliaSearchHelper}
7086
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6649
7087
  */
6650
- AlgoliaSearchHelper.prototype.clearCache = function() {
6651
- this.client.clearCache && this.client.clearCache();
7088
+ AlgoliaSearchHelper.prototype.clearCache = function () {
7089
+ if (this.client.clearCache) this.client.clearCache();
6652
7090
  return this;
6653
7091
  };
6654
7092
 
@@ -6656,9 +7094,9 @@
6656
7094
  * Updates the internal client instance. If the reference of the clients
6657
7095
  * are equal then no update is actually done.
6658
7096
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
6659
- * @return {AlgoliaSearchHelper}
7097
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6660
7098
  */
6661
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
7099
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
6662
7100
  if (this.client === newClient) return this;
6663
7101
 
6664
7102
  if (typeof newClient.addAlgoliaAgent === 'function') {
@@ -6671,9 +7109,9 @@
6671
7109
 
6672
7110
  /**
6673
7111
  * Gets the instance of the currently used client.
6674
- * @return {AlgoliaSearch}
7112
+ * @return {AlgoliaSearch} the currently used client
6675
7113
  */
6676
- AlgoliaSearchHelper.prototype.getClient = function() {
7114
+ AlgoliaSearchHelper.prototype.getClient = function () {
6677
7115
  return this.client;
6678
7116
  };
6679
7117
 
@@ -6694,9 +7132,9 @@
6694
7132
  * and the SearchParameters that is returned by the call of the
6695
7133
  * parameter function.
6696
7134
  * @param {function} fn SearchParameters -> SearchParameters
6697
- * @return {DerivedHelper}
7135
+ * @return {DerivedHelper} a new DerivedHelper
6698
7136
  */
6699
- AlgoliaSearchHelper.prototype.derive = function(fn) {
7137
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
6700
7138
  var derivedHelper = new DerivedHelper_1(this, fn);
6701
7139
  this.derivedHelpers.push(derivedHelper);
6702
7140
  return derivedHelper;
@@ -6706,10 +7144,11 @@
6706
7144
  * This method detaches a derived Helper from the main one. Prefer using the one from the
6707
7145
  * derived helper itself, to remove the event listeners too.
6708
7146
  * @private
6709
- * @return {undefined}
7147
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
7148
+ * @return {undefined} nothing is returned
6710
7149
  * @throws Error
6711
7150
  */
6712
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
7151
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
6713
7152
  var pos = this.derivedHelpers.indexOf(derivedHelper);
6714
7153
  if (pos === -1) throw new Error('Derived helper already detached');
6715
7154
  this.derivedHelpers.splice(pos, 1);
@@ -6719,7 +7158,7 @@
6719
7158
  * This method returns true if there is currently at least one on-going search.
6720
7159
  * @return {boolean} true if there is a search pending
6721
7160
  */
6722
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
7161
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
6723
7162
  return this._currentNbQueries > 0;
6724
7163
  };
6725
7164
 
@@ -6770,7 +7209,7 @@
6770
7209
  * @param {AlgoliaSearch} client an AlgoliaSearch client
6771
7210
  * @param {string} index the name of the index to query
6772
7211
  * @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.
6773
- * @return {AlgoliaSearchHelper}
7212
+ * @return {AlgoliaSearchHelper} The helper instance
6774
7213
  */
6775
7214
  function algoliasearchHelper(client, index, opts) {
6776
7215
  return new algoliasearch_helper(client, index, opts);
@@ -7085,26 +7524,30 @@
7085
7524
  */
7086
7525
 
7087
7526
  var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
7527
+
7088
7528
  var ReactPropTypesSecret_1 = ReactPropTypesSecret;
7089
7529
 
7090
7530
  function emptyFunction() {}
7091
7531
  function emptyFunctionWithReset() {}
7092
7532
  emptyFunctionWithReset.resetWarningCache = emptyFunction;
7093
- var factoryWithThrowingShims = function () {
7533
+
7534
+ var factoryWithThrowingShims = function() {
7094
7535
  function shim(props, propName, componentName, location, propFullName, secret) {
7095
7536
  if (secret === ReactPropTypesSecret_1) {
7096
7537
  // It is still safe when called from React.
7097
7538
  return;
7098
7539
  }
7099
- 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');
7540
+ var err = new Error(
7541
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
7542
+ 'Use PropTypes.checkPropTypes() to call them. ' +
7543
+ 'Read more at http://fb.me/use-check-prop-types'
7544
+ );
7100
7545
  err.name = 'Invariant Violation';
7101
7546
  throw err;
7102
- }
7103
- shim.isRequired = shim;
7547
+ } shim.isRequired = shim;
7104
7548
  function getShim() {
7105
7549
  return shim;
7106
- }
7107
- // Important!
7550
+ } // Important!
7108
7551
  // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
7109
7552
  var ReactPropTypes = {
7110
7553
  array: shim,
@@ -7115,6 +7558,7 @@
7115
7558
  object: shim,
7116
7559
  string: shim,
7117
7560
  symbol: shim,
7561
+
7118
7562
  any: shim,
7119
7563
  arrayOf: getShim,
7120
7564
  element: shim,
@@ -7126,10 +7570,13 @@
7126
7570
  oneOfType: getShim,
7127
7571
  shape: getShim,
7128
7572
  exact: getShim,
7573
+
7129
7574
  checkPropTypes: emptyFunctionWithReset,
7130
7575
  resetWarningCache: emptyFunction
7131
7576
  };
7577
+
7132
7578
  ReactPropTypes.PropTypes = ReactPropTypes;
7579
+
7133
7580
  return ReactPropTypes;
7134
7581
  };
7135
7582