react-instantsearch-core 6.40.1 → 6.40.2

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.
@@ -873,7 +873,7 @@
873
873
  });
874
874
  }
875
875
 
876
- var version = '6.40.1';
876
+ var version = '6.40.2';
877
877
 
878
878
  function translatable(defaultTranslations) {
879
879
  return function (Composed) {
@@ -1215,45 +1215,32 @@
1215
1215
  });
1216
1216
 
1217
1217
  function clone(value) {
1218
- if (typeof value === 'object' && value !== null) {
1218
+ if (_typeof(value) === 'object' && value !== null) {
1219
1219
  return _merge(Array.isArray(value) ? [] : {}, value);
1220
1220
  }
1221
1221
  return value;
1222
1222
  }
1223
-
1224
1223
  function isObjectOrArrayOrFunction(value) {
1225
- return (
1226
- typeof value === 'function' ||
1227
- Array.isArray(value) ||
1228
- Object.prototype.toString.call(value) === '[object Object]'
1229
- );
1224
+ return typeof value === 'function' || Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
1230
1225
  }
1231
-
1232
1226
  function _merge(target, source) {
1233
1227
  if (target === source) {
1234
1228
  return target;
1235
1229
  }
1236
1230
 
1231
+ // eslint-disable-next-line no-restricted-syntax
1237
1232
  for (var key in source) {
1238
- if (
1239
- !Object.prototype.hasOwnProperty.call(source, key) ||
1240
- key === '__proto__' ||
1241
- key === 'constructor'
1242
- ) {
1233
+ if (!Object.prototype.hasOwnProperty.call(source, key) || key === '__proto__' || key === 'constructor') {
1234
+ // eslint-disable-next-line no-continue
1243
1235
  continue;
1244
1236
  }
1245
-
1246
1237
  var sourceVal = source[key];
1247
1238
  var targetVal = target[key];
1248
-
1249
1239
  if (typeof targetVal !== 'undefined' && typeof sourceVal === 'undefined') {
1240
+ // eslint-disable-next-line no-continue
1250
1241
  continue;
1251
1242
  }
1252
-
1253
- if (
1254
- isObjectOrArrayOrFunction(targetVal) &&
1255
- isObjectOrArrayOrFunction(sourceVal)
1256
- ) {
1243
+ if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
1257
1244
  target[key] = _merge(targetVal, sourceVal);
1258
1245
  } else {
1259
1246
  target[key] = clone(sourceVal);
@@ -1273,35 +1260,34 @@
1273
1260
  * - treats sparse arrays as sparse
1274
1261
  * - does not convert Array-like objects (Arguments, NodeLists, etc.) to arrays
1275
1262
  *
1276
- * @param {Object} object The destination object.
1263
+ * @param {Object} target The destination object.
1277
1264
  * @param {...Object} [sources] The source objects.
1278
1265
  * @returns {Object} Returns `object`.
1279
1266
  */
1280
-
1281
1267
  function merge(target) {
1282
1268
  if (!isObjectOrArrayOrFunction(target)) {
1283
1269
  target = {};
1284
1270
  }
1285
-
1286
1271
  for (var i = 1, l = arguments.length; i < l; i++) {
1287
1272
  var source = arguments[i];
1288
-
1289
1273
  if (isObjectOrArrayOrFunction(source)) {
1290
1274
  _merge(target, source);
1291
1275
  }
1292
1276
  }
1293
1277
  return target;
1294
1278
  }
1279
+ module.exports = merge;
1295
1280
 
1296
- var merge_1 = merge;
1281
+ var merge$1 = /*#__PURE__*/Object.freeze({
1282
+ __proto__: null
1283
+ });
1297
1284
 
1298
1285
  // NOTE: this behaves like lodash/defaults, but doesn't mutate the target
1299
1286
  // it also preserve keys order
1300
1287
  var defaultsPure = function defaultsPure() {
1301
1288
  var sources = Array.prototype.slice.call(arguments);
1302
-
1303
- return sources.reduceRight(function(acc, source) {
1304
- Object.keys(Object(source)).forEach(function(key) {
1289
+ return sources.reduceRight(function (acc, source) {
1290
+ Object.keys(Object(source)).forEach(function (key) {
1305
1291
  if (source[key] === undefined) {
1306
1292
  return;
1307
1293
  }
@@ -1316,11 +1302,8 @@
1316
1302
  };
1317
1303
 
1318
1304
  function intersection(arr1, arr2) {
1319
- return arr1.filter(function(value, index) {
1320
- return (
1321
- arr2.indexOf(value) > -1 &&
1322
- arr1.indexOf(value) === index /* skips duplicates */
1323
- );
1305
+ return arr1.filter(function (value, index) {
1306
+ return arr2.indexOf(value) > -1 && arr1.indexOf(value) === index /* skips duplicates */;
1324
1307
  });
1325
1308
  }
1326
1309
 
@@ -1331,12 +1314,12 @@
1331
1314
  if (!Array.isArray(array)) {
1332
1315
  return undefined;
1333
1316
  }
1334
-
1335
1317
  for (var i = 0; i < array.length; i++) {
1336
1318
  if (comparator(array[i])) {
1337
1319
  return array[i];
1338
1320
  }
1339
1321
  }
1322
+ return undefined;
1340
1323
  };
1341
1324
 
1342
1325
  function valToNumber(v) {
@@ -1347,10 +1330,8 @@
1347
1330
  } else if (Array.isArray(v)) {
1348
1331
  return v.map(valToNumber);
1349
1332
  }
1350
-
1351
1333
  throw new Error('The value should be a number, a parsable string or an array of those.');
1352
1334
  }
1353
-
1354
1335
  var valToNumber_1 = valToNumber;
1355
1336
 
1356
1337
  // https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
@@ -1362,18 +1343,17 @@
1362
1343
  var i;
1363
1344
  for (i = 0; i < sourceKeys.length; i++) {
1364
1345
  key = sourceKeys[i];
1346
+ // eslint-disable-next-line no-continue
1365
1347
  if (excluded.indexOf(key) >= 0) continue;
1366
1348
  target[key] = source[key];
1367
1349
  }
1368
1350
  return target;
1369
1351
  }
1370
-
1371
1352
  var omit$1 = _objectWithoutPropertiesLoose$1;
1372
1353
 
1373
1354
  function objectHasKeys$1(obj) {
1374
1355
  return obj && Object.keys(obj).length > 0;
1375
1356
  }
1376
-
1377
1357
  var objectHasKeys_1 = objectHasKeys$1;
1378
1358
 
1379
1359
  var isValidUserToken = function isValidUserToken(userToken) {
@@ -1397,8 +1377,6 @@
1397
1377
 
1398
1378
 
1399
1379
 
1400
-
1401
-
1402
1380
  var lib = {
1403
1381
  /**
1404
1382
  * Adds a refinement to a RefinementList
@@ -1411,17 +1389,10 @@
1411
1389
  if (lib.isRefined(refinementList, attribute, value)) {
1412
1390
  return refinementList;
1413
1391
  }
1414
-
1415
1392
  var valueAsString = '' + value;
1416
-
1417
- var facetRefinement = !refinementList[attribute] ?
1418
- [valueAsString] :
1419
- refinementList[attribute].concat(valueAsString);
1420
-
1393
+ var facetRefinement = !refinementList[attribute] ? [valueAsString] : refinementList[attribute].concat(valueAsString);
1421
1394
  var mod = {};
1422
-
1423
1395
  mod[attribute] = facetRefinement;
1424
-
1425
1396
  return defaultsPure({}, mod, refinementList);
1426
1397
  },
1427
1398
  /**
@@ -1437,14 +1408,12 @@
1437
1408
  if (value === undefined) {
1438
1409
  // we use the "filter" form of clearRefinement, since it leaves empty values as-is
1439
1410
  // the form with a string will remove the attribute completely
1440
- return lib.clearRefinement(refinementList, function(v, f) {
1411
+ return lib.clearRefinement(refinementList, function (v, f) {
1441
1412
  return attribute === f;
1442
1413
  });
1443
1414
  }
1444
-
1445
1415
  var valueAsString = '' + value;
1446
-
1447
- return lib.clearRefinement(refinementList, function(v, f) {
1416
+ return lib.clearRefinement(refinementList, function (v, f) {
1448
1417
  return attribute === f && valueAsString === v;
1449
1418
  });
1450
1419
  },
@@ -1457,11 +1426,9 @@
1457
1426
  */
1458
1427
  toggleRefinement: function toggleRefinement(refinementList, attribute, value) {
1459
1428
  if (value === undefined) throw new Error('toggleRefinement should be used with a value');
1460
-
1461
1429
  if (lib.isRefined(refinementList, attribute, value)) {
1462
1430
  return lib.removeRefinement(refinementList, attribute, value);
1463
1431
  }
1464
-
1465
1432
  return lib.addRefinement(refinementList, attribute, value);
1466
1433
  },
1467
1434
  /**
@@ -1477,6 +1444,8 @@
1477
1444
  */
1478
1445
  clearRefinement: function clearRefinement(refinementList, attribute, refinementType) {
1479
1446
  if (attribute === undefined) {
1447
+ // return the same object if the list is already empty
1448
+ // this is mainly for tests, as it doesn't have much impact on performance
1480
1449
  if (!objectHasKeys_1(refinementList)) {
1481
1450
  return refinementList;
1482
1451
  }
@@ -1485,24 +1454,24 @@
1485
1454
  return omit$1(refinementList, [attribute]);
1486
1455
  } else if (typeof attribute === 'function') {
1487
1456
  var hasChanged = false;
1488
-
1489
- var newRefinementList = Object.keys(refinementList).reduce(function(memo, key) {
1457
+ var newRefinementList = Object.keys(refinementList).reduce(function (memo, key) {
1490
1458
  var values = refinementList[key] || [];
1491
- var facetList = values.filter(function(value) {
1459
+ var facetList = values.filter(function (value) {
1492
1460
  return !attribute(value, key, refinementType);
1493
1461
  });
1494
-
1495
1462
  if (facetList.length !== values.length) {
1496
1463
  hasChanged = true;
1497
1464
  }
1498
1465
  memo[key] = facetList;
1499
-
1500
1466
  return memo;
1501
1467
  }, {});
1502
-
1503
1468
  if (hasChanged) return newRefinementList;
1504
1469
  return refinementList;
1505
1470
  }
1471
+
1472
+ // We return nothing if the attribute is not undefined, a string or a function,
1473
+ // as it is not a valid value for a refinement
1474
+ return undefined;
1506
1475
  },
1507
1476
  /**
1508
1477
  * Test if the refinement value is used for the attribute. If no refinement value
@@ -1511,22 +1480,17 @@
1511
1480
  * @param {RefinementList} refinementList the list of refinement
1512
1481
  * @param {string} attribute name of the attribute
1513
1482
  * @param {string} [refinementValue] value of the filter/refinement
1514
- * @return {boolean}
1483
+ * @return {boolean} true if the attribute is refined, false otherwise
1515
1484
  */
1516
1485
  isRefined: function isRefined(refinementList, attribute, refinementValue) {
1517
- var containsRefinements = !!refinementList[attribute] &&
1518
- refinementList[attribute].length > 0;
1519
-
1486
+ var containsRefinements = Boolean(refinementList[attribute]) && refinementList[attribute].length > 0;
1520
1487
  if (refinementValue === undefined || !containsRefinements) {
1521
1488
  return containsRefinements;
1522
1489
  }
1523
-
1524
1490
  var refinementValueAsString = '' + refinementValue;
1525
-
1526
1491
  return refinementList[attribute].indexOf(refinementValueAsString) !== -1;
1527
1492
  }
1528
1493
  };
1529
-
1530
1494
  var RefinementList = lib;
1531
1495
 
1532
1496
  /**
@@ -1535,15 +1499,15 @@
1535
1499
  * - [5]
1536
1500
  * - [[5]]
1537
1501
  * - [[5,5],[4]]
1502
+ * @param {any} a numeric refinement value
1503
+ * @param {any} b numeric refinement value
1504
+ * @return {boolean} true if the values are equal
1538
1505
  */
1539
1506
  function isEqualNumericRefinement(a, b) {
1540
1507
  if (Array.isArray(a) && Array.isArray(b)) {
1541
- return (
1542
- a.length === b.length &&
1543
- a.every(function(el, i) {
1544
- return isEqualNumericRefinement(b[i], el);
1545
- })
1546
- );
1508
+ return a.length === b.length && a.every(function (el, i) {
1509
+ return isEqualNumericRefinement(b[i], el);
1510
+ });
1547
1511
  }
1548
1512
  return a === b;
1549
1513
  }
@@ -1557,7 +1521,7 @@
1557
1521
  * @return {any} the searched value or undefined
1558
1522
  */
1559
1523
  function findArray(array, searchedValue) {
1560
- return find$1(array, function(currentValue) {
1524
+ return find$1(array, function (currentValue) {
1561
1525
  return isEqualNumericRefinement(currentValue, searchedValue);
1562
1526
  });
1563
1527
  }
@@ -1611,8 +1575,8 @@
1611
1575
  */
1612
1576
  function SearchParameters(newParameters) {
1613
1577
  var params = newParameters ? SearchParameters._parseNumbers(newParameters) : {};
1614
-
1615
1578
  if (params.userToken !== undefined && !isValidUserToken(params.userToken)) {
1579
+ // eslint-disable-next-line no-console
1616
1580
  console.warn('[algoliasearch-helper] The `userToken` parameter is invalid. This can lead to wrong analytics.\n - Format: [a-zA-Z0-9_-]{1,64}');
1617
1581
  }
1618
1582
  /**
@@ -1715,11 +1679,11 @@
1715
1679
  */
1716
1680
  this.hierarchicalFacetsRefinements = params.hierarchicalFacetsRefinements || {};
1717
1681
 
1682
+ // eslint-disable-next-line consistent-this
1718
1683
  var self = this;
1719
- Object.keys(params).forEach(function(paramName) {
1684
+ Object.keys(params).forEach(function (paramName) {
1720
1685
  var isKeyKnown = SearchParameters.PARAMETERS.indexOf(paramName) !== -1;
1721
1686
  var isValueDefined = params[paramName] !== undefined;
1722
-
1723
1687
  if (!isKeyKnown && isValueDefined) {
1724
1688
  self[paramName] = params[paramName];
1725
1689
  }
@@ -1738,27 +1702,12 @@
1738
1702
  * @param {object} partialState full or part of a state
1739
1703
  * @return {object} a new object with the number keys as number
1740
1704
  */
1741
- SearchParameters._parseNumbers = function(partialState) {
1742
- // Do not reparse numbers in SearchParameters, they ought to be parsed already
1705
+ SearchParameters._parseNumbers = function (partialState) {
1706
+ // Do not parse numbers again in SearchParameters, they ought to be parsed already
1743
1707
  if (partialState instanceof SearchParameters) return partialState;
1744
-
1745
1708
  var numbers = {};
1746
-
1747
- var numberKeys = [
1748
- 'aroundPrecision',
1749
- 'aroundRadius',
1750
- 'getRankingInfo',
1751
- 'minWordSizefor2Typos',
1752
- 'minWordSizefor1Typo',
1753
- 'page',
1754
- 'maxValuesPerFacet',
1755
- 'distinct',
1756
- 'minimumAroundRadius',
1757
- 'hitsPerPage',
1758
- 'minProximity'
1759
- ];
1760
-
1761
- numberKeys.forEach(function(k) {
1709
+ var numberKeys = ['aroundPrecision', 'aroundRadius', 'getRankingInfo', 'minWordSizefor2Typos', 'minWordSizefor1Typo', 'page', 'maxValuesPerFacet', 'distinct', 'minimumAroundRadius', 'hitsPerPage', 'minProximity'];
1710
+ numberKeys.forEach(function (k) {
1762
1711
  var value = partialState[k];
1763
1712
  if (typeof value === 'string') {
1764
1713
  var parsedValue = parseFloat(value);
@@ -1770,26 +1719,25 @@
1770
1719
  // there's two formats of insideBoundingBox, we need to parse
1771
1720
  // the one which is an array of float geo rectangles
1772
1721
  if (Array.isArray(partialState.insideBoundingBox)) {
1773
- numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
1722
+ numbers.insideBoundingBox = partialState.insideBoundingBox.map(function (geoRect) {
1774
1723
  if (Array.isArray(geoRect)) {
1775
- return geoRect.map(function(value) {
1724
+ return geoRect.map(function (value) {
1776
1725
  return parseFloat(value);
1777
1726
  });
1778
1727
  }
1779
1728
  return geoRect;
1780
1729
  });
1781
1730
  }
1782
-
1783
1731
  if (partialState.numericRefinements) {
1784
1732
  var numericRefinements = {};
1785
- Object.keys(partialState.numericRefinements).forEach(function(attribute) {
1733
+ Object.keys(partialState.numericRefinements).forEach(function (attribute) {
1786
1734
  var operators = partialState.numericRefinements[attribute] || {};
1787
1735
  numericRefinements[attribute] = {};
1788
- Object.keys(operators).forEach(function(operator) {
1736
+ Object.keys(operators).forEach(function (operator) {
1789
1737
  var values = operators[operator];
1790
- var parsedValues = values.map(function(v) {
1738
+ var parsedValues = values.map(function (v) {
1791
1739
  if (Array.isArray(v)) {
1792
- return v.map(function(vPrime) {
1740
+ return v.map(function (vPrime) {
1793
1741
  if (typeof vPrime === 'string') {
1794
1742
  return parseFloat(vPrime);
1795
1743
  }
@@ -1805,8 +1753,7 @@
1805
1753
  });
1806
1754
  numbers.numericRefinements = numericRefinements;
1807
1755
  }
1808
-
1809
- return merge_1({}, partialState, numbers);
1756
+ return merge$1({}, partialState, numbers);
1810
1757
  };
1811
1758
 
1812
1759
  /**
@@ -1817,12 +1764,10 @@
1817
1764
  */
1818
1765
  SearchParameters.make = function makeSearchParameters(newParameters) {
1819
1766
  var instance = new SearchParameters(newParameters);
1820
-
1821
1767
  var hierarchicalFacets = newParameters.hierarchicalFacets || [];
1822
- hierarchicalFacets.forEach(function(facet) {
1768
+ hierarchicalFacets.forEach(function (facet) {
1823
1769
  if (facet.rootPath) {
1824
1770
  var currentRefinement = instance.getHierarchicalRefinement(facet.name);
1825
-
1826
1771
  if (currentRefinement.length > 0 && currentRefinement[0].indexOf(facet.rootPath) !== 0) {
1827
1772
  instance = instance.clearRefinements(facet.name);
1828
1773
  }
@@ -1834,7 +1779,6 @@
1834
1779
  }
1835
1780
  }
1836
1781
  });
1837
-
1838
1782
  return instance;
1839
1783
  };
1840
1784
 
@@ -1844,46 +1788,24 @@
1844
1788
  * @param {object|SearchParameters} parameters the new parameters to set
1845
1789
  * @return {Error|null} Error if the modification is invalid, null otherwise
1846
1790
  */
1847
- SearchParameters.validate = function(currentState, parameters) {
1791
+ SearchParameters.validate = function (currentState, parameters) {
1848
1792
  var params = parameters || {};
1849
-
1850
1793
  if (currentState.tagFilters && params.tagRefinements && params.tagRefinements.length > 0) {
1851
- return new Error(
1852
- '[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' +
1853
- 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
1794
+ return new Error('[Tags] Cannot switch from the managed tag API to the advanced API. It is probably ' + 'an error, if it is really what you want, you should first clear the tags with clearTags method.');
1854
1795
  }
1855
-
1856
1796
  if (currentState.tagRefinements.length > 0 && params.tagFilters) {
1857
- return new Error(
1858
- '[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' +
1859
- 'an error, if it is not, you should first clear the tags with clearTags method.');
1860
- }
1861
-
1862
- if (
1863
- currentState.numericFilters &&
1864
- params.numericRefinements &&
1865
- objectHasKeys_1(params.numericRefinements)
1866
- ) {
1867
- return new Error(
1868
- "[Numeric filters] Can't switch from the advanced to the managed API. It" +
1869
- ' is probably an error, if this is really what you want, you have to first' +
1870
- ' clear the numeric filters.'
1871
- );
1797
+ return new Error('[Tags] Cannot switch from the advanced tag API to the managed API. It is probably ' + 'an error, if it is not, you should first clear the tags with clearTags method.');
1798
+ }
1799
+ if (currentState.numericFilters && params.numericRefinements && objectHasKeys_1(params.numericRefinements)) {
1800
+ return new Error("[Numeric filters] Can't switch from the advanced to the managed API. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
1872
1801
  }
1873
-
1874
1802
  if (objectHasKeys_1(currentState.numericRefinements) && params.numericFilters) {
1875
- return new Error(
1876
- "[Numeric filters] Can't switch from the managed API to the advanced. It" +
1877
- ' is probably an error, if this is really what you want, you have to first' +
1878
- ' clear the numeric filters.');
1803
+ return new Error("[Numeric filters] Can't switch from the managed API to the advanced. It" + ' is probably an error, if this is really what you want, you have to first' + ' clear the numeric filters.');
1879
1804
  }
1880
-
1881
1805
  return null;
1882
1806
  };
1883
-
1884
1807
  SearchParameters.prototype = {
1885
1808
  constructor: SearchParameters,
1886
-
1887
1809
  /**
1888
1810
  * Remove all refinements (disjunctive + conjunctive + excludes + numeric filters)
1889
1811
  * @method
@@ -1891,39 +1813,17 @@
1891
1813
  * - If not given, means to clear all the filters.
1892
1814
  * - If `string`, means to clear all refinements for the `attribute` named filter.
1893
1815
  * - If `function`, means to clear all the refinements that return truthy values.
1894
- * @return {SearchParameters}
1816
+ * @return {SearchParameters} new instance with filters cleared
1895
1817
  */
1896
1818
  clearRefinements: function clearRefinements(attribute) {
1897
1819
  var patch = {
1898
1820
  numericRefinements: this._clearNumericRefinements(attribute),
1899
- facetsRefinements: RefinementList.clearRefinement(
1900
- this.facetsRefinements,
1901
- attribute,
1902
- 'conjunctiveFacet'
1903
- ),
1904
- facetsExcludes: RefinementList.clearRefinement(
1905
- this.facetsExcludes,
1906
- attribute,
1907
- 'exclude'
1908
- ),
1909
- disjunctiveFacetsRefinements: RefinementList.clearRefinement(
1910
- this.disjunctiveFacetsRefinements,
1911
- attribute,
1912
- 'disjunctiveFacet'
1913
- ),
1914
- hierarchicalFacetsRefinements: RefinementList.clearRefinement(
1915
- this.hierarchicalFacetsRefinements,
1916
- attribute,
1917
- 'hierarchicalFacet'
1918
- )
1821
+ facetsRefinements: RefinementList.clearRefinement(this.facetsRefinements, attribute, 'conjunctiveFacet'),
1822
+ facetsExcludes: RefinementList.clearRefinement(this.facetsExcludes, attribute, 'exclude'),
1823
+ disjunctiveFacetsRefinements: RefinementList.clearRefinement(this.disjunctiveFacetsRefinements, attribute, 'disjunctiveFacet'),
1824
+ hierarchicalFacetsRefinements: RefinementList.clearRefinement(this.hierarchicalFacetsRefinements, attribute, 'hierarchicalFacet')
1919
1825
  };
1920
- if (
1921
- patch.numericRefinements === this.numericRefinements &&
1922
- patch.facetsRefinements === this.facetsRefinements &&
1923
- patch.facetsExcludes === this.facetsExcludes &&
1924
- patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements &&
1925
- patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements
1926
- ) {
1826
+ if (patch.numericRefinements === this.numericRefinements && patch.facetsRefinements === this.facetsRefinements && patch.facetsExcludes === this.facetsExcludes && patch.disjunctiveFacetsRefinements === this.disjunctiveFacetsRefinements && patch.hierarchicalFacetsRefinements === this.hierarchicalFacetsRefinements) {
1927
1827
  return this;
1928
1828
  }
1929
1829
  return this.setQueryParameters(patch);
@@ -1931,11 +1831,10 @@
1931
1831
  /**
1932
1832
  * Remove all the refined tags from the SearchParameters
1933
1833
  * @method
1934
- * @return {SearchParameters}
1834
+ * @return {SearchParameters} new instance with tags cleared
1935
1835
  */
1936
1836
  clearTags: function clearTags() {
1937
1837
  if (this.tagFilters === undefined && this.tagRefinements.length === 0) return this;
1938
-
1939
1838
  return this.setQueryParameters({
1940
1839
  tagFilters: undefined,
1941
1840
  tagRefinements: []
@@ -1945,11 +1844,10 @@
1945
1844
  * Set the index.
1946
1845
  * @method
1947
1846
  * @param {string} index the index name
1948
- * @return {SearchParameters}
1847
+ * @return {SearchParameters} new instance
1949
1848
  */
1950
1849
  setIndex: function setIndex(index) {
1951
1850
  if (index === this.index) return this;
1952
-
1953
1851
  return this.setQueryParameters({
1954
1852
  index: index
1955
1853
  });
@@ -1958,11 +1856,10 @@
1958
1856
  * Query setter
1959
1857
  * @method
1960
1858
  * @param {string} newQuery value for the new query
1961
- * @return {SearchParameters}
1859
+ * @return {SearchParameters} new instance
1962
1860
  */
1963
1861
  setQuery: function setQuery(newQuery) {
1964
1862
  if (newQuery === this.query) return this;
1965
-
1966
1863
  return this.setQueryParameters({
1967
1864
  query: newQuery
1968
1865
  });
@@ -1971,11 +1868,10 @@
1971
1868
  * Page setter
1972
1869
  * @method
1973
1870
  * @param {number} newPage new page number
1974
- * @return {SearchParameters}
1871
+ * @return {SearchParameters} new instance
1975
1872
  */
1976
1873
  setPage: function setPage(newPage) {
1977
1874
  if (newPage === this.page) return this;
1978
-
1979
1875
  return this.setQueryParameters({
1980
1876
  page: newPage
1981
1877
  });
@@ -1985,7 +1881,7 @@
1985
1881
  * The facets are the simple facets, used for conjunctive (and) faceting.
1986
1882
  * @method
1987
1883
  * @param {string[]} facets all the attributes of the algolia records used for conjunctive faceting
1988
- * @return {SearchParameters}
1884
+ * @return {SearchParameters} new instance
1989
1885
  */
1990
1886
  setFacets: function setFacets(facets) {
1991
1887
  return this.setQueryParameters({
@@ -1997,7 +1893,7 @@
1997
1893
  * Change the list of disjunctive (or) facets the helper chan handle.
1998
1894
  * @method
1999
1895
  * @param {string[]} facets all the attributes of the algolia records used for disjunctive faceting
2000
- * @return {SearchParameters}
1896
+ * @return {SearchParameters} new instance
2001
1897
  */
2002
1898
  setDisjunctiveFacets: function setDisjunctiveFacets(facets) {
2003
1899
  return this.setQueryParameters({
@@ -2009,11 +1905,10 @@
2009
1905
  * Hits per page represents the number of hits retrieved for this query
2010
1906
  * @method
2011
1907
  * @param {number} n number of hits retrieved per page of results
2012
- * @return {SearchParameters}
1908
+ * @return {SearchParameters} new instance
2013
1909
  */
2014
1910
  setHitsPerPage: function setHitsPerPage(n) {
2015
1911
  if (this.hitsPerPage === n) return this;
2016
-
2017
1912
  return this.setQueryParameters({
2018
1913
  hitsPerPage: n
2019
1914
  });
@@ -2023,11 +1918,10 @@
2023
1918
  * Set the value of typoTolerance
2024
1919
  * @method
2025
1920
  * @param {string} typoTolerance new value of typoTolerance ("true", "false", "min" or "strict")
2026
- * @return {SearchParameters}
1921
+ * @return {SearchParameters} new instance
2027
1922
  */
2028
1923
  setTypoTolerance: function setTypoTolerance(typoTolerance) {
2029
1924
  if (this.typoTolerance === typoTolerance) return this;
2030
-
2031
1925
  return this.setQueryParameters({
2032
1926
  typoTolerance: typoTolerance
2033
1927
  });
@@ -2040,33 +1934,28 @@
2040
1934
  * @param {string} attribute attribute to set the filter on
2041
1935
  * @param {string} operator operator of the filter (possible values: =, >, >=, <, <=, !=)
2042
1936
  * @param {number | number[]} value value of the filter
2043
- * @return {SearchParameters}
1937
+ * @return {SearchParameters} new instance
2044
1938
  * @example
2045
1939
  * // for price = 50 or 40
2046
- * searchparameter.addNumericRefinement('price', '=', [50, 40]);
1940
+ * state.addNumericRefinement('price', '=', [50, 40]);
2047
1941
  * @example
2048
1942
  * // for size = 38 and 40
2049
- * searchparameter.addNumericRefinement('size', '=', 38);
2050
- * searchparameter.addNumericRefinement('size', '=', 40);
1943
+ * state.addNumericRefinement('size', '=', 38);
1944
+ * state.addNumericRefinement('size', '=', 40);
2051
1945
  */
2052
- addNumericRefinement: function(attribute, operator, v) {
2053
- var value = valToNumber_1(v);
2054
-
2055
- if (this.isNumericRefined(attribute, operator, value)) return this;
2056
-
2057
- var mod = merge_1({}, this.numericRefinements);
2058
-
2059
- mod[attribute] = merge_1({}, mod[attribute]);
2060
-
1946
+ addNumericRefinement: function addNumericRefinement(attribute, operator, value) {
1947
+ var val = valToNumber_1(value);
1948
+ if (this.isNumericRefined(attribute, operator, val)) return this;
1949
+ var mod = merge$1({}, this.numericRefinements);
1950
+ mod[attribute] = merge$1({}, mod[attribute]);
2061
1951
  if (mod[attribute][operator]) {
2062
1952
  // Array copy
2063
1953
  mod[attribute][operator] = mod[attribute][operator].slice();
2064
1954
  // Add the element. Concat can't be used here because value can be an array.
2065
- mod[attribute][operator].push(value);
1955
+ mod[attribute][operator].push(val);
2066
1956
  } else {
2067
- mod[attribute][operator] = [value];
1957
+ mod[attribute][operator] = [val];
2068
1958
  }
2069
-
2070
1959
  return this.setQueryParameters({
2071
1960
  numericRefinements: mod
2072
1961
  });
@@ -2076,7 +1965,7 @@
2076
1965
  * @param {string} facetName name of the attribute used for faceting
2077
1966
  * @return {string[]} list of refinements
2078
1967
  */
2079
- getConjunctiveRefinements: function(facetName) {
1968
+ getConjunctiveRefinements: function getConjunctiveRefinements(facetName) {
2080
1969
  if (!this.isConjunctiveFacet(facetName)) {
2081
1970
  return [];
2082
1971
  }
@@ -2087,7 +1976,7 @@
2087
1976
  * @param {string} facetName name of the attribute used for faceting
2088
1977
  * @return {string[]} list of refinements
2089
1978
  */
2090
- getDisjunctiveRefinements: function(facetName) {
1979
+ getDisjunctiveRefinements: function getDisjunctiveRefinements(facetName) {
2091
1980
  if (!this.isDisjunctiveFacet(facetName)) {
2092
1981
  return [];
2093
1982
  }
@@ -2098,7 +1987,7 @@
2098
1987
  * @param {string} facetName name of the attribute used for faceting
2099
1988
  * @return {string[]} list of refinements
2100
1989
  */
2101
- getHierarchicalRefinement: function(facetName) {
1990
+ getHierarchicalRefinement: function getHierarchicalRefinement(facetName) {
2102
1991
  // we send an array but we currently do not support multiple
2103
1992
  // hierarchicalRefinements for a hierarchicalFacet
2104
1993
  return this.hierarchicalFacetsRefinements[facetName] || [];
@@ -2108,47 +1997,42 @@
2108
1997
  * @param {string} facetName name of the attribute used for faceting
2109
1998
  * @return {string[]} list of refinements
2110
1999
  */
2111
- getExcludeRefinements: function(facetName) {
2000
+ getExcludeRefinements: function getExcludeRefinements(facetName) {
2112
2001
  if (!this.isConjunctiveFacet(facetName)) {
2113
2002
  return [];
2114
2003
  }
2115
2004
  return this.facetsExcludes[facetName] || [];
2116
2005
  },
2117
-
2118
2006
  /**
2119
2007
  * Remove all the numeric filter for a given (attribute, operator)
2120
2008
  * @method
2121
2009
  * @param {string} attribute attribute to set the filter on
2122
2010
  * @param {string} [operator] operator of the filter (possible values: =, >, >=, <, <=, !=)
2123
2011
  * @param {number} [number] the value to be removed
2124
- * @return {SearchParameters}
2012
+ * @return {SearchParameters} new instance
2125
2013
  */
2126
- removeNumericRefinement: function(attribute, operator, paramValue) {
2014
+ removeNumericRefinement: function removeNumericRefinement(attribute, operator, number) {
2015
+ var paramValue = number;
2127
2016
  if (paramValue !== undefined) {
2128
2017
  if (!this.isNumericRefined(attribute, operator, paramValue)) {
2129
2018
  return this;
2130
2019
  }
2131
2020
  return this.setQueryParameters({
2132
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2133
- return (
2134
- key === attribute &&
2135
- value.op === operator &&
2136
- isEqualNumericRefinement(value.val, valToNumber_1(paramValue))
2137
- );
2021
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2022
+ return key === attribute && value.op === operator && isEqualNumericRefinement(value.val, valToNumber_1(paramValue));
2138
2023
  })
2139
2024
  });
2140
2025
  } else if (operator !== undefined) {
2141
2026
  if (!this.isNumericRefined(attribute, operator)) return this;
2142
2027
  return this.setQueryParameters({
2143
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2028
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2144
2029
  return key === attribute && value.op === operator;
2145
2030
  })
2146
2031
  });
2147
2032
  }
2148
-
2149
2033
  if (!this.isNumericRefined(attribute)) return this;
2150
2034
  return this.setQueryParameters({
2151
- numericRefinements: this._clearNumericRefinements(function(value, key) {
2035
+ numericRefinements: this._clearNumericRefinements(function (value, key) {
2152
2036
  return key === attribute;
2153
2037
  })
2154
2038
  });
@@ -2158,7 +2042,7 @@
2158
2042
  * @param {string} facetName name of the attribute used for faceting
2159
2043
  * @return {SearchParameters.OperatorList} list of refinements
2160
2044
  */
2161
- getNumericRefinements: function(facetName) {
2045
+ getNumericRefinements: function getNumericRefinements(facetName) {
2162
2046
  return this.numericRefinements[facetName] || {};
2163
2047
  },
2164
2048
  /**
@@ -2167,7 +2051,7 @@
2167
2051
  * @param {string} operator operator applied on the refined values
2168
2052
  * @return {Array.<number|number[]>} refined values
2169
2053
  */
2170
- getNumericRefinement: function(attribute, operator) {
2054
+ getNumericRefinement: function getNumericRefinement(attribute, operator) {
2171
2055
  return this.numericRefinements[attribute] && this.numericRefinements[attribute][operator];
2172
2056
  },
2173
2057
  /**
@@ -2178,7 +2062,7 @@
2178
2062
  * - If not given, means to clear all the filters.
2179
2063
  * - If `string`, means to clear all refinements for the `attribute` named filter.
2180
2064
  * - If `function`, means to clear all the refinements that return truthy values.
2181
- * @return {Object.<string, OperatorList>}
2065
+ * @return {Object.<string, OperatorList>} new numeric refinements
2182
2066
  */
2183
2067
  _clearNumericRefinements: function _clearNumericRefinements(attribute) {
2184
2068
  if (attribute === undefined) {
@@ -2191,16 +2075,18 @@
2191
2075
  } else if (typeof attribute === 'function') {
2192
2076
  var hasChanged = false;
2193
2077
  var numericRefinements = this.numericRefinements;
2194
- var newNumericRefinements = Object.keys(numericRefinements).reduce(function(memo, key) {
2078
+ var newNumericRefinements = Object.keys(numericRefinements).reduce(function (memo, key) {
2195
2079
  var operators = numericRefinements[key];
2196
2080
  var operatorList = {};
2197
-
2198
2081
  operators = operators || {};
2199
- Object.keys(operators).forEach(function(operator) {
2082
+ Object.keys(operators).forEach(function (operator) {
2200
2083
  var values = operators[operator] || [];
2201
2084
  var outValues = [];
2202
- values.forEach(function(value) {
2203
- var predicateResult = attribute({val: value, op: operator}, key, 'numeric');
2085
+ values.forEach(function (value) {
2086
+ var predicateResult = attribute({
2087
+ val: value,
2088
+ op: operator
2089
+ }, key, 'numeric');
2204
2090
  if (!predicateResult) outValues.push(value);
2205
2091
  });
2206
2092
  if (outValues.length !== values.length) {
@@ -2208,28 +2094,28 @@
2208
2094
  }
2209
2095
  operatorList[operator] = outValues;
2210
2096
  });
2211
-
2212
2097
  memo[key] = operatorList;
2213
-
2214
2098
  return memo;
2215
2099
  }, {});
2216
-
2217
2100
  if (hasChanged) return newNumericRefinements;
2218
2101
  return this.numericRefinements;
2219
2102
  }
2103
+
2104
+ // We return nothing if the attribute is not undefined, a string or a function,
2105
+ // as it is not a valid value for a refinement
2106
+ return undefined;
2220
2107
  },
2221
2108
  /**
2222
2109
  * Add a facet to the facets attribute of the helper configuration, if it
2223
2110
  * isn't already present.
2224
2111
  * @method
2225
2112
  * @param {string} facet facet name to add
2226
- * @return {SearchParameters}
2113
+ * @return {SearchParameters} new instance
2227
2114
  */
2228
2115
  addFacet: function addFacet(facet) {
2229
2116
  if (this.isConjunctiveFacet(facet)) {
2230
2117
  return this;
2231
2118
  }
2232
-
2233
2119
  return this.setQueryParameters({
2234
2120
  facets: this.facets.concat([facet])
2235
2121
  });
@@ -2239,13 +2125,12 @@
2239
2125
  * configuration, if it isn't already present.
2240
2126
  * @method
2241
2127
  * @param {string} facet disjunctive facet name to add
2242
- * @return {SearchParameters}
2128
+ * @return {SearchParameters} new instance
2243
2129
  */
2244
2130
  addDisjunctiveFacet: function addDisjunctiveFacet(facet) {
2245
2131
  if (this.isDisjunctiveFacet(facet)) {
2246
2132
  return this;
2247
2133
  }
2248
-
2249
2134
  return this.setQueryParameters({
2250
2135
  disjunctiveFacets: this.disjunctiveFacets.concat([facet])
2251
2136
  });
@@ -2255,15 +2140,13 @@
2255
2140
  * configuration.
2256
2141
  * @method
2257
2142
  * @param {object} hierarchicalFacet hierarchical facet to add
2258
- * @return {SearchParameters}
2143
+ * @return {SearchParameters} new instance
2259
2144
  * @throws will throw an error if a hierarchical facet with the same name was already declared
2260
2145
  */
2261
2146
  addHierarchicalFacet: function addHierarchicalFacet(hierarchicalFacet) {
2262
2147
  if (this.isHierarchicalFacet(hierarchicalFacet.name)) {
2263
- throw new Error(
2264
- 'Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2148
+ throw new Error('Cannot declare two hierarchical facets with the same name: `' + hierarchicalFacet.name + '`');
2265
2149
  }
2266
-
2267
2150
  return this.setQueryParameters({
2268
2151
  hierarchicalFacets: this.hierarchicalFacets.concat([hierarchicalFacet])
2269
2152
  });
@@ -2273,14 +2156,13 @@
2273
2156
  * @method
2274
2157
  * @param {string} facet attribute to apply the faceting on
2275
2158
  * @param {string} value value of the attribute (will be converted to string)
2276
- * @return {SearchParameters}
2159
+ * @return {SearchParameters} new instance
2277
2160
  */
2278
2161
  addFacetRefinement: function addFacetRefinement(facet, value) {
2279
2162
  if (!this.isConjunctiveFacet(facet)) {
2280
2163
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2281
2164
  }
2282
2165
  if (RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2283
-
2284
2166
  return this.setQueryParameters({
2285
2167
  facetsRefinements: RefinementList.addRefinement(this.facetsRefinements, facet, value)
2286
2168
  });
@@ -2290,14 +2172,13 @@
2290
2172
  * @method
2291
2173
  * @param {string} facet attribute to apply the exclusion on
2292
2174
  * @param {string} value value of the attribute (will be converted to string)
2293
- * @return {SearchParameters}
2175
+ * @return {SearchParameters} new instance
2294
2176
  */
2295
2177
  addExcludeRefinement: function addExcludeRefinement(facet, value) {
2296
2178
  if (!this.isConjunctiveFacet(facet)) {
2297
2179
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2298
2180
  }
2299
2181
  if (RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2300
-
2301
2182
  return this.setQueryParameters({
2302
2183
  facetsExcludes: RefinementList.addRefinement(this.facetsExcludes, facet, value)
2303
2184
  });
@@ -2307,33 +2188,27 @@
2307
2188
  * @method
2308
2189
  * @param {string} facet attribute to apply the faceting on
2309
2190
  * @param {string} value value of the attribute (will be converted to string)
2310
- * @return {SearchParameters}
2191
+ * @return {SearchParameters} new instance
2311
2192
  */
2312
2193
  addDisjunctiveFacetRefinement: function addDisjunctiveFacetRefinement(facet, value) {
2313
2194
  if (!this.isDisjunctiveFacet(facet)) {
2314
- throw new Error(
2315
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2195
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2316
2196
  }
2317
-
2318
2197
  if (RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2319
-
2320
2198
  return this.setQueryParameters({
2321
- disjunctiveFacetsRefinements: RefinementList.addRefinement(
2322
- this.disjunctiveFacetsRefinements, facet, value)
2199
+ disjunctiveFacetsRefinements: RefinementList.addRefinement(this.disjunctiveFacetsRefinements, facet, value)
2323
2200
  });
2324
2201
  },
2325
2202
  /**
2326
2203
  * addTagRefinement adds a tag to the list used to filter the results
2327
2204
  * @param {string} tag tag to be added
2328
- * @return {SearchParameters}
2205
+ * @return {SearchParameters} new instance
2329
2206
  */
2330
2207
  addTagRefinement: function addTagRefinement(tag) {
2331
2208
  if (this.isTagRefined(tag)) return this;
2332
-
2333
2209
  var modification = {
2334
2210
  tagRefinements: this.tagRefinements.concat(tag)
2335
2211
  };
2336
-
2337
2212
  return this.setQueryParameters(modification);
2338
2213
  },
2339
2214
  /**
@@ -2341,15 +2216,14 @@
2341
2216
  * is present.
2342
2217
  * @method
2343
2218
  * @param {string} facet facet name to remove
2344
- * @return {SearchParameters}
2219
+ * @return {SearchParameters} new instance
2345
2220
  */
2346
2221
  removeFacet: function removeFacet(facet) {
2347
2222
  if (!this.isConjunctiveFacet(facet)) {
2348
2223
  return this;
2349
2224
  }
2350
-
2351
2225
  return this.clearRefinements(facet).setQueryParameters({
2352
- facets: this.facets.filter(function(f) {
2226
+ facets: this.facets.filter(function (f) {
2353
2227
  return f !== facet;
2354
2228
  })
2355
2229
  });
@@ -2359,15 +2233,14 @@
2359
2233
  * helper configuration, if it is present.
2360
2234
  * @method
2361
2235
  * @param {string} facet disjunctive facet name to remove
2362
- * @return {SearchParameters}
2236
+ * @return {SearchParameters} new instance
2363
2237
  */
2364
2238
  removeDisjunctiveFacet: function removeDisjunctiveFacet(facet) {
2365
2239
  if (!this.isDisjunctiveFacet(facet)) {
2366
2240
  return this;
2367
2241
  }
2368
-
2369
2242
  return this.clearRefinements(facet).setQueryParameters({
2370
- disjunctiveFacets: this.disjunctiveFacets.filter(function(f) {
2243
+ disjunctiveFacets: this.disjunctiveFacets.filter(function (f) {
2371
2244
  return f !== facet;
2372
2245
  })
2373
2246
  });
@@ -2377,15 +2250,14 @@
2377
2250
  * helper configuration, if it is present.
2378
2251
  * @method
2379
2252
  * @param {string} facet hierarchical facet name to remove
2380
- * @return {SearchParameters}
2253
+ * @return {SearchParameters} new instance
2381
2254
  */
2382
2255
  removeHierarchicalFacet: function removeHierarchicalFacet(facet) {
2383
2256
  if (!this.isHierarchicalFacet(facet)) {
2384
2257
  return this;
2385
2258
  }
2386
-
2387
2259
  return this.clearRefinements(facet).setQueryParameters({
2388
- hierarchicalFacets: this.hierarchicalFacets.filter(function(f) {
2260
+ hierarchicalFacets: this.hierarchicalFacets.filter(function (f) {
2389
2261
  return f.name !== facet;
2390
2262
  })
2391
2263
  });
@@ -2397,14 +2269,13 @@
2397
2269
  * @method
2398
2270
  * @param {string} facet name of the attribute used for faceting
2399
2271
  * @param {string} [value] value used to filter
2400
- * @return {SearchParameters}
2272
+ * @return {SearchParameters} new instance
2401
2273
  */
2402
2274
  removeFacetRefinement: function removeFacetRefinement(facet, value) {
2403
2275
  if (!this.isConjunctiveFacet(facet)) {
2404
2276
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2405
2277
  }
2406
2278
  if (!RefinementList.isRefined(this.facetsRefinements, facet, value)) return this;
2407
-
2408
2279
  return this.setQueryParameters({
2409
2280
  facetsRefinements: RefinementList.removeRefinement(this.facetsRefinements, facet, value)
2410
2281
  });
@@ -2414,14 +2285,13 @@
2414
2285
  * @method
2415
2286
  * @param {string} facet name of the attribute used for faceting
2416
2287
  * @param {string} value value used to filter
2417
- * @return {SearchParameters}
2288
+ * @return {SearchParameters} new instance
2418
2289
  */
2419
2290
  removeExcludeRefinement: function removeExcludeRefinement(facet, value) {
2420
2291
  if (!this.isConjunctiveFacet(facet)) {
2421
2292
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2422
2293
  }
2423
2294
  if (!RefinementList.isRefined(this.facetsExcludes, facet, value)) return this;
2424
-
2425
2295
  return this.setQueryParameters({
2426
2296
  facetsExcludes: RefinementList.removeRefinement(this.facetsExcludes, facet, value)
2427
2297
  });
@@ -2431,35 +2301,30 @@
2431
2301
  * @method
2432
2302
  * @param {string} facet name of the attribute used for faceting
2433
2303
  * @param {string} value value used to filter
2434
- * @return {SearchParameters}
2304
+ * @return {SearchParameters} new instance
2435
2305
  */
2436
2306
  removeDisjunctiveFacetRefinement: function removeDisjunctiveFacetRefinement(facet, value) {
2437
2307
  if (!this.isDisjunctiveFacet(facet)) {
2438
- throw new Error(
2439
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2308
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2440
2309
  }
2441
2310
  if (!RefinementList.isRefined(this.disjunctiveFacetsRefinements, facet, value)) return this;
2442
-
2443
2311
  return this.setQueryParameters({
2444
- disjunctiveFacetsRefinements: RefinementList.removeRefinement(
2445
- this.disjunctiveFacetsRefinements, facet, value)
2312
+ disjunctiveFacetsRefinements: RefinementList.removeRefinement(this.disjunctiveFacetsRefinements, facet, value)
2446
2313
  });
2447
2314
  },
2448
2315
  /**
2449
2316
  * Remove a tag from the list of tag refinements
2450
2317
  * @method
2451
2318
  * @param {string} tag the tag to remove
2452
- * @return {SearchParameters}
2319
+ * @return {SearchParameters} new instance
2453
2320
  */
2454
2321
  removeTagRefinement: function removeTagRefinement(tag) {
2455
2322
  if (!this.isTagRefined(tag)) return this;
2456
-
2457
2323
  var modification = {
2458
- tagRefinements: this.tagRefinements.filter(function(t) {
2324
+ tagRefinements: this.tagRefinements.filter(function (t) {
2459
2325
  return t !== tag;
2460
2326
  })
2461
2327
  };
2462
-
2463
2328
  return this.setQueryParameters(modification);
2464
2329
  },
2465
2330
  /**
@@ -2467,7 +2332,7 @@
2467
2332
  * and hierarchical facets
2468
2333
  * @param {string} facet the facet to refine
2469
2334
  * @param {string} value the associated value
2470
- * @return {SearchParameters}
2335
+ * @return {SearchParameters} new instance
2471
2336
  * @throws will throw an error if the facet is not declared in the settings of the helper
2472
2337
  * @deprecated since version 2.19.0, see {@link SearchParameters#toggleFacetRefinement}
2473
2338
  */
@@ -2479,7 +2344,7 @@
2479
2344
  * and hierarchical facets
2480
2345
  * @param {string} facet the facet to refine
2481
2346
  * @param {string} value the associated value
2482
- * @return {SearchParameters}
2347
+ * @return {SearchParameters} new instance
2483
2348
  * @throws will throw an error if the facet is not declared in the settings of the helper
2484
2349
  */
2485
2350
  toggleFacetRefinement: function toggleFacetRefinement(facet, value) {
@@ -2490,22 +2355,19 @@
2490
2355
  } else if (this.isDisjunctiveFacet(facet)) {
2491
2356
  return this.toggleDisjunctiveFacetRefinement(facet, value);
2492
2357
  }
2493
-
2494
- throw new Error('Cannot refine the undeclared facet ' + facet +
2495
- '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2358
+ throw new Error('Cannot refine the undeclared facet ' + facet + '; it should be added to the helper options facets, disjunctiveFacets or hierarchicalFacets');
2496
2359
  },
2497
2360
  /**
2498
2361
  * Switch the refinement applied over a facet/value
2499
2362
  * @method
2500
2363
  * @param {string} facet name of the attribute used for faceting
2501
2364
  * @param {value} value value used for filtering
2502
- * @return {SearchParameters}
2365
+ * @return {SearchParameters} new instance
2503
2366
  */
2504
2367
  toggleConjunctiveFacetRefinement: function toggleConjunctiveFacetRefinement(facet, value) {
2505
2368
  if (!this.isConjunctiveFacet(facet)) {
2506
2369
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2507
2370
  }
2508
-
2509
2371
  return this.setQueryParameters({
2510
2372
  facetsRefinements: RefinementList.toggleRefinement(this.facetsRefinements, facet, value)
2511
2373
  });
@@ -2515,13 +2377,12 @@
2515
2377
  * @method
2516
2378
  * @param {string} facet name of the attribute used for faceting
2517
2379
  * @param {value} value value used for filtering
2518
- * @return {SearchParameters}
2380
+ * @return {SearchParameters} new instance
2519
2381
  */
2520
2382
  toggleExcludeFacetRefinement: function toggleExcludeFacetRefinement(facet, value) {
2521
2383
  if (!this.isConjunctiveFacet(facet)) {
2522
2384
  throw new Error(facet + ' is not defined in the facets attribute of the helper configuration');
2523
2385
  }
2524
-
2525
2386
  return this.setQueryParameters({
2526
2387
  facetsExcludes: RefinementList.toggleRefinement(this.facetsExcludes, facet, value)
2527
2388
  });
@@ -2531,17 +2392,14 @@
2531
2392
  * @method
2532
2393
  * @param {string} facet name of the attribute used for faceting
2533
2394
  * @param {value} value value used for filtering
2534
- * @return {SearchParameters}
2395
+ * @return {SearchParameters} new instance
2535
2396
  */
2536
2397
  toggleDisjunctiveFacetRefinement: function toggleDisjunctiveFacetRefinement(facet, value) {
2537
2398
  if (!this.isDisjunctiveFacet(facet)) {
2538
- throw new Error(
2539
- facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2399
+ throw new Error(facet + ' is not defined in the disjunctiveFacets attribute of the helper configuration');
2540
2400
  }
2541
-
2542
2401
  return this.setQueryParameters({
2543
- disjunctiveFacetsRefinements: RefinementList.toggleRefinement(
2544
- this.disjunctiveFacetsRefinements, facet, value)
2402
+ disjunctiveFacetsRefinements: RefinementList.toggleRefinement(this.disjunctiveFacetsRefinements, facet, value)
2545
2403
  });
2546
2404
  },
2547
2405
  /**
@@ -2549,30 +2407,23 @@
2549
2407
  * @method
2550
2408
  * @param {string} facet name of the attribute used for faceting
2551
2409
  * @param {value} value value used for filtering
2552
- * @return {SearchParameters}
2410
+ * @return {SearchParameters} new instance
2553
2411
  */
2554
2412
  toggleHierarchicalFacetRefinement: function toggleHierarchicalFacetRefinement(facet, value) {
2555
2413
  if (!this.isHierarchicalFacet(facet)) {
2556
- throw new Error(
2557
- facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
2414
+ throw new Error(facet + ' is not defined in the hierarchicalFacets attribute of the helper configuration');
2558
2415
  }
2559
-
2560
2416
  var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facet));
2561
-
2562
2417
  var mod = {};
2563
-
2564
- var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined &&
2565
- this.hierarchicalFacetsRefinements[facet].length > 0 && (
2566
- // remove current refinement:
2567
- // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2568
- this.hierarchicalFacetsRefinements[facet][0] === value ||
2569
- // remove a parent refinement of the current refinement:
2570
- // - refinement was 'beer > IPA > Flying dog'
2571
- // - call is toggleRefine('beer > IPA')
2572
- // - refinement should be `beer`
2573
- this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0
2574
- );
2575
-
2418
+ var upOneOrMultipleLevel = this.hierarchicalFacetsRefinements[facet] !== undefined && this.hierarchicalFacetsRefinements[facet].length > 0 && (
2419
+ // remove current refinement:
2420
+ // refinement was 'beer > IPA', call is toggleRefine('beer > IPA'), refinement should be `beer`
2421
+ this.hierarchicalFacetsRefinements[facet][0] === value ||
2422
+ // remove a parent refinement of the current refinement:
2423
+ // - refinement was 'beer > IPA > Flying dog'
2424
+ // - call is toggleRefine('beer > IPA')
2425
+ // - refinement should be `beer`
2426
+ this.hierarchicalFacetsRefinements[facet][0].indexOf(value + separator) === 0);
2576
2427
  if (upOneOrMultipleLevel) {
2577
2428
  if (value.indexOf(separator) === -1) {
2578
2429
  // go back to root level
@@ -2583,12 +2434,10 @@
2583
2434
  } else {
2584
2435
  mod[facet] = [value];
2585
2436
  }
2586
-
2587
2437
  return this.setQueryParameters({
2588
2438
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2589
2439
  });
2590
2440
  },
2591
-
2592
2441
  /**
2593
2442
  * Adds a refinement on a hierarchical facet.
2594
2443
  * @param {string} facet the facet name
@@ -2596,7 +2445,7 @@
2596
2445
  * @return {SearchParameter} the new state
2597
2446
  * @throws Error if the facet is not defined or if the facet is refined
2598
2447
  */
2599
- addHierarchicalFacetRefinement: function(facet, path) {
2448
+ addHierarchicalFacetRefinement: function addHierarchicalFacetRefinement(facet, path) {
2600
2449
  if (this.isHierarchicalFacetRefined(facet)) {
2601
2450
  throw new Error(facet + ' is already refined.');
2602
2451
  }
@@ -2609,14 +2458,13 @@
2609
2458
  hierarchicalFacetsRefinements: defaultsPure({}, mod, this.hierarchicalFacetsRefinements)
2610
2459
  });
2611
2460
  },
2612
-
2613
2461
  /**
2614
2462
  * Removes the refinement set on a hierarchical facet.
2615
2463
  * @param {string} facet the facet name
2616
2464
  * @return {SearchParameter} the new state
2617
2465
  * @throws Error if the facet is not defined or if the facet is not refined
2618
2466
  */
2619
- removeHierarchicalFacetRefinement: function(facet) {
2467
+ removeHierarchicalFacetRefinement: function removeHierarchicalFacetRefinement(facet) {
2620
2468
  if (!this.isHierarchicalFacetRefined(facet)) {
2621
2469
  return this;
2622
2470
  }
@@ -2630,40 +2478,39 @@
2630
2478
  * Switch the tag refinement
2631
2479
  * @method
2632
2480
  * @param {string} tag the tag to remove or add
2633
- * @return {SearchParameters}
2481
+ * @return {SearchParameters} new instance
2634
2482
  */
2635
2483
  toggleTagRefinement: function toggleTagRefinement(tag) {
2636
2484
  if (this.isTagRefined(tag)) {
2637
2485
  return this.removeTagRefinement(tag);
2638
2486
  }
2639
-
2640
2487
  return this.addTagRefinement(tag);
2641
2488
  },
2642
2489
  /**
2643
2490
  * Test if the facet name is from one of the disjunctive facets
2644
2491
  * @method
2645
2492
  * @param {string} facet facet name to test
2646
- * @return {boolean}
2493
+ * @return {boolean} true if facet is a disjunctive facet
2647
2494
  */
2648
- isDisjunctiveFacet: function(facet) {
2495
+ isDisjunctiveFacet: function isDisjunctiveFacet(facet) {
2649
2496
  return this.disjunctiveFacets.indexOf(facet) > -1;
2650
2497
  },
2651
2498
  /**
2652
2499
  * Test if the facet name is from one of the hierarchical facets
2653
2500
  * @method
2654
2501
  * @param {string} facetName facet name to test
2655
- * @return {boolean}
2502
+ * @return {boolean} true if facetName is a hierarchical facet
2656
2503
  */
2657
- isHierarchicalFacet: function(facetName) {
2504
+ isHierarchicalFacet: function isHierarchicalFacet(facetName) {
2658
2505
  return this.getHierarchicalFacetByName(facetName) !== undefined;
2659
2506
  },
2660
2507
  /**
2661
2508
  * Test if the facet name is from one of the conjunctive/normal facets
2662
2509
  * @method
2663
2510
  * @param {string} facet facet name to test
2664
- * @return {boolean}
2511
+ * @return {boolean} true if facet is a conjunctive facet
2665
2512
  */
2666
- isConjunctiveFacet: function(facet) {
2513
+ isConjunctiveFacet: function isConjunctiveFacet(facet) {
2667
2514
  return this.facets.indexOf(facet) > -1;
2668
2515
  },
2669
2516
  /**
@@ -2704,7 +2551,7 @@
2704
2551
  * @param {string} facet name of the attribute for used for faceting
2705
2552
  * @param {string} value optional, will test if the value is used for refinement
2706
2553
  * if there is one, otherwise will test if the facet contains any refinement
2707
- * @return {boolean}
2554
+ * @return {boolean} true if the facet is refined
2708
2555
  */
2709
2556
  isDisjunctiveFacetRefined: function isDisjunctiveFacetRefined(facet, value) {
2710
2557
  if (!this.isDisjunctiveFacet(facet)) {
@@ -2719,19 +2566,16 @@
2719
2566
  * @param {string} facet name of the attribute for used for faceting
2720
2567
  * @param {string} value optional, will test if the value is used for refinement
2721
2568
  * if there is one, otherwise will test if the facet contains any refinement
2722
- * @return {boolean}
2569
+ * @return {boolean} true if the facet is refined
2723
2570
  */
2724
2571
  isHierarchicalFacetRefined: function isHierarchicalFacetRefined(facet, value) {
2725
2572
  if (!this.isHierarchicalFacet(facet)) {
2726
2573
  return false;
2727
2574
  }
2728
-
2729
2575
  var refinements = this.getHierarchicalRefinement(facet);
2730
-
2731
2576
  if (!value) {
2732
2577
  return refinements.length > 0;
2733
2578
  }
2734
-
2735
2579
  return refinements.indexOf(value) !== -1;
2736
2580
  },
2737
2581
  /**
@@ -2746,29 +2590,21 @@
2746
2590
  */
2747
2591
  isNumericRefined: function isNumericRefined(attribute, operator, value) {
2748
2592
  if (value === undefined && operator === undefined) {
2749
- return !!this.numericRefinements[attribute];
2593
+ return Boolean(this.numericRefinements[attribute]);
2750
2594
  }
2751
-
2752
- var isOperatorDefined =
2753
- this.numericRefinements[attribute] &&
2754
- this.numericRefinements[attribute][operator] !== undefined;
2755
-
2595
+ var isOperatorDefined = this.numericRefinements[attribute] && this.numericRefinements[attribute][operator] !== undefined;
2756
2596
  if (value === undefined || !isOperatorDefined) {
2757
2597
  return isOperatorDefined;
2758
2598
  }
2759
-
2760
2599
  var parsedValue = valToNumber_1(value);
2761
- var isAttributeValueDefined =
2762
- findArray(this.numericRefinements[attribute][operator], parsedValue) !==
2763
- undefined;
2764
-
2600
+ var isAttributeValueDefined = findArray(this.numericRefinements[attribute][operator], parsedValue) !== undefined;
2765
2601
  return isOperatorDefined && isAttributeValueDefined;
2766
2602
  },
2767
2603
  /**
2768
2604
  * Returns true if the tag refined, false otherwise
2769
2605
  * @method
2770
2606
  * @param {string} tag the tag to check
2771
- * @return {boolean}
2607
+ * @return {boolean} true if tag is refined
2772
2608
  */
2773
2609
  isTagRefined: function isTagRefined(tag) {
2774
2610
  return this.tagRefinements.indexOf(tag) !== -1;
@@ -2778,83 +2614,63 @@
2778
2614
  * @method
2779
2615
  * @param {string} facet name of the attribute used for faceting
2780
2616
  * @param {value} value value used for filtering
2781
- * @return {string[]}
2617
+ * @return {string[]} returns the list of refinements
2782
2618
  */
2783
2619
  getRefinedDisjunctiveFacets: function getRefinedDisjunctiveFacets() {
2620
+ // eslint-disable-next-line consistent-this
2784
2621
  var self = this;
2785
2622
 
2786
2623
  // attributes used for numeric filter can also be disjunctive
2787
- var disjunctiveNumericRefinedFacets = intersection_1(
2788
- Object.keys(this.numericRefinements).filter(function(facet) {
2789
- return Object.keys(self.numericRefinements[facet]).length > 0;
2790
- }),
2791
- this.disjunctiveFacets
2792
- );
2793
-
2794
- return Object.keys(this.disjunctiveFacetsRefinements).filter(function(facet) {
2624
+ var disjunctiveNumericRefinedFacets = intersection_1(Object.keys(this.numericRefinements).filter(function (facet) {
2625
+ return Object.keys(self.numericRefinements[facet]).length > 0;
2626
+ }), this.disjunctiveFacets);
2627
+ return Object.keys(this.disjunctiveFacetsRefinements).filter(function (facet) {
2795
2628
  return self.disjunctiveFacetsRefinements[facet].length > 0;
2796
- })
2797
- .concat(disjunctiveNumericRefinedFacets)
2798
- .concat(this.getRefinedHierarchicalFacets());
2629
+ }).concat(disjunctiveNumericRefinedFacets).concat(this.getRefinedHierarchicalFacets());
2799
2630
  },
2800
2631
  /**
2801
2632
  * Returns the list of all disjunctive facets refined
2802
2633
  * @method
2803
2634
  * @param {string} facet name of the attribute used for faceting
2804
2635
  * @param {value} value value used for filtering
2805
- * @return {string[]}
2636
+ * @return {string[]} returns the list of refinements
2806
2637
  */
2807
2638
  getRefinedHierarchicalFacets: function getRefinedHierarchicalFacets() {
2639
+ // eslint-disable-next-line consistent-this
2808
2640
  var self = this;
2809
2641
  return intersection_1(
2810
- // enforce the order between the two arrays,
2811
- // so that refinement name index === hierarchical facet index
2812
- this.hierarchicalFacets.map(function(facet) { return facet.name; }),
2813
- Object.keys(this.hierarchicalFacetsRefinements).filter(function(facet) {
2814
- return self.hierarchicalFacetsRefinements[facet].length > 0;
2815
- })
2816
- );
2642
+ // enforce the order between the two arrays,
2643
+ // so that refinement name index === hierarchical facet index
2644
+ this.hierarchicalFacets.map(function (facet) {
2645
+ return facet.name;
2646
+ }), Object.keys(this.hierarchicalFacetsRefinements).filter(function (facet) {
2647
+ return self.hierarchicalFacetsRefinements[facet].length > 0;
2648
+ }));
2817
2649
  },
2818
2650
  /**
2819
2651
  * Returned the list of all disjunctive facets not refined
2820
2652
  * @method
2821
- * @return {string[]}
2653
+ * @return {string[]} returns the list of facets that are not refined
2822
2654
  */
2823
- getUnrefinedDisjunctiveFacets: function() {
2655
+ getUnrefinedDisjunctiveFacets: function getUnrefinedDisjunctiveFacets() {
2824
2656
  var refinedFacets = this.getRefinedDisjunctiveFacets();
2825
-
2826
- return this.disjunctiveFacets.filter(function(f) {
2657
+ return this.disjunctiveFacets.filter(function (f) {
2827
2658
  return refinedFacets.indexOf(f) === -1;
2828
2659
  });
2829
2660
  },
2830
-
2831
- managedParameters: [
2832
- 'index',
2833
-
2834
- 'facets',
2835
- 'disjunctiveFacets',
2836
- 'facetsRefinements',
2837
- 'hierarchicalFacets',
2838
- 'facetsExcludes',
2839
-
2840
- 'disjunctiveFacetsRefinements',
2841
- 'numericRefinements',
2842
- 'tagRefinements',
2843
- 'hierarchicalFacetsRefinements'
2844
- ],
2661
+ managedParameters: ['index', 'facets', 'disjunctiveFacets', 'facetsRefinements', 'hierarchicalFacets', 'facetsExcludes', 'disjunctiveFacetsRefinements', 'numericRefinements', 'tagRefinements', 'hierarchicalFacetsRefinements'],
2845
2662
  getQueryParams: function getQueryParams() {
2846
2663
  var managedParameters = this.managedParameters;
2847
-
2848
2664
  var queryParams = {};
2849
2665
 
2666
+ // eslint-disable-next-line consistent-this
2850
2667
  var self = this;
2851
- Object.keys(this).forEach(function(paramName) {
2668
+ Object.keys(this).forEach(function (paramName) {
2852
2669
  var paramValue = self[paramName];
2853
2670
  if (managedParameters.indexOf(paramName) === -1 && paramValue !== undefined) {
2854
2671
  queryParams[paramName] = paramValue;
2855
2672
  }
2856
2673
  });
2857
-
2858
2674
  return queryParams;
2859
2675
  },
2860
2676
  /**
@@ -2869,11 +2685,8 @@
2869
2685
  */
2870
2686
  setQueryParameter: function setParameter(parameter, value) {
2871
2687
  if (this[parameter] === value) return this;
2872
-
2873
2688
  var modification = {};
2874
-
2875
2689
  modification[parameter] = value;
2876
-
2877
2690
  return this.setQueryParameters(modification);
2878
2691
  },
2879
2692
  /**
@@ -2884,134 +2697,109 @@
2884
2697
  */
2885
2698
  setQueryParameters: function setQueryParameters(params) {
2886
2699
  if (!params) return this;
2887
-
2888
2700
  var error = SearchParameters.validate(this, params);
2889
-
2890
2701
  if (error) {
2891
2702
  throw error;
2892
2703
  }
2893
2704
 
2705
+ // eslint-disable-next-line consistent-this
2894
2706
  var self = this;
2895
2707
  var nextWithNumbers = SearchParameters._parseNumbers(params);
2896
- var previousPlainObject = Object.keys(this).reduce(function(acc, key) {
2708
+ var previousPlainObject = Object.keys(this).reduce(function (acc, key) {
2897
2709
  acc[key] = self[key];
2898
2710
  return acc;
2899
2711
  }, {});
2900
-
2901
- var nextPlainObject = Object.keys(nextWithNumbers).reduce(
2902
- function(previous, key) {
2903
- var isPreviousValueDefined = previous[key] !== undefined;
2904
- var isNextValueDefined = nextWithNumbers[key] !== undefined;
2905
-
2906
- if (isPreviousValueDefined && !isNextValueDefined) {
2907
- return omit$1(previous, [key]);
2908
- }
2909
-
2910
- if (isNextValueDefined) {
2911
- previous[key] = nextWithNumbers[key];
2912
- }
2913
-
2914
- return previous;
2915
- },
2916
- previousPlainObject
2917
- );
2918
-
2712
+ var nextPlainObject = Object.keys(nextWithNumbers).reduce(function (previous, key) {
2713
+ var isPreviousValueDefined = previous[key] !== undefined;
2714
+ var isNextValueDefined = nextWithNumbers[key] !== undefined;
2715
+ if (isPreviousValueDefined && !isNextValueDefined) {
2716
+ return omit$1(previous, [key]);
2717
+ }
2718
+ if (isNextValueDefined) {
2719
+ previous[key] = nextWithNumbers[key];
2720
+ }
2721
+ return previous;
2722
+ }, previousPlainObject);
2919
2723
  return new this.constructor(nextPlainObject);
2920
2724
  },
2921
-
2922
2725
  /**
2923
2726
  * Returns a new instance with the page reset. Two scenarios possible:
2924
2727
  * the page is omitted -> return the given instance
2925
2728
  * the page is set -> return a new instance with a page of 0
2926
2729
  * @return {SearchParameters} a new updated instance
2927
2730
  */
2928
- resetPage: function() {
2731
+ resetPage: function resetPage() {
2929
2732
  if (this.page === undefined) {
2930
2733
  return this;
2931
2734
  }
2932
-
2933
2735
  return this.setPage(0);
2934
2736
  },
2935
-
2936
2737
  /**
2937
2738
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
2938
- * @param {object} hierarchicalFacet
2739
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2939
2740
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
2940
2741
  */
2941
- _getHierarchicalFacetSortBy: function(hierarchicalFacet) {
2742
+ _getHierarchicalFacetSortBy: function _getHierarchicalFacetSortBy(hierarchicalFacet) {
2942
2743
  return hierarchicalFacet.sortBy || ['isRefined:desc', 'name:asc'];
2943
2744
  },
2944
-
2945
2745
  /**
2946
2746
  * Helper function to get the hierarchicalFacet separator or the default one (`>`)
2947
2747
  * @private
2948
- * @param {object} hierarchicalFacet
2748
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2949
2749
  * @return {string} returns the hierarchicalFacet.separator or `>` as default
2950
2750
  */
2951
- _getHierarchicalFacetSeparator: function(hierarchicalFacet) {
2751
+ _getHierarchicalFacetSeparator: function _getHierarchicalFacetSeparator(hierarchicalFacet) {
2952
2752
  return hierarchicalFacet.separator || ' > ';
2953
2753
  },
2954
-
2955
2754
  /**
2956
2755
  * Helper function to get the hierarchicalFacet prefix path or null
2957
2756
  * @private
2958
- * @param {object} hierarchicalFacet
2757
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2959
2758
  * @return {string} returns the hierarchicalFacet.rootPath or null as default
2960
2759
  */
2961
- _getHierarchicalRootPath: function(hierarchicalFacet) {
2760
+ _getHierarchicalRootPath: function _getHierarchicalRootPath(hierarchicalFacet) {
2962
2761
  return hierarchicalFacet.rootPath || null;
2963
2762
  },
2964
-
2965
2763
  /**
2966
2764
  * Helper function to check if we show the parent level of the hierarchicalFacet
2967
2765
  * @private
2968
- * @param {object} hierarchicalFacet
2766
+ * @param {object} hierarchicalFacet the hierarchicalFacet object
2969
2767
  * @return {string} returns the hierarchicalFacet.showParentLevel or true as default
2970
2768
  */
2971
- _getHierarchicalShowParentLevel: function(hierarchicalFacet) {
2769
+ _getHierarchicalShowParentLevel: function _getHierarchicalShowParentLevel(hierarchicalFacet) {
2972
2770
  if (typeof hierarchicalFacet.showParentLevel === 'boolean') {
2973
2771
  return hierarchicalFacet.showParentLevel;
2974
2772
  }
2975
2773
  return true;
2976
2774
  },
2977
-
2978
2775
  /**
2979
2776
  * Helper function to get the hierarchicalFacet by it's name
2980
- * @param {string} hierarchicalFacetName
2777
+ * @param {string} hierarchicalFacetName the hierarchicalFacet name
2981
2778
  * @return {object} a hierarchicalFacet
2982
2779
  */
2983
- getHierarchicalFacetByName: function(hierarchicalFacetName) {
2984
- return find$1(
2985
- this.hierarchicalFacets,
2986
- function(f) {
2987
- return f.name === hierarchicalFacetName;
2988
- }
2989
- );
2780
+ getHierarchicalFacetByName: function getHierarchicalFacetByName(hierarchicalFacetName) {
2781
+ return find$1(this.hierarchicalFacets, function (f) {
2782
+ return f.name === hierarchicalFacetName;
2783
+ });
2990
2784
  },
2991
-
2992
2785
  /**
2993
2786
  * Get the current breadcrumb for a hierarchical facet, as an array
2994
2787
  * @param {string} facetName Hierarchical facet name
2995
2788
  * @return {array.<string>} the path as an array of string
2996
2789
  */
2997
- getHierarchicalFacetBreadcrumb: function(facetName) {
2790
+ getHierarchicalFacetBreadcrumb: function getHierarchicalFacetBreadcrumb(facetName) {
2998
2791
  if (!this.isHierarchicalFacet(facetName)) {
2999
2792
  return [];
3000
2793
  }
3001
-
3002
2794
  var refinement = this.getHierarchicalRefinement(facetName)[0];
3003
2795
  if (!refinement) return [];
3004
-
3005
- var separator = this._getHierarchicalFacetSeparator(
3006
- this.getHierarchicalFacetByName(facetName)
3007
- );
2796
+ var separator = this._getHierarchicalFacetSeparator(this.getHierarchicalFacetByName(facetName));
3008
2797
  var path = refinement.split(separator);
3009
- return path.map(function(part) {
2798
+ return path.map(function (part) {
3010
2799
  return part.trim();
3011
2800
  });
3012
2801
  },
3013
-
3014
- toString: function() {
2802
+ toString: function toString() {
3015
2803
  return JSON.stringify(this, null, 2);
3016
2804
  }
3017
2805
  };
@@ -3031,22 +2819,12 @@
3031
2819
  if (value !== other) {
3032
2820
  var valIsDefined = value !== undefined;
3033
2821
  var valIsNull = value === null;
3034
-
3035
2822
  var othIsDefined = other !== undefined;
3036
2823
  var othIsNull = other === null;
3037
-
3038
- if (
3039
- (!othIsNull && value > other) ||
3040
- (valIsNull && othIsDefined) ||
3041
- !valIsDefined
3042
- ) {
2824
+ if (!othIsNull && value > other || valIsNull && othIsDefined || !valIsDefined) {
3043
2825
  return 1;
3044
2826
  }
3045
- if (
3046
- (!valIsNull && value < other) ||
3047
- (othIsNull && valIsDefined) ||
3048
- !othIsDefined
3049
- ) {
2827
+ if (!valIsNull && value < other || othIsNull && valIsDefined || !othIsDefined) {
3050
2828
  return -1;
3051
2829
  }
3052
2830
  }
@@ -3057,29 +2835,26 @@
3057
2835
  * @param {Array<object>} collection object with keys in attributes
3058
2836
  * @param {Array<string>} iteratees attributes
3059
2837
  * @param {Array<string>} orders asc | desc
2838
+ * @return {Array<object>} sorted collection
3060
2839
  */
3061
2840
  function orderBy(collection, iteratees, orders) {
3062
2841
  if (!Array.isArray(collection)) {
3063
2842
  return [];
3064
2843
  }
3065
-
3066
2844
  if (!Array.isArray(orders)) {
3067
2845
  orders = [];
3068
2846
  }
3069
-
3070
- var result = collection.map(function(value, index) {
2847
+ var result = collection.map(function (value, index) {
3071
2848
  return {
3072
- criteria: iteratees.map(function(iteratee) {
2849
+ criteria: iteratees.map(function (iteratee) {
3073
2850
  return value[iteratee];
3074
2851
  }),
3075
2852
  index: index,
3076
2853
  value: value
3077
2854
  };
3078
2855
  });
3079
-
3080
2856
  result.sort(function comparer(object, other) {
3081
2857
  var index = -1;
3082
-
3083
2858
  while (++index < object.criteria.length) {
3084
2859
  var res = compareAscending(object.criteria[index], other.criteria[index]);
3085
2860
  if (res) {
@@ -3097,19 +2872,16 @@
3097
2872
  // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
3098
2873
  return object.index - other.index;
3099
2874
  });
3100
-
3101
- return result.map(function(res) {
2875
+ return result.map(function (res) {
3102
2876
  return res.value;
3103
2877
  });
3104
2878
  }
3105
-
3106
2879
  var orderBy_1 = orderBy;
3107
2880
 
3108
2881
  var compact = function compact(array) {
3109
2882
  if (!Array.isArray(array)) {
3110
2883
  return [];
3111
2884
  }
3112
-
3113
2885
  return array.filter(Boolean);
3114
2886
  };
3115
2887
 
@@ -3118,7 +2890,6 @@
3118
2890
  if (!Array.isArray(array)) {
3119
2891
  return -1;
3120
2892
  }
3121
-
3122
2893
  for (var i = 0; i < array.length; i++) {
3123
2894
  if (comparator(array[i])) {
3124
2895
  return i;
@@ -3134,43 +2905,33 @@
3134
2905
  * @return {array.<string[]>} array containing 2 elements : attributes, orders
3135
2906
  */
3136
2907
  var formatSort = function formatSort(sortBy, defaults) {
3137
- var defaultInstructions = (defaults || []).map(function(sort) {
2908
+ var defaultInstructions = (defaults || []).map(function (sort) {
3138
2909
  return sort.split(':');
3139
2910
  });
3140
-
3141
- return sortBy.reduce(
3142
- function preparePredicate(out, sort) {
3143
- var sortInstruction = sort.split(':');
3144
-
3145
- var matchingDefault = find$1(defaultInstructions, function(
3146
- defaultInstruction
3147
- ) {
3148
- return defaultInstruction[0] === sortInstruction[0];
3149
- });
3150
-
3151
- if (sortInstruction.length > 1 || !matchingDefault) {
3152
- out[0].push(sortInstruction[0]);
3153
- out[1].push(sortInstruction[1]);
3154
- return out;
3155
- }
3156
-
3157
- out[0].push(matchingDefault[0]);
3158
- out[1].push(matchingDefault[1]);
2911
+ return sortBy.reduce(function preparePredicate(out, sort) {
2912
+ var sortInstruction = sort.split(':');
2913
+ var matchingDefault = find$1(defaultInstructions, function (defaultInstruction) {
2914
+ return defaultInstruction[0] === sortInstruction[0];
2915
+ });
2916
+ if (sortInstruction.length > 1 || !matchingDefault) {
2917
+ out[0].push(sortInstruction[0]);
2918
+ out[1].push(sortInstruction[1]);
3159
2919
  return out;
3160
- },
3161
- [[], []]
3162
- );
2920
+ }
2921
+ out[0].push(matchingDefault[0]);
2922
+ out[1].push(matchingDefault[1]);
2923
+ return out;
2924
+ }, [[], []]);
3163
2925
  };
3164
2926
 
3165
2927
  /**
3166
2928
  * Replaces a leading - with \-
3167
2929
  * @private
3168
2930
  * @param {any} value the facet value to replace
3169
- * @returns any
2931
+ * @returns {any} the escaped facet value or the value if it was not a string
3170
2932
  */
3171
2933
  function escapeFacetValue(value) {
3172
2934
  if (typeof value !== 'string') return value;
3173
-
3174
2935
  return String(value).replace(/^-/, '\\-');
3175
2936
  }
3176
2937
 
@@ -3178,14 +2939,12 @@
3178
2939
  * Replaces a leading \- with -
3179
2940
  * @private
3180
2941
  * @param {any} value the escaped facet value
3181
- * @returns any
2942
+ * @returns {any} the unescaped facet value or the value if it was not a string
3182
2943
  */
3183
2944
  function unescapeFacetValue$1(value) {
3184
2945
  if (typeof value !== 'string') return value;
3185
-
3186
2946
  return value.replace(/^\\-/, '-');
3187
2947
  }
3188
-
3189
2948
  var escapeFacetValue_1 = {
3190
2949
  escapeFacetValue: escapeFacetValue,
3191
2950
  unescapeFacetValue: unescapeFacetValue$1
@@ -3196,87 +2955,50 @@
3196
2955
 
3197
2956
 
3198
2957
 
3199
-
3200
2958
  var escapeFacetValue$1 = escapeFacetValue_1.escapeFacetValue;
3201
2959
  var unescapeFacetValue$2 = escapeFacetValue_1.unescapeFacetValue;
3202
-
3203
2960
  function generateTrees(state) {
3204
2961
  return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
3205
2962
  var hierarchicalFacet = state.hierarchicalFacets[hierarchicalFacetIndex];
3206
- var hierarchicalFacetRefinement =
3207
- (state.hierarchicalFacetsRefinements[hierarchicalFacet.name] &&
3208
- state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0]) ||
3209
- '';
3210
- var hierarchicalSeparator = state._getHierarchicalFacetSeparator(
3211
- hierarchicalFacet
3212
- );
3213
- var hierarchicalRootPath = state._getHierarchicalRootPath(
3214
- hierarchicalFacet
3215
- );
3216
- var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(
3217
- hierarchicalFacet
3218
- );
3219
- var sortBy = formatSort(
3220
- state._getHierarchicalFacetSortBy(hierarchicalFacet)
3221
- );
3222
-
3223
- var rootExhaustive = hierarchicalFacetResult.every(function(facetResult) {
2963
+ var hierarchicalFacetRefinement = state.hierarchicalFacetsRefinements[hierarchicalFacet.name] && state.hierarchicalFacetsRefinements[hierarchicalFacet.name][0] || '';
2964
+ var hierarchicalSeparator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
2965
+ var hierarchicalRootPath = state._getHierarchicalRootPath(hierarchicalFacet);
2966
+ var hierarchicalShowParentLevel = state._getHierarchicalShowParentLevel(hierarchicalFacet);
2967
+ var sortBy = formatSort(state._getHierarchicalFacetSortBy(hierarchicalFacet));
2968
+ var rootExhaustive = hierarchicalFacetResult.every(function (facetResult) {
3224
2969
  return facetResult.exhaustive;
3225
2970
  });
3226
-
3227
- var generateTreeFn = generateHierarchicalTree(
3228
- sortBy,
3229
- hierarchicalSeparator,
3230
- hierarchicalRootPath,
3231
- hierarchicalShowParentLevel,
3232
- hierarchicalFacetRefinement
3233
- );
3234
-
2971
+ var generateTreeFn = generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, hierarchicalFacetRefinement);
3235
2972
  var results = hierarchicalFacetResult;
3236
-
3237
2973
  if (hierarchicalRootPath) {
3238
- results = hierarchicalFacetResult.slice(
3239
- hierarchicalRootPath.split(hierarchicalSeparator).length
3240
- );
2974
+ results = hierarchicalFacetResult.slice(hierarchicalRootPath.split(hierarchicalSeparator).length);
3241
2975
  }
3242
-
3243
2976
  return results.reduce(generateTreeFn, {
3244
2977
  name: state.hierarchicalFacets[hierarchicalFacetIndex].name,
3245
- count: null, // root level, no count
3246
- isRefined: true, // root level, always refined
3247
- path: null, // root level, no path
2978
+ count: null,
2979
+ // root level, no count
2980
+ isRefined: true,
2981
+ // root level, always refined
2982
+ path: null,
2983
+ // root level, no path
3248
2984
  escapedValue: null,
3249
2985
  exhaustive: rootExhaustive,
3250
2986
  data: null
3251
2987
  });
3252
2988
  };
3253
2989
  }
3254
-
3255
- function generateHierarchicalTree(
3256
- sortBy,
3257
- hierarchicalSeparator,
3258
- hierarchicalRootPath,
3259
- hierarchicalShowParentLevel,
3260
- currentRefinement
3261
- ) {
3262
- return function generateTree(
3263
- hierarchicalTree,
3264
- hierarchicalFacetResult,
3265
- currentHierarchicalLevel
3266
- ) {
2990
+ function generateHierarchicalTree(sortBy, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel, currentRefinement) {
2991
+ return function generateTree(hierarchicalTree, hierarchicalFacetResult, currentHierarchicalLevel) {
3267
2992
  var parent = hierarchicalTree;
3268
-
3269
2993
  if (currentHierarchicalLevel > 0) {
3270
2994
  var level = 0;
3271
-
3272
2995
  parent = hierarchicalTree;
3273
-
3274
2996
  while (level < currentHierarchicalLevel) {
3275
2997
  /**
3276
2998
  * @type {object[]]} hierarchical data
3277
2999
  */
3278
3000
  var data = parent && Array.isArray(parent.data) ? parent.data : [];
3279
- parent = find$1(data, function(subtree) {
3001
+ parent = find$1(data, function (subtree) {
3280
3002
  return subtree.isRefined;
3281
3003
  });
3282
3004
  level++;
@@ -3296,99 +3018,49 @@
3296
3018
  // If parent refinement is `beers`, then we do not want to have `bières > Belges`
3297
3019
  // showing up
3298
3020
 
3299
- var picked = Object.keys(hierarchicalFacetResult.data)
3300
- .map(function(facetValue) {
3301
- return [facetValue, hierarchicalFacetResult.data[facetValue]];
3302
- })
3303
- .filter(function(tuple) {
3304
- var facetValue = tuple[0];
3305
- return onlyMatchingTree(
3306
- facetValue,
3307
- parent.path || hierarchicalRootPath,
3308
- currentRefinement,
3309
- hierarchicalSeparator,
3310
- hierarchicalRootPath,
3311
- hierarchicalShowParentLevel
3312
- );
3313
- });
3314
-
3315
- parent.data = orderBy_1(
3316
- picked.map(function(tuple) {
3317
- var facetValue = tuple[0];
3318
- var facetCount = tuple[1];
3319
-
3320
- return format(
3321
- facetCount,
3322
- facetValue,
3323
- hierarchicalSeparator,
3324
- unescapeFacetValue$2(currentRefinement),
3325
- hierarchicalFacetResult.exhaustive
3326
- );
3327
- }),
3328
- sortBy[0],
3329
- sortBy[1]
3330
- );
3021
+ var picked = Object.keys(hierarchicalFacetResult.data).map(function (facetValue) {
3022
+ return [facetValue, hierarchicalFacetResult.data[facetValue]];
3023
+ }).filter(function (tuple) {
3024
+ var facetValue = tuple[0];
3025
+ return onlyMatchingTree(facetValue, parent.path || hierarchicalRootPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel);
3026
+ });
3027
+ parent.data = orderBy_1(picked.map(function (tuple) {
3028
+ var facetValue = tuple[0];
3029
+ var facetCount = tuple[1];
3030
+ return format(facetCount, facetValue, hierarchicalSeparator, unescapeFacetValue$2(currentRefinement), hierarchicalFacetResult.exhaustive);
3031
+ }), sortBy[0], sortBy[1]);
3331
3032
  }
3332
-
3333
3033
  return hierarchicalTree;
3334
3034
  };
3335
3035
  }
3336
3036
 
3337
- function onlyMatchingTree(
3338
- facetValue,
3339
- parentPath,
3340
- currentRefinement,
3341
- hierarchicalSeparator,
3342
- hierarchicalRootPath,
3343
- hierarchicalShowParentLevel
3344
- ) {
3037
+ // eslint-disable-next-line max-params
3038
+ function onlyMatchingTree(facetValue, parentPath, currentRefinement, hierarchicalSeparator, hierarchicalRootPath, hierarchicalShowParentLevel) {
3345
3039
  // we want the facetValue is a child of hierarchicalRootPath
3346
- if (
3347
- hierarchicalRootPath &&
3348
- (facetValue.indexOf(hierarchicalRootPath) !== 0 ||
3349
- hierarchicalRootPath === facetValue)
3350
- ) {
3040
+ if (hierarchicalRootPath && (facetValue.indexOf(hierarchicalRootPath) !== 0 || hierarchicalRootPath === facetValue)) {
3351
3041
  return false;
3352
3042
  }
3353
3043
 
3354
3044
  // we always want root levels (only when there is no prefix path)
3355
- return (
3356
- (!hierarchicalRootPath &&
3357
- facetValue.indexOf(hierarchicalSeparator) === -1) ||
3358
- // if there is a rootPath, being root level mean 1 level under rootPath
3359
- (hierarchicalRootPath &&
3360
- facetValue.split(hierarchicalSeparator).length -
3361
- hierarchicalRootPath.split(hierarchicalSeparator).length ===
3362
- 1) ||
3363
- // if current refinement is a root level and current facetValue is a root level,
3364
- // keep the facetValue
3365
- (facetValue.indexOf(hierarchicalSeparator) === -1 &&
3366
- currentRefinement.indexOf(hierarchicalSeparator) === -1) ||
3367
- // currentRefinement is a child of the facet value
3368
- currentRefinement.indexOf(facetValue) === 0 ||
3369
- // facetValue is a child of the current parent, add it
3370
- (facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 &&
3371
- (hierarchicalShowParentLevel ||
3372
- facetValue.indexOf(currentRefinement) === 0))
3373
- );
3374
- }
3375
-
3376
- function format(
3377
- facetCount,
3378
- facetValue,
3379
- hierarchicalSeparator,
3380
- currentRefinement,
3381
- exhaustive
3382
- ) {
3045
+ return !hierarchicalRootPath && facetValue.indexOf(hierarchicalSeparator) === -1 ||
3046
+ // if there is a rootPath, being root level mean 1 level under rootPath
3047
+ hierarchicalRootPath && facetValue.split(hierarchicalSeparator).length - hierarchicalRootPath.split(hierarchicalSeparator).length === 1 ||
3048
+ // if current refinement is a root level and current facetValue is a root level,
3049
+ // keep the facetValue
3050
+ facetValue.indexOf(hierarchicalSeparator) === -1 && currentRefinement.indexOf(hierarchicalSeparator) === -1 ||
3051
+ // currentRefinement is a child of the facet value
3052
+ currentRefinement.indexOf(facetValue) === 0 ||
3053
+ // facetValue is a child of the current parent, add it
3054
+ facetValue.indexOf(parentPath + hierarchicalSeparator) === 0 && (hierarchicalShowParentLevel || facetValue.indexOf(currentRefinement) === 0);
3055
+ }
3056
+ function format(facetCount, facetValue, hierarchicalSeparator, currentRefinement, exhaustive) {
3383
3057
  var parts = facetValue.split(hierarchicalSeparator);
3384
3058
  return {
3385
3059
  name: parts[parts.length - 1].trim(),
3386
3060
  path: facetValue,
3387
3061
  escapedValue: escapeFacetValue$1(facetValue),
3388
3062
  count: facetCount,
3389
- isRefined:
3390
- currentRefinement === facetValue ||
3391
- currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3063
+ isRefined: currentRefinement === facetValue || currentRefinement.indexOf(facetValue + hierarchicalSeparator) === 0,
3392
3064
  exhaustive: exhaustive,
3393
3065
  data: null
3394
3066
  };
@@ -3398,7 +3070,6 @@
3398
3070
  var unescapeFacetValue$3 = escapeFacetValue_1.unescapeFacetValue;
3399
3071
 
3400
3072
 
3401
-
3402
3073
  /**
3403
3074
  * @typedef SearchResults.Facet
3404
3075
  * @type {object}
@@ -3441,18 +3112,17 @@
3441
3112
  */
3442
3113
 
3443
3114
  /**
3444
- * @param {string[]} attributes
3115
+ * Turn an array of attributes in an object of attributes with their position in the array as value
3116
+ * @param {string[]} attributes the list of attributes in the record
3117
+ * @return {object} the list of attributes indexed by attribute name
3445
3118
  */
3446
3119
  function getIndices(attributes) {
3447
3120
  var indices = {};
3448
-
3449
- attributes.forEach(function(val, idx) {
3121
+ attributes.forEach(function (val, idx) {
3450
3122
  indices[val] = idx;
3451
3123
  });
3452
-
3453
3124
  return indices;
3454
3125
  }
3455
-
3456
3126
  function assignFacetStats(dest, facetStats, key) {
3457
3127
  if (facetStats && facetStats[key]) {
3458
3128
  dest.stats = facetStats[key];
@@ -3466,22 +3136,18 @@
3466
3136
  */
3467
3137
 
3468
3138
  /**
3469
- * @param {HierarchicalFacet[]} hierarchicalFacets
3470
- * @param {string} hierarchicalAttributeName
3139
+ * @param {HierarchicalFacet[]} hierarchicalFacets All hierarchical facets
3140
+ * @param {string} hierarchicalAttributeName The name of the hierarchical attribute
3141
+ * @return {HierarchicalFacet} The hierarchical facet matching the attribute name
3471
3142
  */
3472
- function findMatchingHierarchicalFacetFromAttributeName(
3473
- hierarchicalFacets,
3474
- hierarchicalAttributeName
3475
- ) {
3476
- return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(
3477
- hierarchicalFacet
3478
- ) {
3143
+ function findMatchingHierarchicalFacetFromAttributeName(hierarchicalFacets, hierarchicalAttributeName) {
3144
+ return find$1(hierarchicalFacets, function facetKeyMatchesAttribute(hierarchicalFacet) {
3479
3145
  var facetNames = hierarchicalFacet.attributes || [];
3480
3146
  return facetNames.indexOf(hierarchicalAttributeName) > -1;
3481
3147
  });
3482
3148
  }
3483
3149
 
3484
- /*eslint-disable */
3150
+ // eslint-disable-next-line valid-jsdoc
3485
3151
  /**
3486
3152
  * Constructor for SearchResults
3487
3153
  * @class
@@ -3612,21 +3278,20 @@
3612
3278
  "index": "bestbuy"
3613
3279
  }
3614
3280
  **/
3615
- /*eslint-enable */
3616
3281
  function SearchResults(state, results, options) {
3617
3282
  var mainSubResponse = results[0];
3618
-
3619
3283
  this._rawResults = results;
3620
3284
 
3285
+ // eslint-disable-next-line consistent-this
3621
3286
  var self = this;
3622
3287
 
3623
3288
  // https://www.algolia.com/doc/api-reference/api-methods/search/#response
3624
- Object.keys(mainSubResponse).forEach(function(key) {
3289
+ Object.keys(mainSubResponse).forEach(function (key) {
3625
3290
  self[key] = mainSubResponse[key];
3626
3291
  });
3627
3292
 
3628
3293
  // Make every key of the result options reachable from the instance
3629
- Object.keys(options || {}).forEach(function(key) {
3294
+ Object.keys(options || {}).forEach(function (key) {
3630
3295
  self[key] = options[key];
3631
3296
  });
3632
3297
 
@@ -3648,8 +3313,8 @@
3648
3313
  * all the records that match the search parameters. Each record is
3649
3314
  * augmented with a new attribute `_highlightResult`
3650
3315
  * which is an object keyed by attribute and with the following properties:
3651
- * - `value` : the value of the facet highlighted (html)
3652
- * - `matchLevel`: full, partial or none depending on how the query terms match
3316
+ * - `value` : the value of the facet highlighted (html)
3317
+ * - `matchLevel`: `full`, `partial` or `none`, depending on how the query terms match
3653
3318
  * @name hits
3654
3319
  * @member {object[]}
3655
3320
  * @memberof SearchResults
@@ -3770,10 +3435,8 @@
3770
3435
  * @memberof SearchResults
3771
3436
  * @instance
3772
3437
  */
3773
- this.processingTimeMS = results.reduce(function(sum, result) {
3774
- return result.processingTimeMS === undefined
3775
- ? sum
3776
- : sum + result.processingTimeMS;
3438
+ this.processingTimeMS = results.reduce(function (sum, result) {
3439
+ return result.processingTimeMS === undefined ? sum : sum + result.processingTimeMS;
3777
3440
  }, 0);
3778
3441
 
3779
3442
  /**
@@ -3793,9 +3456,7 @@
3793
3456
  * @member {SearchResults.Facet[]}
3794
3457
  */
3795
3458
  this.facets = [];
3796
-
3797
3459
  var disjunctiveFacets = state.getRefinedDisjunctiveFacets();
3798
-
3799
3460
  var facetsIndices = getIndices(state.facets);
3800
3461
  var disjunctiveFacetsIndices = getIndices(state.disjunctiveFacets);
3801
3462
  var nextDisjunctiveResult = 1;
@@ -3804,20 +3465,14 @@
3804
3465
  // we get the facets information from the first, general, response.
3805
3466
 
3806
3467
  var mainFacets = mainSubResponse.facets || {};
3807
-
3808
- Object.keys(mainFacets).forEach(function(facetKey) {
3468
+ Object.keys(mainFacets).forEach(function (facetKey) {
3809
3469
  var facetValueObject = mainFacets[facetKey];
3810
-
3811
- var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(
3812
- state.hierarchicalFacets,
3813
- facetKey
3814
- );
3815
-
3470
+ var hierarchicalFacet = findMatchingHierarchicalFacetFromAttributeName(state.hierarchicalFacets, facetKey);
3816
3471
  if (hierarchicalFacet) {
3817
3472
  // Place the hierarchicalFacet data at the correct index depending on
3818
3473
  // the attributes order that was defined at the helper initialization
3819
3474
  var facetIndex = hierarchicalFacet.attributes.indexOf(facetKey);
3820
- var idxAttributeName = findIndex(state.hierarchicalFacets, function(f) {
3475
+ var idxAttributeName = findIndex(state.hierarchicalFacets, function (f) {
3821
3476
  return f.name === hierarchicalFacet.name;
3822
3477
  });
3823
3478
  self.hierarchicalFacets[idxAttributeName][facetIndex] = {
@@ -3829,7 +3484,6 @@
3829
3484
  var isFacetDisjunctive = state.disjunctiveFacets.indexOf(facetKey) !== -1;
3830
3485
  var isFacetConjunctive = state.facets.indexOf(facetKey) !== -1;
3831
3486
  var position;
3832
-
3833
3487
  if (isFacetDisjunctive) {
3834
3488
  position = disjunctiveFacetsIndices[facetKey];
3835
3489
  self.disjunctiveFacets[position] = {
@@ -3855,22 +3509,20 @@
3855
3509
  this.hierarchicalFacets = compact(this.hierarchicalFacets);
3856
3510
 
3857
3511
  // aggregate the refined disjunctive facets
3858
- disjunctiveFacets.forEach(function(disjunctiveFacet) {
3512
+ disjunctiveFacets.forEach(function (disjunctiveFacet) {
3859
3513
  var result = results[nextDisjunctiveResult];
3860
3514
  var facets = result && result.facets ? result.facets : {};
3861
3515
  var hierarchicalFacet = state.getHierarchicalFacetByName(disjunctiveFacet);
3862
3516
 
3863
3517
  // There should be only item in facets.
3864
- Object.keys(facets).forEach(function(dfacet) {
3518
+ Object.keys(facets).forEach(function (dfacet) {
3865
3519
  var facetResults = facets[dfacet];
3866
-
3867
3520
  var position;
3868
-
3869
3521
  if (hierarchicalFacet) {
3870
- position = findIndex(state.hierarchicalFacets, function(f) {
3522
+ position = findIndex(state.hierarchicalFacets, function (f) {
3871
3523
  return f.name === hierarchicalFacet.name;
3872
3524
  });
3873
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3525
+ var attributeIndex = findIndex(self.hierarchicalFacets[position], function (f) {
3874
3526
  return f.attribute === dfacet;
3875
3527
  });
3876
3528
 
@@ -3878,29 +3530,20 @@
3878
3530
  if (attributeIndex === -1) {
3879
3531
  return;
3880
3532
  }
3881
-
3882
- self.hierarchicalFacets[position][attributeIndex].data = merge_1(
3883
- {},
3884
- self.hierarchicalFacets[position][attributeIndex].data,
3885
- facetResults
3886
- );
3533
+ self.hierarchicalFacets[position][attributeIndex].data = merge$1({}, self.hierarchicalFacets[position][attributeIndex].data, facetResults);
3887
3534
  } else {
3888
3535
  position = disjunctiveFacetsIndices[dfacet];
3889
-
3890
3536
  var dataFromMainRequest = mainSubResponse.facets && mainSubResponse.facets[dfacet] || {};
3891
-
3892
3537
  self.disjunctiveFacets[position] = {
3893
3538
  name: dfacet,
3894
3539
  data: defaultsPure({}, facetResults, dataFromMainRequest),
3895
3540
  exhaustive: result.exhaustiveFacetsCount
3896
3541
  };
3897
3542
  assignFacetStats(self.disjunctiveFacets[position], result.facets_stats, dfacet);
3898
-
3899
3543
  if (state.disjunctiveFacetsRefinements[dfacet]) {
3900
- state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
3544
+ state.disjunctiveFacetsRefinements[dfacet].forEach(function (refinementValue) {
3901
3545
  // add the disjunctive refinements if it is no more retrieved
3902
- if (!self.disjunctiveFacets[position].data[refinementValue] &&
3903
- state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
3546
+ if (!self.disjunctiveFacets[position].data[refinementValue] && state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue$3(refinementValue)) > -1) {
3904
3547
  self.disjunctiveFacets[position].data[refinementValue] = 0;
3905
3548
  }
3906
3549
  });
@@ -3911,28 +3554,23 @@
3911
3554
  });
3912
3555
 
3913
3556
  // if we have some parent level values for hierarchical facets, merge them
3914
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
3557
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
3915
3558
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
3916
3559
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
3917
-
3918
3560
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
3919
3561
  // if we are already at a root refinement (or no refinement at all), there is no
3920
3562
  // root level values request
3921
3563
  if (currentRefinement.length === 0 || currentRefinement[0].split(separator).length < 2) {
3922
3564
  return;
3923
3565
  }
3924
-
3925
- results.slice(nextDisjunctiveResult).forEach(function(result) {
3926
- var facets = result && result.facets
3927
- ? result.facets
3928
- : {};
3929
-
3930
- Object.keys(facets).forEach(function(dfacet) {
3566
+ results.slice(nextDisjunctiveResult).forEach(function (result) {
3567
+ var facets = result && result.facets ? result.facets : {};
3568
+ Object.keys(facets).forEach(function (dfacet) {
3931
3569
  var facetResults = facets[dfacet];
3932
- var position = findIndex(state.hierarchicalFacets, function(f) {
3570
+ var position = findIndex(state.hierarchicalFacets, function (f) {
3933
3571
  return f.name === hierarchicalFacet.name;
3934
3572
  });
3935
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3573
+ var attributeIndex = findIndex(self.hierarchicalFacets[position], function (f) {
3936
3574
  return f.attribute === dfacet;
3937
3575
  });
3938
3576
 
@@ -3950,35 +3588,29 @@
3950
3588
  // | beers (5)
3951
3589
  // > IPA (5)
3952
3590
  var defaultData = {};
3953
-
3954
3591
  if (currentRefinement.length > 0) {
3955
3592
  var root = currentRefinement[0].split(separator)[0];
3956
3593
  defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
3957
3594
  }
3958
-
3959
- self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
3960
- defaultData,
3961
- facetResults,
3962
- self.hierarchicalFacets[position][attributeIndex].data
3963
- );
3595
+ self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data);
3964
3596
  });
3965
-
3966
3597
  nextDisjunctiveResult++;
3967
3598
  });
3968
3599
  });
3969
3600
 
3970
3601
  // add the excludes
3971
- Object.keys(state.facetsExcludes).forEach(function(facetName) {
3602
+ Object.keys(state.facetsExcludes).forEach(function (facetName) {
3972
3603
  var excludes = state.facetsExcludes[facetName];
3973
3604
  var position = facetsIndices[facetName];
3974
-
3975
3605
  self.facets[position] = {
3976
3606
  name: facetName,
3977
3607
  data: mainFacets[facetName],
3978
3608
  exhaustive: mainSubResponse.exhaustiveFacetsCount
3979
3609
  };
3980
- excludes.forEach(function(facetValue) {
3981
- self.facets[position] = self.facets[position] || {name: facetName};
3610
+ excludes.forEach(function (facetValue) {
3611
+ self.facets[position] = self.facets[position] || {
3612
+ name: facetName
3613
+ };
3982
3614
  self.facets[position].data = self.facets[position].data || {};
3983
3615
  self.facets[position].data[facetValue] = 0;
3984
3616
  });
@@ -3997,7 +3629,6 @@
3997
3629
  * @type {Array}
3998
3630
  */
3999
3631
  this.disjunctiveFacets = compact(this.disjunctiveFacets);
4000
-
4001
3632
  this._state = state;
4002
3633
  }
4003
3634
 
@@ -4007,14 +3638,11 @@
4007
3638
  * @param {string} name name of the faceted attribute
4008
3639
  * @return {SearchResults.Facet} the facet object
4009
3640
  */
4010
- SearchResults.prototype.getFacetByName = function(name) {
3641
+ SearchResults.prototype.getFacetByName = function (name) {
4011
3642
  function predicate(facet) {
4012
3643
  return facet.name === name;
4013
3644
  }
4014
-
4015
- return find$1(this.facets, predicate) ||
4016
- find$1(this.disjunctiveFacets, predicate) ||
4017
- find$1(this.hierarchicalFacets, predicate);
3645
+ return find$1(this.facets, predicate) || find$1(this.disjunctiveFacets, predicate) || find$1(this.hierarchicalFacets, predicate);
4018
3646
  };
4019
3647
 
4020
3648
  /**
@@ -4028,12 +3656,10 @@
4028
3656
  function predicate(facet) {
4029
3657
  return facet.name === attribute;
4030
3658
  }
4031
-
4032
3659
  if (results._state.isConjunctiveFacet(attribute)) {
4033
3660
  var facet = find$1(results.facets, predicate);
4034
3661
  if (!facet) return [];
4035
-
4036
- return Object.keys(facet.data).map(function(name) {
3662
+ return Object.keys(facet.data).map(function (name) {
4037
3663
  var value = escapeFacetValue$2(name);
4038
3664
  return {
4039
3665
  name: name,
@@ -4046,8 +3672,7 @@
4046
3672
  } else if (results._state.isDisjunctiveFacet(attribute)) {
4047
3673
  var disjunctiveFacet = find$1(results.disjunctiveFacets, predicate);
4048
3674
  if (!disjunctiveFacet) return [];
4049
-
4050
- return Object.keys(disjunctiveFacet.data).map(function(name) {
3675
+ return Object.keys(disjunctiveFacet.data).map(function (name) {
4051
3676
  var value = escapeFacetValue$2(name);
4052
3677
  return {
4053
3678
  name: name,
@@ -4059,29 +3684,31 @@
4059
3684
  } else if (results._state.isHierarchicalFacet(attribute)) {
4060
3685
  var hierarchicalFacetValues = find$1(results.hierarchicalFacets, predicate);
4061
3686
  if (!hierarchicalFacetValues) return hierarchicalFacetValues;
4062
-
4063
3687
  var hierarchicalFacet = results._state.getHierarchicalFacetByName(attribute);
4064
- var currentRefinementSplit = unescapeFacetValue$3(
4065
- results._state.getHierarchicalRefinement(attribute)[0] || ''
4066
- ).split(results._state._getHierarchicalFacetSeparator(hierarchicalFacet));
3688
+ var separator = results._state._getHierarchicalFacetSeparator(hierarchicalFacet);
3689
+ var currentRefinement = unescapeFacetValue$3(results._state.getHierarchicalRefinement(attribute)[0] || '');
3690
+ if (currentRefinement.indexOf(hierarchicalFacet.rootPath) === 0) {
3691
+ currentRefinement = currentRefinement.replace(hierarchicalFacet.rootPath + separator, '');
3692
+ }
3693
+ var currentRefinementSplit = currentRefinement.split(separator);
4067
3694
  currentRefinementSplit.unshift(attribute);
4068
-
4069
3695
  setIsRefined(hierarchicalFacetValues, currentRefinementSplit, 0);
4070
-
4071
3696
  return hierarchicalFacetValues;
4072
3697
  }
3698
+ return undefined;
4073
3699
  }
4074
3700
 
4075
3701
  /**
4076
3702
  * Set the isRefined of a hierarchical facet result based on the current state.
4077
3703
  * @param {SearchResults.HierarchicalFacet} item Hierarchical facet to fix
4078
- * @param {string[]} currentRefinementSplit array of parts of the current hierarchical refinement
3704
+ * @param {string[]} currentRefinement array of parts of the current hierarchical refinement
4079
3705
  * @param {number} depth recursion depth in the currentRefinement
3706
+ * @return {undefined} function mutates the item
4080
3707
  */
4081
3708
  function setIsRefined(item, currentRefinement, depth) {
4082
3709
  item.isRefined = item.name === currentRefinement[depth];
4083
3710
  if (item.data) {
4084
- item.data.forEach(function(child) {
3711
+ item.data.forEach(function (child) {
4085
3712
  setIsRefined(child, currentRefinement, depth + 1);
4086
3713
  });
4087
3714
  }
@@ -4090,32 +3717,30 @@
4090
3717
  /**
4091
3718
  * Sort nodes of a hierarchical or disjunctive facet results
4092
3719
  * @private
4093
- * @param {function} sortFn
3720
+ * @param {function} sortFn sort function to apply
4094
3721
  * @param {HierarchicalFacet|Array} node node upon which we want to apply the sort
4095
3722
  * @param {string[]} names attribute names
4096
3723
  * @param {number} [level=0] current index in the names array
3724
+ * @return {HierarchicalFacet|Array} sorted node
4097
3725
  */
4098
3726
  function recSort(sortFn, node, names, level) {
4099
3727
  level = level || 0;
4100
-
4101
3728
  if (Array.isArray(node)) {
4102
3729
  return sortFn(node, names[level]);
4103
3730
  }
4104
-
4105
3731
  if (!node.data || node.data.length === 0) {
4106
3732
  return node;
4107
3733
  }
4108
-
4109
- var children = node.data.map(function(childNode) {
3734
+ var children = node.data.map(function (childNode) {
4110
3735
  return recSort(sortFn, childNode, names, level + 1);
4111
3736
  });
4112
3737
  var sortedChildren = sortFn(children, names[level]);
4113
- var newNode = defaultsPure({data: sortedChildren}, node);
3738
+ var newNode = defaultsPure({
3739
+ data: sortedChildren
3740
+ }, node);
4114
3741
  return newNode;
4115
3742
  }
4116
-
4117
3743
  SearchResults.DEFAULT_SORT = ['isRefined:desc', 'count:desc', 'name:asc'];
4118
-
4119
3744
  function vanillaSortFn(order, data) {
4120
3745
  return data.sort(order);
4121
3746
  }
@@ -4131,23 +3756,21 @@
4131
3756
  * Sorts facet arrays via their facet ordering
4132
3757
  * @param {Array} facetValues the values
4133
3758
  * @param {FacetOrdering} facetOrdering the ordering
4134
- * @returns {Array}
3759
+ * @returns {Array} the sorted facet values
4135
3760
  */
4136
3761
  function sortViaFacetOrdering(facetValues, facetOrdering) {
4137
3762
  var orderedFacets = [];
4138
3763
  var remainingFacets = [];
4139
-
4140
3764
  var order = facetOrdering.order || [];
4141
3765
  /**
4142
3766
  * an object with the keys being the values in order, the values their index:
4143
3767
  * ['one', 'two'] -> { one: 0, two: 1 }
4144
3768
  */
4145
- var reverseOrder = order.reduce(function(acc, name, i) {
3769
+ var reverseOrder = order.reduce(function (acc, name, i) {
4146
3770
  acc[name] = i;
4147
3771
  return acc;
4148
3772
  }, {});
4149
-
4150
- facetValues.forEach(function(item) {
3773
+ facetValues.forEach(function (item) {
4151
3774
  // hierarchical facets get sorted using their raw name
4152
3775
  var name = item.path || item.name;
4153
3776
  if (reverseOrder[name] !== undefined) {
@@ -4156,11 +3779,9 @@
4156
3779
  remainingFacets.push(item);
4157
3780
  }
4158
3781
  });
4159
-
4160
- orderedFacets = orderedFacets.filter(function(facet) {
3782
+ orderedFacets = orderedFacets.filter(function (facet) {
4161
3783
  return facet;
4162
3784
  });
4163
-
4164
3785
  var sortRemainingBy = facetOrdering.sortRemainingBy;
4165
3786
  var ordering;
4166
3787
  if (sortRemainingBy === 'hidden') {
@@ -4170,24 +3791,16 @@
4170
3791
  } else {
4171
3792
  ordering = [['count'], ['desc']];
4172
3793
  }
4173
-
4174
- return orderedFacets.concat(
4175
- orderBy_1(remainingFacets, ordering[0], ordering[1])
4176
- );
3794
+ return orderedFacets.concat(orderBy_1(remainingFacets, ordering[0], ordering[1]));
4177
3795
  }
4178
3796
 
4179
3797
  /**
4180
3798
  * @param {SearchResults} results the search results class
4181
3799
  * @param {string} attribute the attribute to retrieve ordering of
4182
- * @returns {FacetOrdering=}
3800
+ * @returns {FacetOrdering | undefined} the facet ordering
4183
3801
  */
4184
3802
  function getFacetOrdering(results, attribute) {
4185
- return (
4186
- results.renderingContent &&
4187
- results.renderingContent.facetOrdering &&
4188
- results.renderingContent.facetOrdering.values &&
4189
- results.renderingContent.facetOrdering.values[attribute]
4190
- );
3803
+ return results.renderingContent && results.renderingContent.facetOrdering && results.renderingContent.facetOrdering.values && results.renderingContent.facetOrdering.values[attribute];
4191
3804
  }
4192
3805
 
4193
3806
  /**
@@ -4238,12 +3851,11 @@
4238
3851
  * });
4239
3852
  * });
4240
3853
  */
4241
- SearchResults.prototype.getFacetValues = function(attribute, opts) {
3854
+ SearchResults.prototype.getFacetValues = function (attribute, opts) {
4242
3855
  var facetValues = extractNormalizedFacetValues(this, attribute);
4243
3856
  if (!facetValues) {
4244
3857
  return undefined;
4245
3858
  }
4246
-
4247
3859
  var options = defaultsPure({}, opts, {
4248
3860
  sortBy: SearchResults.DEFAULT_SORT,
4249
3861
  // if no sortBy is given, attempt to sort based on facetOrdering
@@ -4251,6 +3863,7 @@
4251
3863
  facetOrdering: !(opts && opts.sortBy)
4252
3864
  });
4253
3865
 
3866
+ // eslint-disable-next-line consistent-this
4254
3867
  var results = this;
4255
3868
  var attributes;
4256
3869
  if (Array.isArray(facetValues)) {
@@ -4259,25 +3872,20 @@
4259
3872
  var config = results._state.getHierarchicalFacetByName(facetValues.name);
4260
3873
  attributes = config.attributes;
4261
3874
  }
4262
-
4263
- return recSort(function(data, facetName) {
3875
+ return recSort(function (data, facetName) {
4264
3876
  if (options.facetOrdering) {
4265
3877
  var facetOrdering = getFacetOrdering(results, facetName);
4266
- if (Boolean(facetOrdering)) {
3878
+ if (facetOrdering) {
4267
3879
  return sortViaFacetOrdering(data, facetOrdering);
4268
3880
  }
4269
3881
  }
4270
-
4271
3882
  if (Array.isArray(options.sortBy)) {
4272
3883
  var order = formatSort(options.sortBy, SearchResults.DEFAULT_SORT);
4273
3884
  return orderBy_1(data, order[0], order[1]);
4274
3885
  } else if (typeof options.sortBy === 'function') {
4275
3886
  return vanillaSortFn(options.sortBy, data);
4276
3887
  }
4277
- throw new Error(
4278
- 'options.sortBy is optional but if defined it must be ' +
4279
- 'either an array of string (predicates) or a sorting function'
4280
- );
3888
+ throw new Error('options.sortBy is optional but if defined it must be ' + 'either an array of string (predicates) or a sorting function');
4281
3889
  }, facetValues, attributes);
4282
3890
  };
4283
3891
 
@@ -4287,13 +3895,12 @@
4287
3895
  * @param {string} attribute name of the faceted attribute
4288
3896
  * @return {object} The stats of the facet
4289
3897
  */
4290
- SearchResults.prototype.getFacetStats = function(attribute) {
3898
+ SearchResults.prototype.getFacetStats = function (attribute) {
4291
3899
  if (this._state.isConjunctiveFacet(attribute)) {
4292
3900
  return getFacetStatsIfAvailable(this.facets, attribute);
4293
3901
  } else if (this._state.isDisjunctiveFacet(attribute)) {
4294
3902
  return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
4295
3903
  }
4296
-
4297
3904
  return undefined;
4298
3905
  };
4299
3906
 
@@ -4304,10 +3911,11 @@
4304
3911
 
4305
3912
  /**
4306
3913
  * @param {FacetListItem[]} facetList (has more items, but enough for here)
4307
- * @param {string} facetName
3914
+ * @param {string} facetName The attribute to look for
3915
+ * @return {object|undefined} The stats of the facet
4308
3916
  */
4309
3917
  function getFacetStatsIfAvailable(facetList, facetName) {
4310
- var data = find$1(facetList, function(facet) {
3918
+ var data = find$1(facetList, function (facet) {
4311
3919
  return facet.name === facetName;
4312
3920
  });
4313
3921
  return data && data.stats;
@@ -4325,40 +3933,35 @@
4325
3933
  *
4326
3934
  * @return {Array.<Refinement>} all the refinements
4327
3935
  */
4328
- SearchResults.prototype.getRefinements = function() {
3936
+ SearchResults.prototype.getRefinements = function () {
4329
3937
  var state = this._state;
3938
+ // eslint-disable-next-line consistent-this
4330
3939
  var results = this;
4331
3940
  var res = [];
4332
-
4333
- Object.keys(state.facetsRefinements).forEach(function(attributeName) {
4334
- state.facetsRefinements[attributeName].forEach(function(name) {
3941
+ Object.keys(state.facetsRefinements).forEach(function (attributeName) {
3942
+ state.facetsRefinements[attributeName].forEach(function (name) {
4335
3943
  res.push(getRefinement(state, 'facet', attributeName, name, results.facets));
4336
3944
  });
4337
3945
  });
4338
-
4339
- Object.keys(state.facetsExcludes).forEach(function(attributeName) {
4340
- state.facetsExcludes[attributeName].forEach(function(name) {
3946
+ Object.keys(state.facetsExcludes).forEach(function (attributeName) {
3947
+ state.facetsExcludes[attributeName].forEach(function (name) {
4341
3948
  res.push(getRefinement(state, 'exclude', attributeName, name, results.facets));
4342
3949
  });
4343
3950
  });
4344
-
4345
- Object.keys(state.disjunctiveFacetsRefinements).forEach(function(attributeName) {
4346
- state.disjunctiveFacetsRefinements[attributeName].forEach(function(name) {
3951
+ Object.keys(state.disjunctiveFacetsRefinements).forEach(function (attributeName) {
3952
+ state.disjunctiveFacetsRefinements[attributeName].forEach(function (name) {
4347
3953
  res.push(getRefinement(state, 'disjunctive', attributeName, name, results.disjunctiveFacets));
4348
3954
  });
4349
3955
  });
4350
-
4351
- Object.keys(state.hierarchicalFacetsRefinements).forEach(function(attributeName) {
4352
- state.hierarchicalFacetsRefinements[attributeName].forEach(function(name) {
3956
+ Object.keys(state.hierarchicalFacetsRefinements).forEach(function (attributeName) {
3957
+ state.hierarchicalFacetsRefinements[attributeName].forEach(function (name) {
4353
3958
  res.push(getHierarchicalRefinement(state, attributeName, name, results.hierarchicalFacets));
4354
3959
  });
4355
3960
  });
4356
-
4357
-
4358
- Object.keys(state.numericRefinements).forEach(function(attributeName) {
3961
+ Object.keys(state.numericRefinements).forEach(function (attributeName) {
4359
3962
  var operators = state.numericRefinements[attributeName];
4360
- Object.keys(operators).forEach(function(operator) {
4361
- operators[operator].forEach(function(value) {
3963
+ Object.keys(operators).forEach(function (operator) {
3964
+ operators[operator].forEach(function (value) {
4362
3965
  res.push({
4363
3966
  type: 'numeric',
4364
3967
  attributeName: attributeName,
@@ -4369,11 +3972,13 @@
4369
3972
  });
4370
3973
  });
4371
3974
  });
4372
-
4373
- state.tagRefinements.forEach(function(name) {
4374
- res.push({type: 'tag', attributeName: '_tags', name: name});
3975
+ state.tagRefinements.forEach(function (name) {
3976
+ res.push({
3977
+ type: 'tag',
3978
+ attributeName: '_tags',
3979
+ name: name
3980
+ });
4375
3981
  });
4376
-
4377
3982
  return res;
4378
3983
  };
4379
3984
 
@@ -4385,19 +3990,19 @@
4385
3990
  */
4386
3991
 
4387
3992
  /**
4388
- * @param {*} state
4389
- * @param {*} type
4390
- * @param {string} attributeName
4391
- * @param {*} name
4392
- * @param {Facet[]} resultsFacets
3993
+ * @param {SearchParameters} state the current state
3994
+ * @param {string} type the type of the refinement
3995
+ * @param {string} attributeName The attribute of the facet
3996
+ * @param {*} name The name of the facet
3997
+ * @param {Facet[]} resultsFacets facets from the results
3998
+ * @return {Refinement} the refinement
4393
3999
  */
4394
4000
  function getRefinement(state, type, attributeName, name, resultsFacets) {
4395
- var facet = find$1(resultsFacets, function(f) {
4001
+ var facet = find$1(resultsFacets, function (f) {
4396
4002
  return f.name === attributeName;
4397
4003
  });
4398
4004
  var count = facet && facet.data && facet.data[name] ? facet.data[name] : 0;
4399
- var exhaustive = (facet && facet.exhaustive) || false;
4400
-
4005
+ var exhaustive = facet && facet.exhaustive || false;
4401
4006
  return {
4402
4007
  type: type,
4403
4008
  attributeName: attributeName,
@@ -4408,31 +4013,28 @@
4408
4013
  }
4409
4014
 
4410
4015
  /**
4411
- * @param {*} state
4412
- * @param {string} attributeName
4413
- * @param {*} name
4414
- * @param {Facet[]} resultsFacets
4016
+ * @param {SearchParameters} state the current state
4017
+ * @param {string} attributeName the attribute of the hierarchical facet
4018
+ * @param {string} name the name of the facet
4019
+ * @param {Facet[]} resultsFacets facets from the results
4020
+ * @return {HierarchicalFacet} the hierarchical facet
4415
4021
  */
4416
4022
  function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
4417
4023
  var facetDeclaration = state.getHierarchicalFacetByName(attributeName);
4418
4024
  var separator = state._getHierarchicalFacetSeparator(facetDeclaration);
4419
4025
  var split = name.split(separator);
4420
- var rootFacet = find$1(resultsFacets, function(facet) {
4026
+ var rootFacet = find$1(resultsFacets, function (facet) {
4421
4027
  return facet.name === attributeName;
4422
4028
  });
4423
-
4424
- var facet = split.reduce(function(intermediateFacet, part) {
4425
- var newFacet =
4426
- intermediateFacet && find$1(intermediateFacet.data, function(f) {
4427
- return f.name === part;
4428
- });
4029
+ var facet = split.reduce(function (intermediateFacet, part) {
4030
+ var newFacet = intermediateFacet && find$1(intermediateFacet.data, function (f) {
4031
+ return f.name === part;
4032
+ });
4429
4033
  return newFacet !== undefined ? newFacet : intermediateFacet;
4430
4034
  }, rootFacet);
4431
-
4432
- var count = (facet && facet.count) || 0;
4433
- var exhaustive = (facet && facet.exhaustive) || false;
4434
- var path = (facet && facet.path) || '';
4435
-
4035
+ var count = facet && facet.count || 0;
4036
+ var exhaustive = facet && facet.exhaustive || false;
4037
+ var path = facet && facet.path || '';
4436
4038
  return {
4437
4039
  type: 'hierarchical',
4438
4040
  attributeName: attributeName,
@@ -4441,7 +4043,6 @@
4441
4043
  exhaustive: exhaustive
4442
4044
  };
4443
4045
  }
4444
-
4445
4046
  var SearchResults_1 = SearchResults;
4446
4047
 
4447
4048
  // Copyright Joyent, Inc. and other Node contributors.
@@ -4757,7 +4358,6 @@
4757
4358
  }
4758
4359
  });
4759
4360
  }
4760
-
4761
4361
  var inherits_1 = inherits;
4762
4362
 
4763
4363
  /**
@@ -4769,13 +4369,14 @@
4769
4369
  * - result: when the response is retrieved from Algolia and is processed.
4770
4370
  * This event contains a {@link SearchResults} object and the
4771
4371
  * {@link SearchParameters} corresponding to this answer.
4372
+ * @param {AlgoliaSearchHelper} mainHelper the main helper
4373
+ * @param {function} fn the function to create the derived state
4772
4374
  */
4773
4375
  function DerivedHelper(mainHelper, fn) {
4774
4376
  this.main = mainHelper;
4775
4377
  this.fn = fn;
4776
4378
  this.lastResults = null;
4777
4379
  }
4778
-
4779
4380
  inherits_1(DerivedHelper, events);
4780
4381
 
4781
4382
  /**
@@ -4783,33 +4384,30 @@
4783
4384
  * @return {undefined}
4784
4385
  * @throws Error if the derived helper is already detached
4785
4386
  */
4786
- DerivedHelper.prototype.detach = function() {
4387
+ DerivedHelper.prototype.detach = function () {
4787
4388
  this.removeAllListeners();
4788
4389
  this.main.detachDerivedHelper(this);
4789
4390
  };
4790
-
4791
- DerivedHelper.prototype.getModifiedState = function(parameters) {
4391
+ DerivedHelper.prototype.getModifiedState = function (parameters) {
4792
4392
  return this.fn(parameters);
4793
4393
  };
4794
-
4795
4394
  var DerivedHelper_1 = DerivedHelper;
4796
4395
 
4797
4396
  function sortObject(obj) {
4798
- return Object.keys(obj)
4799
- .sort(function(a, b) {
4800
- return a.localeCompare(b);
4801
- })
4802
- .reduce(function(acc, curr) {
4803
- acc[curr] = obj[curr];
4804
- return acc;
4805
- }, {});
4397
+ return Object.keys(obj).sort(function (a, b) {
4398
+ return a.localeCompare(b);
4399
+ }).reduce(function (acc, curr) {
4400
+ acc[curr] = obj[curr];
4401
+ return acc;
4402
+ }, {});
4806
4403
  }
4807
-
4808
4404
  var requestBuilder = {
4809
4405
  /**
4810
4406
  * Get all the queries to send to the client, those queries can used directly
4811
4407
  * with the Algolia client.
4812
4408
  * @private
4409
+ * @param {string} index The name of the index
4410
+ * @param {SearchParameters} state The state from which to get the queries
4813
4411
  * @return {object[]} The queries
4814
4412
  */
4815
4413
  _getQueries: function getQueries(index, state) {
@@ -4822,7 +4420,7 @@
4822
4420
  });
4823
4421
 
4824
4422
  // One for each disjunctive facets
4825
- state.getRefinedDisjunctiveFacets().forEach(function(refinedFacet) {
4423
+ state.getRefinedDisjunctiveFacets().forEach(function (refinedFacet) {
4826
4424
  queries.push({
4827
4425
  indexName: index,
4828
4426
  params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet)
@@ -4830,7 +4428,7 @@
4830
4428
  });
4831
4429
 
4832
4430
  // More to get the parent levels of the hierarchical facets when refined
4833
- state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
4431
+ state.getRefinedHierarchicalFacets().forEach(function (refinedFacet) {
4834
4432
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
4835
4433
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
4836
4434
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
@@ -4839,75 +4437,58 @@
4839
4437
  // we want to get all parent values
4840
4438
  if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
4841
4439
  // We generate a map of the filters we will use for our facet values queries
4842
- var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
4843
- function createFiltersMap(map, segment, level) {
4844
- return map.concat({
4845
- attribute: hierarchicalFacet.attributes[level],
4846
- value: level === 0
4847
- ? segment
4848
- : [map[map.length - 1].value, segment].join(separator)
4849
- });
4850
- }
4851
- , []);
4852
-
4853
- filtersMap.forEach(function(filter, level) {
4854
- var params = requestBuilder._getDisjunctiveFacetSearchParams(
4855
- state,
4856
- filter.attribute,
4857
- level === 0
4858
- );
4440
+ var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(function createFiltersMap(map, segment, level) {
4441
+ return map.concat({
4442
+ attribute: hierarchicalFacet.attributes[level],
4443
+ value: level === 0 ? segment : [map[map.length - 1].value, segment].join(separator)
4444
+ });
4445
+ }, []);
4446
+ filtersMap.forEach(function (filter, level) {
4447
+ var params = requestBuilder._getDisjunctiveFacetSearchParams(state, filter.attribute, level === 0);
4859
4448
 
4860
4449
  // Keep facet filters unrelated to current hierarchical attributes
4861
4450
  function hasHierarchicalFacetFilter(value) {
4862
- return hierarchicalFacet.attributes.some(function(attribute) {
4451
+ return hierarchicalFacet.attributes.some(function (attribute) {
4863
4452
  return attribute === value.split(':')[0];
4864
4453
  });
4865
4454
  }
4866
-
4867
- var filteredFacetFilters = (params.facetFilters || []).reduce(function(acc, facetFilter) {
4455
+ var filteredFacetFilters = (params.facetFilters || []).reduce(function (acc, facetFilter) {
4868
4456
  if (Array.isArray(facetFilter)) {
4869
- var filtered = facetFilter.filter(function(filterValue) {
4457
+ var filtered = facetFilter.filter(function (filterValue) {
4870
4458
  return !hasHierarchicalFacetFilter(filterValue);
4871
4459
  });
4872
-
4873
4460
  if (filtered.length > 0) {
4874
4461
  acc.push(filtered);
4875
4462
  }
4876
4463
  }
4877
-
4878
4464
  if (typeof facetFilter === 'string' && !hasHierarchicalFacetFilter(facetFilter)) {
4879
4465
  acc.push(facetFilter);
4880
4466
  }
4881
-
4882
4467
  return acc;
4883
4468
  }, []);
4884
-
4885
4469
  var parent = filtersMap[level - 1];
4886
4470
  if (level > 0) {
4887
4471
  params.facetFilters = filteredFacetFilters.concat(parent.attribute + ':' + parent.value);
4888
4472
  } else {
4889
4473
  params.facetFilters = filteredFacetFilters.length > 0 ? filteredFacetFilters : undefined;
4890
4474
  }
4891
-
4892
- queries.push({indexName: index, params: params});
4475
+ queries.push({
4476
+ indexName: index,
4477
+ params: params
4478
+ });
4893
4479
  });
4894
4480
  }
4895
4481
  });
4896
-
4897
4482
  return queries;
4898
4483
  },
4899
-
4900
4484
  /**
4901
4485
  * Build search parameters used to fetch hits
4902
4486
  * @private
4903
- * @return {object.<string, any>}
4487
+ * @param {SearchParameters} state The state from which to get the queries
4488
+ * @return {object.<string, any>} The search parameters for hits
4904
4489
  */
4905
- _getHitsSearchParams: function(state) {
4906
- var facets = state.facets
4907
- .concat(state.disjunctiveFacets)
4908
- .concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
4909
-
4910
-
4490
+ _getHitsSearchParams: function _getHitsSearchParams(state) {
4491
+ var facets = state.facets.concat(state.disjunctiveFacets).concat(requestBuilder._getHitsHierarchicalFacetsAttributes(state));
4911
4492
  var facetFilters = requestBuilder._getFacetFilters(state);
4912
4493
  var numericFilters = requestBuilder._getNumericFilters(state);
4913
4494
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -4915,26 +4496,23 @@
4915
4496
  facets: facets.indexOf('*') > -1 ? ['*'] : facets,
4916
4497
  tagFilters: tagFilters
4917
4498
  };
4918
-
4919
4499
  if (facetFilters.length > 0) {
4920
4500
  additionalParams.facetFilters = facetFilters;
4921
4501
  }
4922
-
4923
4502
  if (numericFilters.length > 0) {
4924
4503
  additionalParams.numericFilters = numericFilters;
4925
4504
  }
4926
-
4927
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
4505
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
4928
4506
  },
4929
-
4930
4507
  /**
4931
4508
  * Build search parameters used to fetch a disjunctive facet
4932
4509
  * @private
4510
+ * @param {SearchParameters} state The state from which to get the queries
4933
4511
  * @param {string} facet the associated facet name
4934
4512
  * @param {boolean} hierarchicalRootLevel ?? FIXME
4935
- * @return {object}
4513
+ * @return {object} The search parameters for a disjunctive facet
4936
4514
  */
4937
- _getDisjunctiveFacetSearchParams: function(state, facet, hierarchicalRootLevel) {
4515
+ _getDisjunctiveFacetSearchParams: function _getDisjunctiveFacetSearchParams(state, facet, hierarchicalRootLevel) {
4938
4516
  var facetFilters = requestBuilder._getFacetFilters(state, facet, hierarchicalRootLevel);
4939
4517
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
4940
4518
  var tagFilters = requestBuilder._getTagFilters(state);
@@ -4944,55 +4522,43 @@
4944
4522
  analytics: false,
4945
4523
  clickAnalytics: false
4946
4524
  };
4947
-
4948
4525
  if (tagFilters.length > 0) {
4949
4526
  additionalParams.tagFilters = tagFilters;
4950
4527
  }
4951
-
4952
4528
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
4953
-
4954
4529
  if (hierarchicalFacet) {
4955
- additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(
4956
- state,
4957
- hierarchicalFacet,
4958
- hierarchicalRootLevel
4959
- );
4530
+ additionalParams.facets = requestBuilder._getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, hierarchicalRootLevel);
4960
4531
  } else {
4961
4532
  additionalParams.facets = facet;
4962
4533
  }
4963
-
4964
4534
  if (numericFilters.length > 0) {
4965
4535
  additionalParams.numericFilters = numericFilters;
4966
4536
  }
4967
-
4968
4537
  if (facetFilters.length > 0) {
4969
4538
  additionalParams.facetFilters = facetFilters;
4970
4539
  }
4971
-
4972
- return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
4540
+ return sortObject(merge$1({}, state.getQueryParams(), additionalParams));
4973
4541
  },
4974
-
4975
4542
  /**
4976
4543
  * Return the numeric filters in an algolia request fashion
4977
4544
  * @private
4545
+ * @param {SearchParameters} state the state from which to get the filters
4978
4546
  * @param {string} [facetName] the name of the attribute for which the filters should be excluded
4979
4547
  * @return {string[]} the numeric filters in the algolia format
4980
4548
  */
4981
- _getNumericFilters: function(state, facetName) {
4549
+ _getNumericFilters: function _getNumericFilters(state, facetName) {
4982
4550
  if (state.numericFilters) {
4983
4551
  return state.numericFilters;
4984
4552
  }
4985
-
4986
4553
  var numericFilters = [];
4987
-
4988
- Object.keys(state.numericRefinements).forEach(function(attribute) {
4554
+ Object.keys(state.numericRefinements).forEach(function (attribute) {
4989
4555
  var operators = state.numericRefinements[attribute] || {};
4990
- Object.keys(operators).forEach(function(operator) {
4556
+ Object.keys(operators).forEach(function (operator) {
4991
4557
  var values = operators[operator] || [];
4992
4558
  if (facetName !== attribute) {
4993
- values.forEach(function(value) {
4559
+ values.forEach(function (value) {
4994
4560
  if (Array.isArray(value)) {
4995
- var vs = value.map(function(v) {
4561
+ var vs = value.map(function (v) {
4996
4562
  return attribute + operator + v;
4997
4563
  });
4998
4564
  numericFilters.push(vs);
@@ -5003,74 +4569,64 @@
5003
4569
  }
5004
4570
  });
5005
4571
  });
5006
-
5007
4572
  return numericFilters;
5008
4573
  },
5009
-
5010
4574
  /**
5011
- * Return the tags filters depending
4575
+ * Return the tags filters depending on which format is used, either tagFilters or tagRefinements
5012
4576
  * @private
5013
- * @return {string}
4577
+ * @param {SearchParameters} state the state from which to get the filters
4578
+ * @return {string} Tag filters in a single string
5014
4579
  */
5015
- _getTagFilters: function(state) {
4580
+ _getTagFilters: function _getTagFilters(state) {
5016
4581
  if (state.tagFilters) {
5017
4582
  return state.tagFilters;
5018
4583
  }
5019
-
5020
4584
  return state.tagRefinements.join(',');
5021
4585
  },
5022
-
5023
-
5024
4586
  /**
5025
4587
  * Build facetFilters parameter based on current refinements. The array returned
5026
4588
  * contains strings representing the facet filters in the algolia format.
5027
4589
  * @private
4590
+ * @param {SearchParameters} state The state from which to get the queries
5028
4591
  * @param {string} [facet] if set, the current disjunctive facet
5029
- * @return {array.<string>}
4592
+ * @param {boolean} [hierarchicalRootLevel] ?? FIXME
4593
+ * @return {array.<string>} The facet filters in the algolia format
5030
4594
  */
5031
- _getFacetFilters: function(state, facet, hierarchicalRootLevel) {
4595
+ _getFacetFilters: function _getFacetFilters(state, facet, hierarchicalRootLevel) {
5032
4596
  var facetFilters = [];
5033
-
5034
4597
  var facetsRefinements = state.facetsRefinements || {};
5035
- Object.keys(facetsRefinements).forEach(function(facetName) {
4598
+ Object.keys(facetsRefinements).forEach(function (facetName) {
5036
4599
  var facetValues = facetsRefinements[facetName] || [];
5037
- facetValues.forEach(function(facetValue) {
4600
+ facetValues.forEach(function (facetValue) {
5038
4601
  facetFilters.push(facetName + ':' + facetValue);
5039
4602
  });
5040
4603
  });
5041
-
5042
4604
  var facetsExcludes = state.facetsExcludes || {};
5043
- Object.keys(facetsExcludes).forEach(function(facetName) {
4605
+ Object.keys(facetsExcludes).forEach(function (facetName) {
5044
4606
  var facetValues = facetsExcludes[facetName] || [];
5045
- facetValues.forEach(function(facetValue) {
4607
+ facetValues.forEach(function (facetValue) {
5046
4608
  facetFilters.push(facetName + ':-' + facetValue);
5047
4609
  });
5048
4610
  });
5049
-
5050
4611
  var disjunctiveFacetsRefinements = state.disjunctiveFacetsRefinements || {};
5051
- Object.keys(disjunctiveFacetsRefinements).forEach(function(facetName) {
4612
+ Object.keys(disjunctiveFacetsRefinements).forEach(function (facetName) {
5052
4613
  var facetValues = disjunctiveFacetsRefinements[facetName] || [];
5053
4614
  if (facetName === facet || !facetValues || facetValues.length === 0) {
5054
4615
  return;
5055
4616
  }
5056
4617
  var orFilters = [];
5057
-
5058
- facetValues.forEach(function(facetValue) {
4618
+ facetValues.forEach(function (facetValue) {
5059
4619
  orFilters.push(facetName + ':' + facetValue);
5060
4620
  });
5061
-
5062
4621
  facetFilters.push(orFilters);
5063
4622
  });
5064
-
5065
4623
  var hierarchicalFacetsRefinements = state.hierarchicalFacetsRefinements || {};
5066
- Object.keys(hierarchicalFacetsRefinements).forEach(function(facetName) {
4624
+ Object.keys(hierarchicalFacetsRefinements).forEach(function (facetName) {
5067
4625
  var facetValues = hierarchicalFacetsRefinements[facetName] || [];
5068
4626
  var facetValue = facetValues[0];
5069
-
5070
4627
  if (facetValue === undefined) {
5071
4628
  return;
5072
4629
  }
5073
-
5074
4630
  var hierarchicalFacet = state.getHierarchicalFacetByName(facetName);
5075
4631
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5076
4632
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
@@ -5081,11 +4637,9 @@
5081
4637
  if (facet === facetName) {
5082
4638
  // if we are at the root level already, no need to ask for facet values, we get them from
5083
4639
  // the hits query
5084
- if (facetValue.indexOf(separator) === -1 || (!rootPath && hierarchicalRootLevel === true) ||
5085
- (rootPath && rootPath.split(separator).length === facetValue.split(separator).length)) {
4640
+ if (facetValue.indexOf(separator) === -1 || !rootPath && hierarchicalRootLevel === true || rootPath && rootPath.split(separator).length === facetValue.split(separator).length) {
5086
4641
  return;
5087
4642
  }
5088
-
5089
4643
  if (!rootPath) {
5090
4644
  attributesIndex = facetValue.split(separator).length - 2;
5091
4645
  facetValue = facetValue.slice(0, facetValue.lastIndexOf(separator));
@@ -5093,56 +4647,45 @@
5093
4647
  attributesIndex = rootPath.split(separator).length - 1;
5094
4648
  facetValue = rootPath;
5095
4649
  }
5096
-
5097
4650
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
5098
4651
  } else {
5099
4652
  attributesIndex = facetValue.split(separator).length - 1;
5100
-
5101
4653
  attributeToRefine = hierarchicalFacet.attributes[attributesIndex];
5102
4654
  }
5103
-
5104
4655
  if (attributeToRefine) {
5105
4656
  facetFilters.push([attributeToRefine + ':' + facetValue]);
5106
4657
  }
5107
4658
  });
5108
-
5109
4659
  return facetFilters;
5110
4660
  },
5111
-
5112
- _getHitsHierarchicalFacetsAttributes: function(state) {
4661
+ _getHitsHierarchicalFacetsAttributes: function _getHitsHierarchicalFacetsAttributes(state) {
5113
4662
  var out = [];
5114
-
5115
4663
  return state.hierarchicalFacets.reduce(
5116
- // ask for as much levels as there's hierarchical refinements
5117
- function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
5118
- var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
5119
-
5120
- // if no refinement, ask for root level
5121
- if (!hierarchicalRefinement) {
5122
- allAttributes.push(hierarchicalFacet.attributes[0]);
5123
- return allAttributes;
5124
- }
5125
-
5126
- var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5127
- var level = hierarchicalRefinement.split(separator).length;
5128
- var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
5129
-
5130
- return allAttributes.concat(newAttributes);
5131
- }, out);
4664
+ // ask for as much levels as there's hierarchical refinements
4665
+ function getHitsAttributesForHierarchicalFacet(allAttributes, hierarchicalFacet) {
4666
+ var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0];
4667
+
4668
+ // if no refinement, ask for root level
4669
+ if (!hierarchicalRefinement) {
4670
+ allAttributes.push(hierarchicalFacet.attributes[0]);
4671
+ return allAttributes;
4672
+ }
4673
+ var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
4674
+ var level = hierarchicalRefinement.split(separator).length;
4675
+ var newAttributes = hierarchicalFacet.attributes.slice(0, level + 1);
4676
+ return allAttributes.concat(newAttributes);
4677
+ }, out);
5132
4678
  },
5133
-
5134
- _getDisjunctiveHierarchicalFacetAttribute: function(state, hierarchicalFacet, rootLevel) {
4679
+ _getDisjunctiveHierarchicalFacetAttribute: function _getDisjunctiveHierarchicalFacetAttribute(state, hierarchicalFacet, rootLevel) {
5135
4680
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
5136
4681
  if (rootLevel === true) {
5137
4682
  var rootPath = state._getHierarchicalRootPath(hierarchicalFacet);
5138
4683
  var attributeIndex = 0;
5139
-
5140
4684
  if (rootPath) {
5141
4685
  attributeIndex = rootPath.split(separator).length;
5142
4686
  }
5143
4687
  return [hierarchicalFacet.attributes[attributeIndex]];
5144
4688
  }
5145
-
5146
4689
  var hierarchicalRefinement = state.getHierarchicalRefinement(hierarchicalFacet.name)[0] || '';
5147
4690
  // if refinement is 'beers > IPA > Flying dog',
5148
4691
  // then we want `facets: ['beers > IPA']` as disjunctive facet (parent level values)
@@ -5150,11 +4693,8 @@
5150
4693
  var parentLevel = hierarchicalRefinement.split(separator).length - 1;
5151
4694
  return hierarchicalFacet.attributes.slice(0, parentLevel + 1);
5152
4695
  },
5153
-
5154
- getSearchForFacetQuery: function(facetName, query, maxFacetHits, state) {
5155
- var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ?
5156
- state.clearRefinements(facetName) :
5157
- state;
4696
+ getSearchForFacetQuery: function getSearchForFacetQuery(facetName, query, maxFacetHits, state) {
4697
+ var stateForSearchForFacetValues = state.isDisjunctiveFacet(facetName) ? state.clearRefinements(facetName) : state;
5158
4698
  var searchForFacetSearchParameters = {
5159
4699
  facetQuery: query,
5160
4700
  facetName: facetName
@@ -5162,17 +4702,12 @@
5162
4702
  if (typeof maxFacetHits === 'number') {
5163
4703
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
5164
4704
  }
5165
- return sortObject(merge_1(
5166
- {},
5167
- requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
5168
- searchForFacetSearchParameters
5169
- ));
4705
+ return sortObject(merge$1({}, requestBuilder._getHitsSearchParams(stateForSearchForFacetValues), searchForFacetSearchParameters));
5170
4706
  }
5171
4707
  };
5172
-
5173
4708
  var requestBuilder_1 = requestBuilder;
5174
4709
 
5175
- var version$1 = '3.13.2';
4710
+ var version$1 = '3.13.3';
5176
4711
 
5177
4712
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
5178
4713
 
@@ -5283,7 +4818,6 @@
5283
4818
  if (typeof client.addAlgoliaAgent === 'function') {
5284
4819
  client.addAlgoliaAgent('JS Helper (' + version$1 + ')');
5285
4820
  }
5286
-
5287
4821
  this.setClient(client);
5288
4822
  var opts = options || {};
5289
4823
  opts.index = index;
@@ -5294,7 +4828,6 @@
5294
4828
  this.derivedHelpers = [];
5295
4829
  this._currentNbQueries = 0;
5296
4830
  }
5297
-
5298
4831
  inherits_1(AlgoliaSearchHelper, events);
5299
4832
 
5300
4833
  /**
@@ -5302,19 +4835,22 @@
5302
4835
  * method is called, it triggers a `search` event. The results will
5303
4836
  * be available through the `result` event. If an error occurs, an
5304
4837
  * `error` will be fired instead.
5305
- * @return {AlgoliaSearchHelper}
4838
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5306
4839
  * @fires search
5307
4840
  * @fires result
5308
4841
  * @fires error
5309
4842
  * @chainable
5310
4843
  */
5311
- AlgoliaSearchHelper.prototype.search = function() {
5312
- this._search({onlyWithDerivedHelpers: false});
4844
+ AlgoliaSearchHelper.prototype.search = function () {
4845
+ this._search({
4846
+ onlyWithDerivedHelpers: false
4847
+ });
5313
4848
  return this;
5314
4849
  };
5315
-
5316
- AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function() {
5317
- this._search({onlyWithDerivedHelpers: true});
4850
+ AlgoliaSearchHelper.prototype.searchOnlyWithDerivedHelpers = function () {
4851
+ this._search({
4852
+ onlyWithDerivedHelpers: true
4853
+ });
5318
4854
  return this;
5319
4855
  };
5320
4856
 
@@ -5323,7 +4859,7 @@
5323
4859
  * for the hits
5324
4860
  * @return {object} Query Parameters
5325
4861
  */
5326
- AlgoliaSearchHelper.prototype.getQuery = function() {
4862
+ AlgoliaSearchHelper.prototype.getQuery = function () {
5327
4863
  var state = this.state;
5328
4864
  return requestBuilder_1._getHitsSearchParams(state);
5329
4865
  };
@@ -5335,7 +4871,7 @@
5335
4871
  * same as a search call before calling searchOnce.
5336
4872
  * @param {object} options can contain all the parameters that can be set to SearchParameters
5337
4873
  * plus the index
5338
- * @param {function} [callback] optional callback executed when the response from the
4874
+ * @param {function} [cb] optional callback executed when the response from the
5339
4875
  * server is back.
5340
4876
  * @return {promise|undefined} if a callback is passed the method returns undefined
5341
4877
  * otherwise it returns a promise containing an object with two keys :
@@ -5364,41 +4900,32 @@
5364
4900
  * // }
5365
4901
  * }
5366
4902
  */
5367
- AlgoliaSearchHelper.prototype.searchOnce = function(options, cb) {
4903
+ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
5368
4904
  var tempState = !options ? this.state : this.state.setQueryParameters(options);
5369
4905
  var queries = requestBuilder_1._getQueries(tempState.index, tempState);
4906
+ // eslint-disable-next-line consistent-this
5370
4907
  var self = this;
5371
-
5372
4908
  this._currentNbQueries++;
5373
-
5374
4909
  this.emit('searchOnce', {
5375
4910
  state: tempState
5376
4911
  });
5377
-
5378
4912
  if (cb) {
5379
- this.client
5380
- .search(queries)
5381
- .then(function(content) {
5382
- self._currentNbQueries--;
5383
- if (self._currentNbQueries === 0) {
5384
- self.emit('searchQueueEmpty');
5385
- }
5386
-
5387
- cb(null, new SearchResults_1(tempState, content.results), tempState);
5388
- })
5389
- .catch(function(err) {
5390
- self._currentNbQueries--;
5391
- if (self._currentNbQueries === 0) {
5392
- self.emit('searchQueueEmpty');
5393
- }
5394
-
5395
- cb(err, null, tempState);
5396
- });
5397
-
4913
+ this.client.search(queries).then(function (content) {
4914
+ self._currentNbQueries--;
4915
+ if (self._currentNbQueries === 0) {
4916
+ self.emit('searchQueueEmpty');
4917
+ }
4918
+ cb(null, new SearchResults_1(tempState, content.results), tempState);
4919
+ }).catch(function (err) {
4920
+ self._currentNbQueries--;
4921
+ if (self._currentNbQueries === 0) {
4922
+ self.emit('searchQueueEmpty');
4923
+ }
4924
+ cb(err, null, tempState);
4925
+ });
5398
4926
  return undefined;
5399
4927
  }
5400
-
5401
- return this.client.search(queries).then(function(content) {
4928
+ return this.client.search(queries).then(function (content) {
5402
4929
  self._currentNbQueries--;
5403
4930
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5404
4931
  return {
@@ -5406,14 +4933,14 @@
5406
4933
  state: tempState,
5407
4934
  _originalResponse: content
5408
4935
  };
5409
- }, function(e) {
4936
+ }, function (e) {
5410
4937
  self._currentNbQueries--;
5411
4938
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5412
4939
  throw e;
5413
4940
  });
5414
4941
  };
5415
4942
 
5416
- /**
4943
+ /**
5417
4944
  * Start the search for answers with the parameters set in the state.
5418
4945
  * This method returns a promise.
5419
4946
  * @param {Object} options - the options for answers API call
@@ -5424,7 +4951,8 @@
5424
4951
  * @return {promise} the answer results
5425
4952
  * @deprecated answers is deprecated and will be replaced with new initiatives
5426
4953
  */
5427
- AlgoliaSearchHelper.prototype.findAnswers = function(options) {
4954
+ AlgoliaSearchHelper.prototype.findAnswers = function (options) {
4955
+ // eslint-disable-next-line no-console
5428
4956
  console.warn('[algoliasearch-helper] answers is no longer supported');
5429
4957
  var state = this.state;
5430
4958
  var derivedHelper = this.derivedHelpers[0];
@@ -5432,21 +4960,12 @@
5432
4960
  return Promise.resolve([]);
5433
4961
  }
5434
4962
  var derivedState = derivedHelper.getModifiedState(state);
5435
- var data = merge_1(
5436
- {
5437
- attributesForPrediction: options.attributesForPrediction,
5438
- nbHits: options.nbHits
5439
- },
5440
- {
5441
- params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), [
5442
- 'attributesToSnippet',
5443
- 'hitsPerPage',
5444
- 'restrictSearchableAttributes',
5445
- 'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
5446
- ])
5447
- }
5448
- );
5449
-
4963
+ var data = merge$1({
4964
+ attributesForPrediction: options.attributesForPrediction,
4965
+ nbHits: options.nbHits
4966
+ }, {
4967
+ params: omit$1(requestBuilder_1._getHitsSearchParams(derivedState), ['attributesToSnippet', 'hitsPerPage', 'restrictSearchableAttributes', 'snippetEllipsisText'])
4968
+ });
5450
4969
  var errorMessage = 'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
5451
4970
  if (typeof this.client.initIndex !== 'function') {
5452
4971
  throw new Error(errorMessage);
@@ -5492,75 +5011,56 @@
5492
5011
  * it in the generated query.
5493
5012
  * @return {promise.<FacetSearchResult>} the results of the search
5494
5013
  */
5495
- AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
5014
+ AlgoliaSearchHelper.prototype.searchForFacetValues = function (facet, query, maxFacetHits, userState) {
5496
5015
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
5497
5016
  var clientHasInitIndex = typeof this.client.initIndex === 'function';
5498
- if (
5499
- !clientHasSFFV &&
5500
- !clientHasInitIndex &&
5501
- typeof this.client.search !== 'function'
5502
- ) {
5503
- throw new Error(
5504
- 'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
5505
- );
5017
+ if (!clientHasSFFV && !clientHasInitIndex && typeof this.client.search !== 'function') {
5018
+ throw new Error('search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues');
5506
5019
  }
5507
-
5508
5020
  var state = this.state.setQueryParameters(userState || {});
5509
5021
  var isDisjunctive = state.isDisjunctiveFacet(facet);
5510
5022
  var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
5511
-
5512
5023
  this._currentNbQueries++;
5024
+ // eslint-disable-next-line consistent-this
5513
5025
  var self = this;
5514
5026
  var searchForFacetValuesPromise;
5515
5027
  // newer algoliasearch ^3.27.1 - ~4.0.0
5516
5028
  if (clientHasSFFV) {
5517
- searchForFacetValuesPromise = this.client.searchForFacetValues([
5518
- {indexName: state.index, params: algoliaQuery}
5519
- ]);
5029
+ searchForFacetValuesPromise = this.client.searchForFacetValues([{
5030
+ indexName: state.index,
5031
+ params: algoliaQuery
5032
+ }]);
5520
5033
  // algoliasearch < 3.27.1
5521
5034
  } else if (clientHasInitIndex) {
5522
- searchForFacetValuesPromise = this.client
5523
- .initIndex(state.index)
5524
- .searchForFacetValues(algoliaQuery);
5035
+ searchForFacetValuesPromise = this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
5525
5036
  // algoliasearch ~5.0.0
5526
5037
  } else {
5527
5038
  // @MAJOR only use client.search
5528
5039
  delete algoliaQuery.facetName;
5529
- searchForFacetValuesPromise = this.client
5530
- .search([
5531
- {
5532
- type: 'facet',
5533
- facet: facet,
5534
- indexName: state.index,
5535
- params: algoliaQuery
5536
- }
5537
- ])
5538
- .then(function processResponse(response) {
5539
- return response.results[0];
5540
- });
5040
+ searchForFacetValuesPromise = this.client.search([{
5041
+ type: 'facet',
5042
+ facet: facet,
5043
+ indexName: state.index,
5044
+ params: algoliaQuery
5045
+ }]).then(function processResponse(response) {
5046
+ return response.results[0];
5047
+ });
5541
5048
  }
5542
-
5543
5049
  this.emit('searchForFacetValues', {
5544
5050
  state: state,
5545
5051
  facet: facet,
5546
5052
  query: query
5547
5053
  });
5548
-
5549
5054
  return searchForFacetValuesPromise.then(function addIsRefined(content) {
5550
5055
  self._currentNbQueries--;
5551
5056
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5552
-
5553
5057
  content = Array.isArray(content) ? content[0] : content;
5554
-
5555
- content.facetHits.forEach(function(f) {
5058
+ content.facetHits.forEach(function (f) {
5556
5059
  f.escapedValue = escapeFacetValue$3(f.value);
5557
- f.isRefined = isDisjunctive
5558
- ? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
5559
- : state.isFacetRefined(facet, f.escapedValue);
5060
+ f.isRefined = isDisjunctive ? state.isDisjunctiveFacetRefined(facet, f.escapedValue) : state.isFacetRefined(facet, f.escapedValue);
5560
5061
  });
5561
-
5562
5062
  return content;
5563
- }, function(e) {
5063
+ }, function (e) {
5564
5064
  self._currentNbQueries--;
5565
5065
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
5566
5066
  throw e;
@@ -5572,16 +5072,15 @@
5572
5072
  *
5573
5073
  * This method resets the current page to 0.
5574
5074
  * @param {string} q the user query
5575
- * @return {AlgoliaSearchHelper}
5075
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5576
5076
  * @fires change
5577
5077
  * @chainable
5578
5078
  */
5579
- AlgoliaSearchHelper.prototype.setQuery = function(q) {
5079
+ AlgoliaSearchHelper.prototype.setQuery = function (q) {
5580
5080
  this._change({
5581
5081
  state: this.state.resetPage().setQuery(q),
5582
5082
  isPageReset: true
5583
5083
  });
5584
-
5585
5084
  return this;
5586
5085
  };
5587
5086
 
@@ -5593,7 +5092,7 @@
5593
5092
  *
5594
5093
  * This method resets the current page to 0.
5595
5094
  * @param {string} [name] optional name of the facet / attribute on which we want to remove all refinements
5596
- * @return {AlgoliaSearchHelper}
5095
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5597
5096
  * @fires change
5598
5097
  * @chainable
5599
5098
  * @example
@@ -5608,12 +5107,11 @@
5608
5107
  * return type === 'exclude' && attribute === 'category';
5609
5108
  * }).search();
5610
5109
  */
5611
- AlgoliaSearchHelper.prototype.clearRefinements = function(name) {
5110
+ AlgoliaSearchHelper.prototype.clearRefinements = function (name) {
5612
5111
  this._change({
5613
5112
  state: this.state.resetPage().clearRefinements(name),
5614
5113
  isPageReset: true
5615
5114
  });
5616
-
5617
5115
  return this;
5618
5116
  };
5619
5117
 
@@ -5621,16 +5119,15 @@
5621
5119
  * Remove all the tag filters.
5622
5120
  *
5623
5121
  * This method resets the current page to 0.
5624
- * @return {AlgoliaSearchHelper}
5122
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5625
5123
  * @fires change
5626
5124
  * @chainable
5627
5125
  */
5628
- AlgoliaSearchHelper.prototype.clearTags = function() {
5126
+ AlgoliaSearchHelper.prototype.clearTags = function () {
5629
5127
  this._change({
5630
5128
  state: this.state.resetPage().clearTags(),
5631
5129
  isPageReset: true
5632
5130
  });
5633
-
5634
5131
  return this;
5635
5132
  };
5636
5133
 
@@ -5641,23 +5138,23 @@
5641
5138
  * This method resets the current page to 0.
5642
5139
  * @param {string} facet the facet to refine
5643
5140
  * @param {string} value the associated value (will be converted to string)
5644
- * @return {AlgoliaSearchHelper}
5141
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5645
5142
  * @fires change
5646
5143
  * @chainable
5647
5144
  */
5648
- AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function(facet, value) {
5145
+ AlgoliaSearchHelper.prototype.addDisjunctiveFacetRefinement = function (facet, value) {
5649
5146
  this._change({
5650
5147
  state: this.state.resetPage().addDisjunctiveFacetRefinement(facet, value),
5651
5148
  isPageReset: true
5652
5149
  });
5653
-
5654
5150
  return this;
5655
5151
  };
5656
5152
 
5153
+ // eslint-disable-next-line valid-jsdoc
5657
5154
  /**
5658
5155
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
5659
5156
  */
5660
- AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function() {
5157
+ AlgoliaSearchHelper.prototype.addDisjunctiveRefine = function () {
5661
5158
  return this.addDisjunctiveFacetRefinement.apply(this, arguments);
5662
5159
  };
5663
5160
 
@@ -5669,17 +5166,16 @@
5669
5166
  * This method resets the current page to 0.
5670
5167
  * @param {string} facet the facet name
5671
5168
  * @param {string} path the hierarchical facet path
5672
- * @return {AlgoliaSearchHelper}
5169
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5673
5170
  * @throws Error if the facet is not defined or if the facet is refined
5674
5171
  * @chainable
5675
5172
  * @fires change
5676
5173
  */
5677
- AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function(facet, value) {
5174
+ AlgoliaSearchHelper.prototype.addHierarchicalFacetRefinement = function (facet, path) {
5678
5175
  this._change({
5679
- state: this.state.resetPage().addHierarchicalFacetRefinement(facet, value),
5176
+ state: this.state.resetPage().addHierarchicalFacetRefinement(facet, path),
5680
5177
  isPageReset: true
5681
5178
  });
5682
-
5683
5179
  return this;
5684
5180
  };
5685
5181
 
@@ -5691,16 +5187,15 @@
5691
5187
  * @param {string} attribute the attribute on which the numeric filter applies
5692
5188
  * @param {string} operator the operator of the filter
5693
5189
  * @param {number} value the value of the filter
5694
- * @return {AlgoliaSearchHelper}
5190
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5695
5191
  * @fires change
5696
5192
  * @chainable
5697
5193
  */
5698
- AlgoliaSearchHelper.prototype.addNumericRefinement = function(attribute, operator, value) {
5194
+ AlgoliaSearchHelper.prototype.addNumericRefinement = function (attribute, operator, value) {
5699
5195
  this._change({
5700
5196
  state: this.state.resetPage().addNumericRefinement(attribute, operator, value),
5701
5197
  isPageReset: true
5702
5198
  });
5703
-
5704
5199
  return this;
5705
5200
  };
5706
5201
 
@@ -5711,27 +5206,26 @@
5711
5206
  * This method resets the current page to 0.
5712
5207
  * @param {string} facet the facet to refine
5713
5208
  * @param {string} value the associated value (will be converted to string)
5714
- * @return {AlgoliaSearchHelper}
5209
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5715
5210
  * @fires change
5716
5211
  * @chainable
5717
5212
  */
5718
- AlgoliaSearchHelper.prototype.addFacetRefinement = function(facet, value) {
5213
+ AlgoliaSearchHelper.prototype.addFacetRefinement = function (facet, value) {
5719
5214
  this._change({
5720
5215
  state: this.state.resetPage().addFacetRefinement(facet, value),
5721
5216
  isPageReset: true
5722
5217
  });
5723
-
5724
5218
  return this;
5725
5219
  };
5726
5220
 
5221
+ // eslint-disable-next-line valid-jsdoc
5727
5222
  /**
5728
5223
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
5729
5224
  */
5730
- AlgoliaSearchHelper.prototype.addRefine = function() {
5225
+ AlgoliaSearchHelper.prototype.addRefine = function () {
5731
5226
  return this.addFacetRefinement.apply(this, arguments);
5732
5227
  };
5733
5228
 
5734
-
5735
5229
  /**
5736
5230
  * Adds a an exclusion filter to a faceted attribute with the `value` provided. If the
5737
5231
  * filter is already set, it doesn't change the filters.
@@ -5739,23 +5233,23 @@
5739
5233
  * This method resets the current page to 0.
5740
5234
  * @param {string} facet the facet to refine
5741
5235
  * @param {string} value the associated value (will be converted to string)
5742
- * @return {AlgoliaSearchHelper}
5236
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5743
5237
  * @fires change
5744
5238
  * @chainable
5745
5239
  */
5746
- AlgoliaSearchHelper.prototype.addFacetExclusion = function(facet, value) {
5240
+ AlgoliaSearchHelper.prototype.addFacetExclusion = function (facet, value) {
5747
5241
  this._change({
5748
5242
  state: this.state.resetPage().addExcludeRefinement(facet, value),
5749
5243
  isPageReset: true
5750
5244
  });
5751
-
5752
5245
  return this;
5753
5246
  };
5754
5247
 
5248
+ // eslint-disable-next-line valid-jsdoc
5755
5249
  /**
5756
5250
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
5757
5251
  */
5758
- AlgoliaSearchHelper.prototype.addExclude = function() {
5252
+ AlgoliaSearchHelper.prototype.addExclude = function () {
5759
5253
  return this.addFacetExclusion.apply(this, arguments);
5760
5254
  };
5761
5255
 
@@ -5765,16 +5259,15 @@
5765
5259
  *
5766
5260
  * This method resets the current page to 0.
5767
5261
  * @param {string} tag the tag to add to the filter
5768
- * @return {AlgoliaSearchHelper}
5262
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5769
5263
  * @fires change
5770
5264
  * @chainable
5771
5265
  */
5772
- AlgoliaSearchHelper.prototype.addTag = function(tag) {
5266
+ AlgoliaSearchHelper.prototype.addTag = function (tag) {
5773
5267
  this._change({
5774
5268
  state: this.state.resetPage().addTagRefinement(tag),
5775
5269
  isPageReset: true
5776
5270
  });
5777
-
5778
5271
  return this;
5779
5272
  };
5780
5273
 
@@ -5792,16 +5285,15 @@
5792
5285
  * @param {string} attribute the attribute on which the numeric filter applies
5793
5286
  * @param {string} [operator] the operator of the filter
5794
5287
  * @param {number} [value] the value of the filter
5795
- * @return {AlgoliaSearchHelper}
5288
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5796
5289
  * @fires change
5797
5290
  * @chainable
5798
5291
  */
5799
- AlgoliaSearchHelper.prototype.removeNumericRefinement = function(attribute, operator, value) {
5292
+ AlgoliaSearchHelper.prototype.removeNumericRefinement = function (attribute, operator, value) {
5800
5293
  this._change({
5801
5294
  state: this.state.resetPage().removeNumericRefinement(attribute, operator, value),
5802
5295
  isPageReset: true
5803
5296
  });
5804
-
5805
5297
  return this;
5806
5298
  };
5807
5299
 
@@ -5815,40 +5307,39 @@
5815
5307
  * This method resets the current page to 0.
5816
5308
  * @param {string} facet the facet to refine
5817
5309
  * @param {string} [value] the associated value
5818
- * @return {AlgoliaSearchHelper}
5310
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5819
5311
  * @fires change
5820
5312
  * @chainable
5821
5313
  */
5822
- AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function(facet, value) {
5314
+ AlgoliaSearchHelper.prototype.removeDisjunctiveFacetRefinement = function (facet, value) {
5823
5315
  this._change({
5824
5316
  state: this.state.resetPage().removeDisjunctiveFacetRefinement(facet, value),
5825
5317
  isPageReset: true
5826
5318
  });
5827
-
5828
5319
  return this;
5829
5320
  };
5830
5321
 
5322
+ // eslint-disable-next-line valid-jsdoc
5831
5323
  /**
5832
5324
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
5833
5325
  */
5834
- AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function() {
5326
+ AlgoliaSearchHelper.prototype.removeDisjunctiveRefine = function () {
5835
5327
  return this.removeDisjunctiveFacetRefinement.apply(this, arguments);
5836
5328
  };
5837
5329
 
5838
5330
  /**
5839
5331
  * Removes the refinement set on a hierarchical facet.
5840
5332
  * @param {string} facet the facet name
5841
- * @return {AlgoliaSearchHelper}
5333
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5842
5334
  * @throws Error if the facet is not defined or if the facet is not refined
5843
5335
  * @fires change
5844
5336
  * @chainable
5845
5337
  */
5846
- AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function(facet) {
5338
+ AlgoliaSearchHelper.prototype.removeHierarchicalFacetRefinement = function (facet) {
5847
5339
  this._change({
5848
5340
  state: this.state.resetPage().removeHierarchicalFacetRefinement(facet),
5849
5341
  isPageReset: true
5850
5342
  });
5851
-
5852
5343
  return this;
5853
5344
  };
5854
5345
 
@@ -5862,23 +5353,23 @@
5862
5353
  * This method resets the current page to 0.
5863
5354
  * @param {string} facet the facet to refine
5864
5355
  * @param {string} [value] the associated value
5865
- * @return {AlgoliaSearchHelper}
5356
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5866
5357
  * @fires change
5867
5358
  * @chainable
5868
5359
  */
5869
- AlgoliaSearchHelper.prototype.removeFacetRefinement = function(facet, value) {
5360
+ AlgoliaSearchHelper.prototype.removeFacetRefinement = function (facet, value) {
5870
5361
  this._change({
5871
5362
  state: this.state.resetPage().removeFacetRefinement(facet, value),
5872
5363
  isPageReset: true
5873
5364
  });
5874
-
5875
5365
  return this;
5876
5366
  };
5877
5367
 
5368
+ // eslint-disable-next-line valid-jsdoc
5878
5369
  /**
5879
5370
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
5880
5371
  */
5881
- AlgoliaSearchHelper.prototype.removeRefine = function() {
5372
+ AlgoliaSearchHelper.prototype.removeRefine = function () {
5882
5373
  return this.removeFacetRefinement.apply(this, arguments);
5883
5374
  };
5884
5375
 
@@ -5892,23 +5383,23 @@
5892
5383
  * This method resets the current page to 0.
5893
5384
  * @param {string} facet the facet to refine
5894
5385
  * @param {string} [value] the associated value
5895
- * @return {AlgoliaSearchHelper}
5386
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5896
5387
  * @fires change
5897
5388
  * @chainable
5898
5389
  */
5899
- AlgoliaSearchHelper.prototype.removeFacetExclusion = function(facet, value) {
5390
+ AlgoliaSearchHelper.prototype.removeFacetExclusion = function (facet, value) {
5900
5391
  this._change({
5901
5392
  state: this.state.resetPage().removeExcludeRefinement(facet, value),
5902
5393
  isPageReset: true
5903
5394
  });
5904
-
5905
5395
  return this;
5906
5396
  };
5907
5397
 
5398
+ // eslint-disable-next-line valid-jsdoc
5908
5399
  /**
5909
5400
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
5910
5401
  */
5911
- AlgoliaSearchHelper.prototype.removeExclude = function() {
5402
+ AlgoliaSearchHelper.prototype.removeExclude = function () {
5912
5403
  return this.removeFacetExclusion.apply(this, arguments);
5913
5404
  };
5914
5405
 
@@ -5918,16 +5409,15 @@
5918
5409
  *
5919
5410
  * This method resets the current page to 0.
5920
5411
  * @param {string} tag tag to remove from the filter
5921
- * @return {AlgoliaSearchHelper}
5412
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5922
5413
  * @fires change
5923
5414
  * @chainable
5924
5415
  */
5925
- AlgoliaSearchHelper.prototype.removeTag = function(tag) {
5416
+ AlgoliaSearchHelper.prototype.removeTag = function (tag) {
5926
5417
  this._change({
5927
5418
  state: this.state.resetPage().removeTagRefinement(tag),
5928
5419
  isPageReset: true
5929
5420
  });
5930
-
5931
5421
  return this;
5932
5422
  };
5933
5423
 
@@ -5938,23 +5428,23 @@
5938
5428
  * This method resets the current page to 0.
5939
5429
  * @param {string} facet the facet to refine
5940
5430
  * @param {string} value the associated value
5941
- * @return {AlgoliaSearchHelper}
5431
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5942
5432
  * @fires change
5943
5433
  * @chainable
5944
5434
  */
5945
- AlgoliaSearchHelper.prototype.toggleFacetExclusion = function(facet, value) {
5435
+ AlgoliaSearchHelper.prototype.toggleFacetExclusion = function (facet, value) {
5946
5436
  this._change({
5947
5437
  state: this.state.resetPage().toggleExcludeFacetRefinement(facet, value),
5948
5438
  isPageReset: true
5949
5439
  });
5950
-
5951
5440
  return this;
5952
5441
  };
5953
5442
 
5443
+ // eslint-disable-next-line valid-jsdoc
5954
5444
  /**
5955
5445
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
5956
5446
  */
5957
- AlgoliaSearchHelper.prototype.toggleExclude = function() {
5447
+ AlgoliaSearchHelper.prototype.toggleExclude = function () {
5958
5448
  return this.toggleFacetExclusion.apply(this, arguments);
5959
5449
  };
5960
5450
 
@@ -5967,13 +5457,13 @@
5967
5457
  * This method resets the current page to 0.
5968
5458
  * @param {string} facet the facet to refine
5969
5459
  * @param {string} value the associated value
5970
- * @return {AlgoliaSearchHelper}
5460
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5971
5461
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
5972
5462
  * @fires change
5973
5463
  * @chainable
5974
5464
  * @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
5975
5465
  */
5976
- AlgoliaSearchHelper.prototype.toggleRefinement = function(facet, value) {
5466
+ AlgoliaSearchHelper.prototype.toggleRefinement = function (facet, value) {
5977
5467
  return this.toggleFacetRefinement(facet, value);
5978
5468
  };
5979
5469
 
@@ -5986,24 +5476,24 @@
5986
5476
  * This method resets the current page to 0.
5987
5477
  * @param {string} facet the facet to refine
5988
5478
  * @param {string} value the associated value
5989
- * @return {AlgoliaSearchHelper}
5479
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5990
5480
  * @throws Error will throw an error if the facet is not declared in the settings of the helper
5991
5481
  * @fires change
5992
5482
  * @chainable
5993
5483
  */
5994
- AlgoliaSearchHelper.prototype.toggleFacetRefinement = function(facet, value) {
5484
+ AlgoliaSearchHelper.prototype.toggleFacetRefinement = function (facet, value) {
5995
5485
  this._change({
5996
5486
  state: this.state.resetPage().toggleFacetRefinement(facet, value),
5997
5487
  isPageReset: true
5998
5488
  });
5999
-
6000
5489
  return this;
6001
5490
  };
6002
5491
 
5492
+ // eslint-disable-next-line valid-jsdoc
6003
5493
  /**
6004
5494
  * @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
6005
5495
  */
6006
- AlgoliaSearchHelper.prototype.toggleRefine = function() {
5496
+ AlgoliaSearchHelper.prototype.toggleRefine = function () {
6007
5497
  return this.toggleFacetRefinement.apply(this, arguments);
6008
5498
  };
6009
5499
 
@@ -6013,29 +5503,28 @@
6013
5503
  *
6014
5504
  * This method resets the current page to 0.
6015
5505
  * @param {string} tag tag to remove or add
6016
- * @return {AlgoliaSearchHelper}
5506
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6017
5507
  * @fires change
6018
5508
  * @chainable
6019
5509
  */
6020
- AlgoliaSearchHelper.prototype.toggleTag = function(tag) {
5510
+ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
6021
5511
  this._change({
6022
5512
  state: this.state.resetPage().toggleTagRefinement(tag),
6023
5513
  isPageReset: true
6024
5514
  });
6025
-
6026
5515
  return this;
6027
5516
  };
6028
5517
 
6029
5518
  /**
6030
5519
  * Increments the page number by one.
6031
- * @return {AlgoliaSearchHelper}
5520
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6032
5521
  * @fires change
6033
5522
  * @chainable
6034
5523
  * @example
6035
5524
  * helper.setPage(0).nextPage().getPage();
6036
5525
  * // returns 1
6037
5526
  */
6038
- AlgoliaSearchHelper.prototype.nextPage = function() {
5527
+ AlgoliaSearchHelper.prototype.nextPage = function () {
6039
5528
  var page = this.state.page || 0;
6040
5529
  return this.setPage(page + 1);
6041
5530
  };
@@ -6043,28 +5532,30 @@
6043
5532
  /**
6044
5533
  * Decrements the page number by one.
6045
5534
  * @fires change
6046
- * @return {AlgoliaSearchHelper}
5535
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6047
5536
  * @chainable
6048
5537
  * @example
6049
5538
  * helper.setPage(1).previousPage().getPage();
6050
5539
  * // returns 0
6051
5540
  */
6052
- AlgoliaSearchHelper.prototype.previousPage = function() {
5541
+ AlgoliaSearchHelper.prototype.previousPage = function () {
6053
5542
  var page = this.state.page || 0;
6054
5543
  return this.setPage(page - 1);
6055
5544
  };
6056
5545
 
6057
5546
  /**
6058
5547
  * @private
5548
+ * @param {number} page The page number
5549
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
5550
+ * @chainable
5551
+ * @fires change
6059
5552
  */
6060
5553
  function setCurrentPage(page) {
6061
5554
  if (page < 0) throw new Error('Page requested below 0.');
6062
-
6063
5555
  this._change({
6064
5556
  state: this.state.setPage(page),
6065
5557
  isPageReset: false
6066
5558
  });
6067
-
6068
5559
  return this;
6069
5560
  }
6070
5561
 
@@ -6072,7 +5563,7 @@
6072
5563
  * Change the current page
6073
5564
  * @deprecated
6074
5565
  * @param {number} page The page number
6075
- * @return {AlgoliaSearchHelper}
5566
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6076
5567
  * @fires change
6077
5568
  * @chainable
6078
5569
  */
@@ -6082,7 +5573,7 @@
6082
5573
  * Updates the current page.
6083
5574
  * @function
6084
5575
  * @param {number} page The page number
6085
- * @return {AlgoliaSearchHelper}
5576
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6086
5577
  * @fires change
6087
5578
  * @chainable
6088
5579
  */
@@ -6093,16 +5584,15 @@
6093
5584
  *
6094
5585
  * This method resets the current page to 0.
6095
5586
  * @param {string} name the index name
6096
- * @return {AlgoliaSearchHelper}
5587
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6097
5588
  * @fires change
6098
5589
  * @chainable
6099
5590
  */
6100
- AlgoliaSearchHelper.prototype.setIndex = function(name) {
5591
+ AlgoliaSearchHelper.prototype.setIndex = function (name) {
6101
5592
  this._change({
6102
5593
  state: this.state.resetPage().setIndex(name),
6103
5594
  isPageReset: true
6104
5595
  });
6105
-
6106
5596
  return this;
6107
5597
  };
6108
5598
 
@@ -6117,34 +5607,32 @@
6117
5607
  * This method resets the current page to 0.
6118
5608
  * @param {string} parameter name of the parameter to update
6119
5609
  * @param {any} value new value of the parameter
6120
- * @return {AlgoliaSearchHelper}
5610
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6121
5611
  * @fires change
6122
5612
  * @chainable
6123
5613
  * @example
6124
5614
  * helper.setQueryParameter('hitsPerPage', 20).search();
6125
5615
  */
6126
- AlgoliaSearchHelper.prototype.setQueryParameter = function(parameter, value) {
5616
+ AlgoliaSearchHelper.prototype.setQueryParameter = function (parameter, value) {
6127
5617
  this._change({
6128
5618
  state: this.state.resetPage().setQueryParameter(parameter, value),
6129
5619
  isPageReset: true
6130
5620
  });
6131
-
6132
5621
  return this;
6133
5622
  };
6134
5623
 
6135
5624
  /**
6136
5625
  * Set the whole state (warning: will erase previous state)
6137
5626
  * @param {SearchParameters} newState the whole new state
6138
- * @return {AlgoliaSearchHelper}
5627
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6139
5628
  * @fires change
6140
5629
  * @chainable
6141
5630
  */
6142
- AlgoliaSearchHelper.prototype.setState = function(newState) {
5631
+ AlgoliaSearchHelper.prototype.setState = function (newState) {
6143
5632
  this._change({
6144
5633
  state: SearchParameters_1.make(newState),
6145
5634
  isPageReset: false
6146
5635
  });
6147
-
6148
5636
  return this;
6149
5637
  };
6150
5638
 
@@ -6153,7 +5641,7 @@
6153
5641
  * Do not use this method unless you know what you are doing. (see the example
6154
5642
  * for a legit use case)
6155
5643
  * @param {SearchParameters} newState the whole new state
6156
- * @return {AlgoliaSearchHelper}
5644
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6157
5645
  * @example
6158
5646
  * helper.on('change', function(state){
6159
5647
  * // In this function you might want to find a way to store the state in the url/history
@@ -6165,7 +5653,7 @@
6165
5653
  * }
6166
5654
  * @chainable
6167
5655
  */
6168
- AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function(newState) {
5656
+ AlgoliaSearchHelper.prototype.overrideStateWithoutTriggeringChangeEvent = function (newState) {
6169
5657
  this.state = new SearchParameters_1(newState);
6170
5658
  return this;
6171
5659
  };
@@ -6193,7 +5681,7 @@
6193
5681
  * helper.hasRefinements('categories'); // true
6194
5682
  *
6195
5683
  */
6196
- AlgoliaSearchHelper.prototype.hasRefinements = function(attribute) {
5684
+ AlgoliaSearchHelper.prototype.hasRefinements = function (attribute) {
6197
5685
  if (objectHasKeys_1(this.state.getNumericRefinements(attribute))) {
6198
5686
  return true;
6199
5687
  } else if (this.state.isConjunctiveFacet(attribute)) {
@@ -6218,7 +5706,7 @@
6218
5706
  *
6219
5707
  * @param {string} facet name of the attribute for used for faceting
6220
5708
  * @param {string} [value] optional value. If passed will test that this value
6221
- * is filtering the given facet.
5709
+ * is filtering the given facet.
6222
5710
  * @return {boolean} true if refined
6223
5711
  * @example
6224
5712
  * helper.isExcludeRefined('color'); // false
@@ -6231,45 +5719,45 @@
6231
5719
  * helper.isExcludeRefined('color', 'blue') // false
6232
5720
  * helper.isExcludeRefined('color', 'red') // true
6233
5721
  */
6234
- AlgoliaSearchHelper.prototype.isExcluded = function(facet, value) {
5722
+ AlgoliaSearchHelper.prototype.isExcluded = function (facet, value) {
6235
5723
  return this.state.isExcludeRefined(facet, value);
6236
5724
  };
6237
5725
 
5726
+ // eslint-disable-next-line valid-jsdoc
6238
5727
  /**
6239
5728
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
6240
5729
  */
6241
- AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function(facet, value) {
5730
+ AlgoliaSearchHelper.prototype.isDisjunctiveRefined = function (facet, value) {
6242
5731
  return this.state.isDisjunctiveFacetRefined(facet, value);
6243
5732
  };
6244
5733
 
6245
5734
  /**
6246
5735
  * Check if the string is a currently filtering tag.
6247
5736
  * @param {string} tag tag to check
6248
- * @return {boolean}
5737
+ * @return {boolean} true if the tag is currently refined
6249
5738
  */
6250
- AlgoliaSearchHelper.prototype.hasTag = function(tag) {
5739
+ AlgoliaSearchHelper.prototype.hasTag = function (tag) {
6251
5740
  return this.state.isTagRefined(tag);
6252
5741
  };
6253
5742
 
5743
+ // eslint-disable-next-line valid-jsdoc
6254
5744
  /**
6255
5745
  * @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
6256
5746
  */
6257
- AlgoliaSearchHelper.prototype.isTagRefined = function() {
5747
+ AlgoliaSearchHelper.prototype.isTagRefined = function () {
6258
5748
  return this.hasTagRefinements.apply(this, arguments);
6259
5749
  };
6260
5750
 
6261
-
6262
5751
  /**
6263
5752
  * Get the name of the currently used index.
6264
- * @return {string}
5753
+ * @return {string} name of the index
6265
5754
  * @example
6266
5755
  * helper.setIndex('highestPrice_products').getIndex();
6267
5756
  * // returns 'highestPrice_products'
6268
5757
  */
6269
- AlgoliaSearchHelper.prototype.getIndex = function() {
5758
+ AlgoliaSearchHelper.prototype.getIndex = function () {
6270
5759
  return this.state.index;
6271
5760
  };
6272
-
6273
5761
  function getCurrentPage() {
6274
5762
  return this.state.page;
6275
5763
  }
@@ -6292,7 +5780,7 @@
6292
5780
  *
6293
5781
  * @return {string[]} The list of tags currently set.
6294
5782
  */
6295
- AlgoliaSearchHelper.prototype.getTags = function() {
5783
+ AlgoliaSearchHelper.prototype.getTags = function () {
6296
5784
  return this.state.tagRefinements;
6297
5785
  };
6298
5786
 
@@ -6340,50 +5828,41 @@
6340
5828
  * // }
6341
5829
  * // ]
6342
5830
  */
6343
- AlgoliaSearchHelper.prototype.getRefinements = function(facetName) {
5831
+ AlgoliaSearchHelper.prototype.getRefinements = function (facetName) {
6344
5832
  var refinements = [];
6345
-
6346
5833
  if (this.state.isConjunctiveFacet(facetName)) {
6347
5834
  var conjRefinements = this.state.getConjunctiveRefinements(facetName);
6348
-
6349
- conjRefinements.forEach(function(r) {
5835
+ conjRefinements.forEach(function (r) {
6350
5836
  refinements.push({
6351
5837
  value: r,
6352
5838
  type: 'conjunctive'
6353
5839
  });
6354
5840
  });
6355
-
6356
5841
  var excludeRefinements = this.state.getExcludeRefinements(facetName);
6357
-
6358
- excludeRefinements.forEach(function(r) {
5842
+ excludeRefinements.forEach(function (r) {
6359
5843
  refinements.push({
6360
5844
  value: r,
6361
5845
  type: 'exclude'
6362
5846
  });
6363
5847
  });
6364
5848
  } else if (this.state.isDisjunctiveFacet(facetName)) {
6365
- var disjRefinements = this.state.getDisjunctiveRefinements(facetName);
6366
-
6367
- disjRefinements.forEach(function(r) {
5849
+ var disjunctiveRefinements = this.state.getDisjunctiveRefinements(facetName);
5850
+ disjunctiveRefinements.forEach(function (r) {
6368
5851
  refinements.push({
6369
5852
  value: r,
6370
5853
  type: 'disjunctive'
6371
5854
  });
6372
5855
  });
6373
5856
  }
6374
-
6375
5857
  var numericRefinements = this.state.getNumericRefinements(facetName);
6376
-
6377
- Object.keys(numericRefinements).forEach(function(operator) {
5858
+ Object.keys(numericRefinements).forEach(function (operator) {
6378
5859
  var value = numericRefinements[operator];
6379
-
6380
5860
  refinements.push({
6381
5861
  value: value,
6382
5862
  operator: operator,
6383
5863
  type: 'numeric'
6384
5864
  });
6385
5865
  });
6386
-
6387
5866
  return refinements;
6388
5867
  };
6389
5868
 
@@ -6393,7 +5872,7 @@
6393
5872
  * @param {string} operator operator applied on the refined values
6394
5873
  * @return {Array.<number|number[]>} refined values
6395
5874
  */
6396
- AlgoliaSearchHelper.prototype.getNumericRefinement = function(attribute, operator) {
5875
+ AlgoliaSearchHelper.prototype.getNumericRefinement = function (attribute, operator) {
6397
5876
  return this.state.getNumericRefinement(attribute, operator);
6398
5877
  };
6399
5878
 
@@ -6402,7 +5881,7 @@
6402
5881
  * @param {string} facetName Hierarchical facet name
6403
5882
  * @return {array.<string>} the path as an array of string
6404
5883
  */
6405
- AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function(facetName) {
5884
+ AlgoliaSearchHelper.prototype.getHierarchicalFacetBreadcrumb = function (facetName) {
6406
5885
  return this.state.getHierarchicalFacetBreadcrumb(facetName);
6407
5886
  };
6408
5887
 
@@ -6411,72 +5890,60 @@
6411
5890
  /**
6412
5891
  * Perform the underlying queries
6413
5892
  * @private
6414
- * @return {undefined}
5893
+ * @param {object} options options for the query
5894
+ * @param {boolean} [options.onlyWithDerivedHelpers=false] if true, only the derived helpers will be queried
5895
+ * @return {undefined} does not return anything
6415
5896
  * @fires search
6416
5897
  * @fires result
6417
5898
  * @fires error
6418
5899
  */
6419
- AlgoliaSearchHelper.prototype._search = function(options) {
5900
+ AlgoliaSearchHelper.prototype._search = function (options) {
6420
5901
  var state = this.state;
6421
5902
  var states = [];
6422
5903
  var mainQueries = [];
6423
-
6424
5904
  if (!options.onlyWithDerivedHelpers) {
6425
5905
  mainQueries = requestBuilder_1._getQueries(state.index, state);
6426
-
6427
5906
  states.push({
6428
5907
  state: state,
6429
5908
  queriesCount: mainQueries.length,
6430
5909
  helper: this
6431
5910
  });
6432
-
6433
5911
  this.emit('search', {
6434
5912
  state: state,
6435
5913
  results: this.lastResults
6436
5914
  });
6437
5915
  }
6438
-
6439
- var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
5916
+ var derivedQueries = this.derivedHelpers.map(function (derivedHelper) {
6440
5917
  var derivedState = derivedHelper.getModifiedState(state);
6441
- var derivedStateQueries = derivedState.index
6442
- ? requestBuilder_1._getQueries(derivedState.index, derivedState)
6443
- : [];
6444
-
5918
+ var derivedStateQueries = derivedState.index ? requestBuilder_1._getQueries(derivedState.index, derivedState) : [];
6445
5919
  states.push({
6446
5920
  state: derivedState,
6447
5921
  queriesCount: derivedStateQueries.length,
6448
5922
  helper: derivedHelper
6449
5923
  });
6450
-
6451
5924
  derivedHelper.emit('search', {
6452
5925
  state: derivedState,
6453
5926
  results: derivedHelper.lastResults
6454
5927
  });
6455
-
6456
5928
  return derivedStateQueries;
6457
5929
  });
6458
-
6459
5930
  var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
6460
-
6461
5931
  var queryId = this._queryId++;
6462
5932
  this._currentNbQueries++;
6463
-
6464
5933
  if (!queries.length) {
6465
- return Promise.resolve({results: []}).then(
6466
- this._dispatchAlgoliaResponse.bind(this, states, queryId)
6467
- );
5934
+ return Promise.resolve({
5935
+ results: []
5936
+ }).then(this._dispatchAlgoliaResponse.bind(this, states, queryId));
6468
5937
  }
6469
-
6470
5938
  try {
6471
- this.client.search(queries)
6472
- .then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
6473
- .catch(this._dispatchAlgoliaError.bind(this, queryId));
5939
+ this.client.search(queries).then(this._dispatchAlgoliaResponse.bind(this, states, queryId)).catch(this._dispatchAlgoliaError.bind(this, queryId));
6474
5940
  } catch (error) {
6475
5941
  // If we reach this part, we're in an internal error state
6476
5942
  this.emit('error', {
6477
5943
  error: error
6478
5944
  });
6479
5945
  }
5946
+ return undefined;
6480
5947
  };
6481
5948
 
6482
5949
  /**
@@ -6484,33 +5951,27 @@
6484
5951
  * usable object that merge the results of all the batch requests. It will dispatch
6485
5952
  * over the different helper + derived helpers (when there are some).
6486
5953
  * @private
6487
- * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>}
6488
- * state state used for to generate the request
5954
+ * @param {array.<{SearchParameters, AlgoliaQueries, AlgoliaSearchHelper}>} states state used to generate the request
6489
5955
  * @param {number} queryId id of the current request
6490
5956
  * @param {object} content content of the response
6491
5957
  * @return {undefined}
6492
5958
  */
6493
- AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function(states, queryId, content) {
6494
- // FIXME remove the number of outdated queries discarded instead of just one
5959
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaResponse = function (states, queryId, content) {
5960
+ // @TODO remove the number of outdated queries discarded instead of just one
6495
5961
 
6496
5962
  if (queryId < this._lastQueryIdReceived) {
6497
5963
  // Outdated answer
6498
5964
  return;
6499
5965
  }
6500
-
6501
- this._currentNbQueries -= (queryId - this._lastQueryIdReceived);
5966
+ this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6502
5967
  this._lastQueryIdReceived = queryId;
6503
-
6504
5968
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6505
-
6506
5969
  var results = content.results.slice();
6507
-
6508
- states.forEach(function(s) {
5970
+ states.forEach(function (s) {
6509
5971
  var state = s.state;
6510
5972
  var queriesCount = s.queriesCount;
6511
5973
  var helper = s.helper;
6512
5974
  var specificResults = results.splice(0, queriesCount);
6513
-
6514
5975
  if (!state.index) {
6515
5976
  helper.emit('result', {
6516
5977
  results: null,
@@ -6518,57 +5979,43 @@
6518
5979
  });
6519
5980
  return;
6520
5981
  }
6521
-
6522
- var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
6523
-
5982
+ helper.lastResults = new SearchResults_1(state, specificResults);
6524
5983
  helper.emit('result', {
6525
- results: formattedResponse,
5984
+ results: helper.lastResults,
6526
5985
  state: state
6527
5986
  });
6528
5987
  });
6529
5988
  };
6530
-
6531
- AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function(queryId, error) {
5989
+ AlgoliaSearchHelper.prototype._dispatchAlgoliaError = function (queryId, error) {
6532
5990
  if (queryId < this._lastQueryIdReceived) {
6533
5991
  // Outdated answer
6534
5992
  return;
6535
5993
  }
6536
-
6537
5994
  this._currentNbQueries -= queryId - this._lastQueryIdReceived;
6538
5995
  this._lastQueryIdReceived = queryId;
6539
-
6540
5996
  this.emit('error', {
6541
5997
  error: error
6542
5998
  });
6543
-
6544
5999
  if (this._currentNbQueries === 0) this.emit('searchQueueEmpty');
6545
6000
  };
6546
-
6547
- AlgoliaSearchHelper.prototype.containsRefinement = function(query, facetFilters, numericFilters, tagFilters) {
6548
- return query ||
6549
- facetFilters.length !== 0 ||
6550
- numericFilters.length !== 0 ||
6551
- tagFilters.length !== 0;
6001
+ AlgoliaSearchHelper.prototype.containsRefinement = function (query, facetFilters, numericFilters, tagFilters) {
6002
+ return query || facetFilters.length !== 0 || numericFilters.length !== 0 || tagFilters.length !== 0;
6552
6003
  };
6553
6004
 
6554
6005
  /**
6555
6006
  * Test if there are some disjunctive refinements on the facet
6556
6007
  * @private
6557
6008
  * @param {string} facet the attribute to test
6558
- * @return {boolean}
6009
+ * @return {boolean} true if there are refinements on this attribute
6559
6010
  */
6560
- AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function(facet) {
6561
- return this.state.disjunctiveRefinements[facet] &&
6562
- this.state.disjunctiveRefinements[facet].length > 0;
6011
+ AlgoliaSearchHelper.prototype._hasDisjunctiveRefinements = function (facet) {
6012
+ return this.state.disjunctiveRefinements[facet] && this.state.disjunctiveRefinements[facet].length > 0;
6563
6013
  };
6564
-
6565
- AlgoliaSearchHelper.prototype._change = function(event) {
6014
+ AlgoliaSearchHelper.prototype._change = function (event) {
6566
6015
  var state = event.state;
6567
6016
  var isPageReset = event.isPageReset;
6568
-
6569
6017
  if (state !== this.state) {
6570
6018
  this.state = state;
6571
-
6572
6019
  this.emit('change', {
6573
6020
  state: this.state,
6574
6021
  results: this.lastResults,
@@ -6579,10 +6026,10 @@
6579
6026
 
6580
6027
  /**
6581
6028
  * Clears the cache of the underlying Algolia client.
6582
- * @return {AlgoliaSearchHelper}
6029
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6583
6030
  */
6584
- AlgoliaSearchHelper.prototype.clearCache = function() {
6585
- this.client.clearCache && this.client.clearCache();
6031
+ AlgoliaSearchHelper.prototype.clearCache = function () {
6032
+ if (this.client.clearCache) this.client.clearCache();
6586
6033
  return this;
6587
6034
  };
6588
6035
 
@@ -6590,24 +6037,22 @@
6590
6037
  * Updates the internal client instance. If the reference of the clients
6591
6038
  * are equal then no update is actually done.
6592
6039
  * @param {AlgoliaSearch} newClient an AlgoliaSearch client
6593
- * @return {AlgoliaSearchHelper}
6040
+ * @return {AlgoliaSearchHelper} Method is chainable, it returns itself
6594
6041
  */
6595
- AlgoliaSearchHelper.prototype.setClient = function(newClient) {
6042
+ AlgoliaSearchHelper.prototype.setClient = function (newClient) {
6596
6043
  if (this.client === newClient) return this;
6597
-
6598
6044
  if (typeof newClient.addAlgoliaAgent === 'function') {
6599
6045
  newClient.addAlgoliaAgent('JS Helper (' + version$1 + ')');
6600
6046
  }
6601
6047
  this.client = newClient;
6602
-
6603
6048
  return this;
6604
6049
  };
6605
6050
 
6606
6051
  /**
6607
6052
  * Gets the instance of the currently used client.
6608
- * @return {AlgoliaSearch}
6053
+ * @return {AlgoliaSearch} the currently used client
6609
6054
  */
6610
- AlgoliaSearchHelper.prototype.getClient = function() {
6055
+ AlgoliaSearchHelper.prototype.getClient = function () {
6611
6056
  return this.client;
6612
6057
  };
6613
6058
 
@@ -6628,9 +6073,9 @@
6628
6073
  * and the SearchParameters that is returned by the call of the
6629
6074
  * parameter function.
6630
6075
  * @param {function} fn SearchParameters -> SearchParameters
6631
- * @return {DerivedHelper}
6076
+ * @return {DerivedHelper} a new DerivedHelper
6632
6077
  */
6633
- AlgoliaSearchHelper.prototype.derive = function(fn) {
6078
+ AlgoliaSearchHelper.prototype.derive = function (fn) {
6634
6079
  var derivedHelper = new DerivedHelper_1(this, fn);
6635
6080
  this.derivedHelpers.push(derivedHelper);
6636
6081
  return derivedHelper;
@@ -6640,10 +6085,11 @@
6640
6085
  * This method detaches a derived Helper from the main one. Prefer using the one from the
6641
6086
  * derived helper itself, to remove the event listeners too.
6642
6087
  * @private
6643
- * @return {undefined}
6088
+ * @param {DerivedHelper} derivedHelper the derived helper to detach
6089
+ * @return {undefined} nothing is returned
6644
6090
  * @throws Error
6645
6091
  */
6646
- AlgoliaSearchHelper.prototype.detachDerivedHelper = function(derivedHelper) {
6092
+ AlgoliaSearchHelper.prototype.detachDerivedHelper = function (derivedHelper) {
6647
6093
  var pos = this.derivedHelpers.indexOf(derivedHelper);
6648
6094
  if (pos === -1) throw new Error('Derived helper already detached');
6649
6095
  this.derivedHelpers.splice(pos, 1);
@@ -6653,7 +6099,7 @@
6653
6099
  * This method returns true if there is currently at least one on-going search.
6654
6100
  * @return {boolean} true if there is a search pending
6655
6101
  */
6656
- AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
6102
+ AlgoliaSearchHelper.prototype.hasPendingRequests = function () {
6657
6103
  return this._currentNbQueries > 0;
6658
6104
  };
6659
6105
 
@@ -6704,7 +6150,7 @@
6704
6150
  * @param {AlgoliaSearch} client an AlgoliaSearch client
6705
6151
  * @param {string} index the name of the index to query
6706
6152
  * @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.
6707
- * @return {AlgoliaSearchHelper}
6153
+ * @return {AlgoliaSearchHelper} The helper instance
6708
6154
  */
6709
6155
  function algoliasearchHelper(client, index, opts) {
6710
6156
  return new algoliasearch_helper(client, index, opts);
@@ -6737,7 +6183,6 @@
6737
6183
  * @type {SearchResults}
6738
6184
  */
6739
6185
  algoliasearchHelper.SearchResults = SearchResults_1;
6740
-
6741
6186
  var algoliasearchHelper_1 = algoliasearchHelper;
6742
6187
 
6743
6188
  function createOptionalFilter(_ref) {