algoliasearch-helper 3.7.2 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +11 -0
- package/dist/algoliasearch.helper.js +68 -26
- package/dist/algoliasearch.helper.js.map +7 -5
- package/dist/algoliasearch.helper.min.js +2 -2
- package/dist/algoliasearch.helper.min.js.map +1 -1
- package/index.d.ts +10 -5
- package/package.json +2 -1
- package/src/SearchResults/generate-hierarchical-tree.js +6 -1
- package/src/SearchResults/index.js +10 -3
- package/src/algoliasearch.helper.js +4 -2
- package/src/functions/escapeFacetValue.js +26 -0
- package/src/version.js +1 -1
package/CHANGELOG
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
3.8.0 - 2022-04-04
|
|
2
|
+
* ci(codesandbox): set up (#899) https://github.com/algolia/algoliasearch-helper-js/commit/ac7de4458f31c01da4e682cabee357e6300e147a
|
|
3
|
+
* ci(typescript): run type tests in CI (#898) https://github.com/algolia/algoliasearch-helper-js/commit/4d45118ef64a8c6352d2e75618df4e18a149ba64
|
|
4
|
+
* feat(facetValues): offer escaped value (#889) https://github.com/algolia/algoliasearch-helper-js/commit/4bae51bdefd217f3ef9ab9bf02fb653f3b8ae643
|
|
5
|
+
|
|
6
|
+
3.7.4 - 2022-03-21
|
|
7
|
+
* fix(type): implement correctly https://github.com/algolia/algoliasearch-helper-js/commit/1c8670b21a507024d2ddf797feae5bb15343c244
|
|
8
|
+
|
|
9
|
+
3.7.3 - 2022-03-18
|
|
10
|
+
* fix(ts): remove stray comment https://github.com/algolia/algoliasearch-helper-js/commit/24fe8de4bebc74500b33c95b124500b8499ef588
|
|
11
|
+
|
|
1
12
|
3.7.2 - 2022-03-18
|
|
2
13
|
* chore(docs): fix capitalization of Github and npm https://github.com/algolia/algoliasearch-helper-js/commit/5babbcad0b3d406a0b56f7a55682ff169e2b853f
|
|
3
14
|
* fix(results): implement search result options via an argument https://github.com/algolia/algoliasearch-helper-js/commit/4e6ac6926bd284c7eafe060480fc4258844d121a
|
|
@@ -71,7 +71,7 @@ algoliasearchHelper.SearchResults = SearchResults;
|
|
|
71
71
|
|
|
72
72
|
module.exports = algoliasearchHelper;
|
|
73
73
|
|
|
74
|
-
},{"./src/SearchParameters":5,"./src/SearchResults":7,"./src/algoliasearch.helper":8,"./src/version.js":
|
|
74
|
+
},{"./src/SearchParameters":5,"./src/SearchResults":7,"./src/algoliasearch.helper":8,"./src/version.js":24}],2:[function(require,module,exports){
|
|
75
75
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
76
76
|
//
|
|
77
77
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
@@ -415,7 +415,7 @@ DerivedHelper.prototype.getModifiedState = function(parameters) {
|
|
|
415
415
|
|
|
416
416
|
module.exports = DerivedHelper;
|
|
417
417
|
|
|
418
|
-
},{"../functions/inherits":
|
|
418
|
+
},{"../functions/inherits":15,"@algolia/events":2}],4:[function(require,module,exports){
|
|
419
419
|
'use strict';
|
|
420
420
|
|
|
421
421
|
/**
|
|
@@ -564,7 +564,7 @@ var lib = {
|
|
|
564
564
|
|
|
565
565
|
module.exports = lib;
|
|
566
566
|
|
|
567
|
-
},{"../functions/defaultsPure":10,"../functions/objectHasKeys":
|
|
567
|
+
},{"../functions/defaultsPure":10,"../functions/objectHasKeys":18,"../functions/omit":19}],5:[function(require,module,exports){
|
|
568
568
|
'use strict';
|
|
569
569
|
|
|
570
570
|
var merge = require('../functions/merge');
|
|
@@ -2076,7 +2076,7 @@ SearchParameters.prototype = {
|
|
|
2076
2076
|
*/
|
|
2077
2077
|
module.exports = SearchParameters;
|
|
2078
2078
|
|
|
2079
|
-
},{"../functions/defaultsPure":10,"../functions/find":
|
|
2079
|
+
},{"../functions/defaultsPure":10,"../functions/find":12,"../functions/intersection":16,"../functions/merge":17,"../functions/objectHasKeys":18,"../functions/omit":19,"../functions/valToNumber":21,"../utils/isValidUserToken":23,"./RefinementList":4}],6:[function(require,module,exports){
|
|
2080
2080
|
'use strict';
|
|
2081
2081
|
|
|
2082
2082
|
module.exports = generateTrees;
|
|
@@ -2084,6 +2084,9 @@ module.exports = generateTrees;
|
|
|
2084
2084
|
var orderBy = require('../functions/orderBy');
|
|
2085
2085
|
var find = require('../functions/find');
|
|
2086
2086
|
var prepareHierarchicalFacetSortBy = require('../functions/formatSort');
|
|
2087
|
+
var fv = require('../functions/escapeFacetValue');
|
|
2088
|
+
var escapeFacetValue = fv.escapeFacetValue;
|
|
2089
|
+
var unescapeFacetValue = fv.unescapeFacetValue;
|
|
2087
2090
|
|
|
2088
2091
|
function generateTrees(state) {
|
|
2089
2092
|
return function generate(hierarchicalFacetResult, hierarchicalFacetIndex) {
|
|
@@ -2130,6 +2133,7 @@ function generateTrees(state) {
|
|
|
2130
2133
|
count: null, // root level, no count
|
|
2131
2134
|
isRefined: true, // root level, always refined
|
|
2132
2135
|
path: null, // root level, no path
|
|
2136
|
+
escapedValue: null,
|
|
2133
2137
|
exhaustive: rootExhaustive,
|
|
2134
2138
|
data: null
|
|
2135
2139
|
});
|
|
@@ -2205,7 +2209,7 @@ function generateHierarchicalTree(
|
|
|
2205
2209
|
facetCount,
|
|
2206
2210
|
facetValue,
|
|
2207
2211
|
hierarchicalSeparator,
|
|
2208
|
-
currentRefinement,
|
|
2212
|
+
unescapeFacetValue(currentRefinement),
|
|
2209
2213
|
hierarchicalFacetResult.exhaustive
|
|
2210
2214
|
);
|
|
2211
2215
|
}),
|
|
@@ -2268,6 +2272,7 @@ function format(
|
|
|
2268
2272
|
return {
|
|
2269
2273
|
name: parts[parts.length - 1].trim(),
|
|
2270
2274
|
path: facetValue,
|
|
2275
|
+
escapedValue: escapeFacetValue(facetValue),
|
|
2271
2276
|
count: facetCount,
|
|
2272
2277
|
isRefined:
|
|
2273
2278
|
currentRefinement === facetValue ||
|
|
@@ -2277,7 +2282,7 @@ function format(
|
|
|
2277
2282
|
};
|
|
2278
2283
|
}
|
|
2279
2284
|
|
|
2280
|
-
},{"../functions/
|
|
2285
|
+
},{"../functions/escapeFacetValue":11,"../functions/find":12,"../functions/formatSort":14,"../functions/orderBy":20}],7:[function(require,module,exports){
|
|
2281
2286
|
'use strict';
|
|
2282
2287
|
|
|
2283
2288
|
var merge = require('../functions/merge');
|
|
@@ -2287,6 +2292,9 @@ var compact = require('../functions/compact');
|
|
|
2287
2292
|
var find = require('../functions/find');
|
|
2288
2293
|
var findIndex = require('../functions/findIndex');
|
|
2289
2294
|
var formatSort = require('../functions/formatSort');
|
|
2295
|
+
var fv = require('../functions/escapeFacetValue');
|
|
2296
|
+
var escapeFacetValue = fv.escapeFacetValue;
|
|
2297
|
+
var unescapeFacetValue = fv.unescapeFacetValue;
|
|
2290
2298
|
|
|
2291
2299
|
var generateHierarchicalTree = require('./generate-hierarchical-tree');
|
|
2292
2300
|
|
|
@@ -2788,7 +2796,7 @@ function SearchResults(state, results, options) {
|
|
|
2788
2796
|
state.disjunctiveFacetsRefinements[dfacet].forEach(function(refinementValue) {
|
|
2789
2797
|
// add the disjunctive refinements if it is no more retrieved
|
|
2790
2798
|
if (!self.disjunctiveFacets[position].data[refinementValue] &&
|
|
2791
|
-
state.disjunctiveFacetsRefinements[dfacet].indexOf(refinementValue) > -1) {
|
|
2799
|
+
state.disjunctiveFacetsRefinements[dfacet].indexOf(unescapeFacetValue(refinementValue)) > -1) {
|
|
2792
2800
|
self.disjunctiveFacets[position].data[refinementValue] = 0;
|
|
2793
2801
|
}
|
|
2794
2802
|
});
|
|
@@ -2920,10 +2928,12 @@ function extractNormalizedFacetValues(results, attribute) {
|
|
|
2920
2928
|
if (!facet) return [];
|
|
2921
2929
|
|
|
2922
2930
|
return Object.keys(facet.data).map(function(name) {
|
|
2931
|
+
var value = escapeFacetValue(name);
|
|
2923
2932
|
return {
|
|
2924
2933
|
name: name,
|
|
2934
|
+
escapedValue: value,
|
|
2925
2935
|
count: facet.data[name],
|
|
2926
|
-
isRefined: results._state.isFacetRefined(attribute,
|
|
2936
|
+
isRefined: results._state.isFacetRefined(attribute, value),
|
|
2927
2937
|
isExcluded: results._state.isExcludeRefined(attribute, name)
|
|
2928
2938
|
};
|
|
2929
2939
|
});
|
|
@@ -2932,10 +2942,12 @@ function extractNormalizedFacetValues(results, attribute) {
|
|
|
2932
2942
|
if (!disjunctiveFacet) return [];
|
|
2933
2943
|
|
|
2934
2944
|
return Object.keys(disjunctiveFacet.data).map(function(name) {
|
|
2945
|
+
var value = escapeFacetValue(name);
|
|
2935
2946
|
return {
|
|
2936
2947
|
name: name,
|
|
2948
|
+
escapedValue: value,
|
|
2937
2949
|
count: disjunctiveFacet.data[name],
|
|
2938
|
-
isRefined: results._state.isDisjunctiveFacetRefined(attribute,
|
|
2950
|
+
isRefined: results._state.isDisjunctiveFacetRefined(attribute, value)
|
|
2939
2951
|
};
|
|
2940
2952
|
});
|
|
2941
2953
|
} else if (results._state.isHierarchicalFacet(attribute)) {
|
|
@@ -3300,7 +3312,7 @@ function getHierarchicalRefinement(state, attributeName, name, resultsFacets) {
|
|
|
3300
3312
|
|
|
3301
3313
|
module.exports = SearchResults;
|
|
3302
3314
|
|
|
3303
|
-
},{"../functions/compact":9,"../functions/defaultsPure":10,"../functions/
|
|
3315
|
+
},{"../functions/compact":9,"../functions/defaultsPure":10,"../functions/escapeFacetValue":11,"../functions/find":12,"../functions/findIndex":13,"../functions/formatSort":14,"../functions/merge":17,"../functions/orderBy":20,"./generate-hierarchical-tree":6}],8:[function(require,module,exports){
|
|
3304
3316
|
'use strict';
|
|
3305
3317
|
|
|
3306
3318
|
var SearchParameters = require('./SearchParameters');
|
|
@@ -3315,6 +3327,7 @@ var omit = require('./functions/omit');
|
|
|
3315
3327
|
var merge = require('./functions/merge');
|
|
3316
3328
|
|
|
3317
3329
|
var version = require('./version');
|
|
3330
|
+
var escapeFacetValue = require('./functions/escapeFacetValue').escapeFacetValue;
|
|
3318
3331
|
|
|
3319
3332
|
/**
|
|
3320
3333
|
* Event triggered when a parameter is set or updated
|
|
@@ -3664,9 +3677,10 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxF
|
|
|
3664
3677
|
content = Array.isArray(content) ? content[0] : content;
|
|
3665
3678
|
|
|
3666
3679
|
content.facetHits.forEach(function(f) {
|
|
3680
|
+
f.escapedValue = escapeFacetValue(f.value);
|
|
3667
3681
|
f.isRefined = isDisjunctive
|
|
3668
|
-
? state.isDisjunctiveFacetRefined(facet, f.
|
|
3669
|
-
: state.isFacetRefined(facet, f.
|
|
3682
|
+
? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
|
|
3683
|
+
: state.isFacetRefined(facet, f.escapedValue);
|
|
3670
3684
|
});
|
|
3671
3685
|
|
|
3672
3686
|
return content;
|
|
@@ -4769,7 +4783,7 @@ AlgoliaSearchHelper.prototype.hasPendingRequests = function() {
|
|
|
4769
4783
|
|
|
4770
4784
|
module.exports = AlgoliaSearchHelper;
|
|
4771
4785
|
|
|
4772
|
-
},{"./DerivedHelper":3,"./SearchParameters":5,"./SearchResults":7,"./functions/inherits":
|
|
4786
|
+
},{"./DerivedHelper":3,"./SearchParameters":5,"./SearchResults":7,"./functions/escapeFacetValue":11,"./functions/inherits":15,"./functions/merge":17,"./functions/objectHasKeys":18,"./functions/omit":19,"./requestBuilder":22,"./version":24,"@algolia/events":2}],9:[function(require,module,exports){
|
|
4773
4787
|
'use strict';
|
|
4774
4788
|
|
|
4775
4789
|
module.exports = function compact(array) {
|
|
@@ -4806,6 +4820,34 @@ module.exports = function defaultsPure() {
|
|
|
4806
4820
|
},{}],11:[function(require,module,exports){
|
|
4807
4821
|
'use strict';
|
|
4808
4822
|
|
|
4823
|
+
/**
|
|
4824
|
+
* Replaces a leading - with \-
|
|
4825
|
+
* @private
|
|
4826
|
+
* @param {string} value the facet value to replace
|
|
4827
|
+
* @returns string
|
|
4828
|
+
*/
|
|
4829
|
+
function escapeFacetValue(value) {
|
|
4830
|
+
return value.replace(/^-/, '\\-');
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4833
|
+
/**
|
|
4834
|
+
* Replaces a leading \- with -
|
|
4835
|
+
* @private
|
|
4836
|
+
* @param {string} value the escaped facet value
|
|
4837
|
+
* @returns string
|
|
4838
|
+
*/
|
|
4839
|
+
function unescapeFacetValue(value) {
|
|
4840
|
+
return value.replace(/^\\-/, '-');
|
|
4841
|
+
}
|
|
4842
|
+
|
|
4843
|
+
module.exports = {
|
|
4844
|
+
escapeFacetValue: escapeFacetValue,
|
|
4845
|
+
unescapeFacetValue: unescapeFacetValue
|
|
4846
|
+
};
|
|
4847
|
+
|
|
4848
|
+
},{}],12:[function(require,module,exports){
|
|
4849
|
+
'use strict';
|
|
4850
|
+
|
|
4809
4851
|
// @MAJOR can be replaced by native Array#find when we change support
|
|
4810
4852
|
module.exports = function find(array, comparator) {
|
|
4811
4853
|
if (!Array.isArray(array)) {
|
|
@@ -4819,7 +4861,7 @@ module.exports = function find(array, comparator) {
|
|
|
4819
4861
|
}
|
|
4820
4862
|
};
|
|
4821
4863
|
|
|
4822
|
-
},{}],
|
|
4864
|
+
},{}],13:[function(require,module,exports){
|
|
4823
4865
|
'use strict';
|
|
4824
4866
|
|
|
4825
4867
|
// @MAJOR can be replaced by native Array#findIndex when we change support
|
|
@@ -4836,7 +4878,7 @@ module.exports = function find(array, comparator) {
|
|
|
4836
4878
|
return -1;
|
|
4837
4879
|
};
|
|
4838
4880
|
|
|
4839
|
-
},{}],
|
|
4881
|
+
},{}],14:[function(require,module,exports){
|
|
4840
4882
|
'use strict';
|
|
4841
4883
|
|
|
4842
4884
|
var find = require('./find');
|
|
@@ -4876,7 +4918,7 @@ module.exports = function formatSort(sortBy, defaults) {
|
|
|
4876
4918
|
);
|
|
4877
4919
|
};
|
|
4878
4920
|
|
|
4879
|
-
},{"./find":
|
|
4921
|
+
},{"./find":12}],15:[function(require,module,exports){
|
|
4880
4922
|
'use strict';
|
|
4881
4923
|
|
|
4882
4924
|
function inherits(ctor, superCtor) {
|
|
@@ -4892,7 +4934,7 @@ function inherits(ctor, superCtor) {
|
|
|
4892
4934
|
|
|
4893
4935
|
module.exports = inherits;
|
|
4894
4936
|
|
|
4895
|
-
},{}],
|
|
4937
|
+
},{}],16:[function(require,module,exports){
|
|
4896
4938
|
'use strict';
|
|
4897
4939
|
|
|
4898
4940
|
function intersection(arr1, arr2) {
|
|
@@ -4906,7 +4948,7 @@ function intersection(arr1, arr2) {
|
|
|
4906
4948
|
|
|
4907
4949
|
module.exports = intersection;
|
|
4908
4950
|
|
|
4909
|
-
},{}],
|
|
4951
|
+
},{}],17:[function(require,module,exports){
|
|
4910
4952
|
'use strict';
|
|
4911
4953
|
|
|
4912
4954
|
function clone(value) {
|
|
@@ -4989,7 +5031,7 @@ function merge(target) {
|
|
|
4989
5031
|
|
|
4990
5032
|
module.exports = merge;
|
|
4991
5033
|
|
|
4992
|
-
},{}],
|
|
5034
|
+
},{}],18:[function(require,module,exports){
|
|
4993
5035
|
'use strict';
|
|
4994
5036
|
|
|
4995
5037
|
function objectHasKeys(obj) {
|
|
@@ -4998,7 +5040,7 @@ function objectHasKeys(obj) {
|
|
|
4998
5040
|
|
|
4999
5041
|
module.exports = objectHasKeys;
|
|
5000
5042
|
|
|
5001
|
-
},{}],
|
|
5043
|
+
},{}],19:[function(require,module,exports){
|
|
5002
5044
|
'use strict';
|
|
5003
5045
|
|
|
5004
5046
|
// https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620
|
|
@@ -5018,7 +5060,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
5018
5060
|
|
|
5019
5061
|
module.exports = _objectWithoutPropertiesLoose;
|
|
5020
5062
|
|
|
5021
|
-
},{}],
|
|
5063
|
+
},{}],20:[function(require,module,exports){
|
|
5022
5064
|
'use strict';
|
|
5023
5065
|
|
|
5024
5066
|
function compareAscending(value, other) {
|
|
@@ -5099,7 +5141,7 @@ function orderBy(collection, iteratees, orders) {
|
|
|
5099
5141
|
|
|
5100
5142
|
module.exports = orderBy;
|
|
5101
5143
|
|
|
5102
|
-
},{}],
|
|
5144
|
+
},{}],21:[function(require,module,exports){
|
|
5103
5145
|
'use strict';
|
|
5104
5146
|
|
|
5105
5147
|
function valToNumber(v) {
|
|
@@ -5116,7 +5158,7 @@ function valToNumber(v) {
|
|
|
5116
5158
|
|
|
5117
5159
|
module.exports = valToNumber;
|
|
5118
5160
|
|
|
5119
|
-
},{}],
|
|
5161
|
+
},{}],22:[function(require,module,exports){
|
|
5120
5162
|
'use strict';
|
|
5121
5163
|
|
|
5122
5164
|
var merge = require('./functions/merge');
|
|
@@ -5439,7 +5481,7 @@ var requestBuilder = {
|
|
|
5439
5481
|
|
|
5440
5482
|
module.exports = requestBuilder;
|
|
5441
5483
|
|
|
5442
|
-
},{"./functions/merge":
|
|
5484
|
+
},{"./functions/merge":17}],23:[function(require,module,exports){
|
|
5443
5485
|
'use strict';
|
|
5444
5486
|
|
|
5445
5487
|
module.exports = function isValidUserToken(userToken) {
|
|
@@ -5449,10 +5491,10 @@ module.exports = function isValidUserToken(userToken) {
|
|
|
5449
5491
|
return /^[a-zA-Z0-9_-]{1,64}$/.test(userToken);
|
|
5450
5492
|
};
|
|
5451
5493
|
|
|
5452
|
-
},{}],
|
|
5494
|
+
},{}],24:[function(require,module,exports){
|
|
5453
5495
|
'use strict';
|
|
5454
5496
|
|
|
5455
|
-
module.exports = '3.
|
|
5497
|
+
module.exports = '3.8.0';
|
|
5456
5498
|
|
|
5457
5499
|
},{}]},{},[1])(1)
|
|
5458
5500
|
});
|