Socket
Socket
Sign inDemoInstall

@algolia/autocomplete-preset-algolia

Package Overview
Dependencies
Maintainers
62
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-preset-algolia - npm Package Compare versions

Comparing version 1.0.0-alpha.38 to 1.0.0-alpha.39

dist/esm/highlight/isPartHighlighted.d.ts

2

dist/esm/highlight/parseAlgoliaHitHighlight.d.ts
import { Hit } from '@algolia/client-search';
import { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';
import { ParsedAttribute } from './ParsedAttribute';
export declare function parseAlgoliaHitHighlight<THit extends Hit<{}>>({ hit, attribute, ignoreEscape, }: ParseAlgoliaHitParams<THit>): ParsedAttribute[];
export declare function parseAlgoliaHitHighlight<THit extends Hit<{}>>({ hit, attribute, }: ParseAlgoliaHitParams<THit>): ParsedAttribute[];

@@ -6,4 +6,3 @@ import { warn } from '@algolia/autocomplete-shared';

var hit = _ref.hit,
attribute = _ref.attribute,
ignoreEscape = _ref.ignoreEscape;
attribute = _ref.attribute;
var path = "_highlightResult.".concat(attribute, ".value");

@@ -18,5 +17,4 @@ var highlightedValue = getAttributeValueByPath(hit, path);

return parseAttribute({
highlightedValue: highlightedValue,
ignoreEscape: ignoreEscape
highlightedValue: highlightedValue
});
}
export declare type ParseAlgoliaHitParams<TItem> = {
hit: TItem;
attribute: keyof TItem;
ignoreEscape?: string[];
};
import { Hit } from '@algolia/client-search';
import { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';
import { ParsedAttribute } from './ParsedAttribute';
export declare function parseAlgoliaHitSnippet<THit extends Hit<{}>>({ hit, attribute, ignoreEscape, }: ParseAlgoliaHitParams<THit>): ParsedAttribute[];
export declare function parseAlgoliaHitSnippet<THit extends Hit<{}>>({ hit, attribute, }: ParseAlgoliaHitParams<THit>): ParsedAttribute[];

@@ -6,4 +6,3 @@ import { warn } from '@algolia/autocomplete-shared';

var hit = _ref.hit,
attribute = _ref.attribute,
ignoreEscape = _ref.ignoreEscape;
attribute = _ref.attribute;
var path = "_snippetResult.".concat(attribute, ".value");

@@ -18,5 +17,4 @@ var highlightedValue = getAttributeValueByPath(hit, path);

return parseAttribute({
highlightedValue: highlightedValue,
ignoreEscape: ignoreEscape
highlightedValue: highlightedValue
});
}
import { ParsedAttribute } from './ParsedAttribute';
declare type ParseAttributeParams = {
highlightedValue: string;
ignoreEscape?: string[];
};
export declare function parseAttribute({ highlightedValue, ignoreEscape, }: ParseAttributeParams): ParsedAttribute[];
export declare function parseAttribute({ highlightedValue, }: ParseAttributeParams): ParsedAttribute[];
export {};
import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../constants';
var htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
export function parseAttribute(_ref) {
var highlightedValue = _ref.highlightedValue,
_ref$ignoreEscape = _ref.ignoreEscape,
ignoreEscape = _ref$ignoreEscape === void 0 ? [] : _ref$ignoreEscape;
var unescapedHtmlRegex = new RegExp("[".concat(Object.keys(htmlEscapes).filter(function (character) {
return ignoreEscape.indexOf(character) === -1;
}).join(''), "]"), 'g');
var hasUnescapedHtmlRegex = RegExp(unescapedHtmlRegex.source);
function escape(value) {
return hasUnescapedHtmlRegex.test(value) ? value.replace(unescapedHtmlRegex, function (key) {
return htmlEscapes[key];
}) : value;
}
/**
* Creates a data structure that allows to concatenate similar highlighting
* parts in a single value.
*/
function createAttributeSet() {
var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var value = initialValue;
return {
get: function get() {
return value;
},
add: function add(part) {
var lastPart = value[value.length - 1];
var splitByPreTag = highlightedValue.split(HIGHLIGHT_PRE_TAG);
var firstValue = splitByPreTag.shift();
var elements = !firstValue ? [] : [{
value: escape(firstValue),
if ((lastPart === null || lastPart === void 0 ? void 0 : lastPart.isHighlighted) === part.isHighlighted) {
value[value.length - 1] = {
value: lastPart.value + part.value,
isHighlighted: lastPart.isHighlighted
};
} else {
value.push(part);
}
}
};
}
export function parseAttribute(_ref) {
var highlightedValue = _ref.highlightedValue;
var preTagParts = highlightedValue.split(HIGHLIGHT_PRE_TAG);
var firstValue = preTagParts.shift();
var parts = createAttributeSet(firstValue ? [{
value: firstValue,
isHighlighted: false
}];
splitByPreTag.forEach(function (split) {
var splitByPostTag = split.split(HIGHLIGHT_POST_TAG);
elements.push({
value: escape(splitByPostTag[0]),
}] : []);
preTagParts.forEach(function (part) {
var postTagParts = part.split(HIGHLIGHT_POST_TAG);
parts.add({
value: postTagParts[0],
isHighlighted: true
});
if (splitByPostTag[1] !== '') {
elements.push({
value: escape(splitByPostTag[1]),
if (postTagParts[1] !== '') {
parts.add({
value: postTagParts[1],
isHighlighted: false

@@ -44,3 +51,3 @@ });

});
return elements;
return parts.get();
}

@@ -7,2 +7,3 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

import { isPartHighlighted } from './isPartHighlighted';
export function reverseHighlightedParts(parts) {

@@ -20,7 +21,7 @@ // We don't want to highlight the whole word when no parts match.

return parts.map(function (part) {
return parts.map(function (part, i) {
return _objectSpread(_objectSpread({}, part), {}, {
isHighlighted: !part.isHighlighted
isHighlighted: !isPartHighlighted(parts, i)
});
});
}

@@ -1,1 +0,1 @@

export declare const version = "1.0.0-alpha.38";
export declare const version = "1.0.0-alpha.39";

@@ -1,1 +0,1 @@

export var version = '1.0.0-alpha.38';
export var version = '1.0.0-alpha.39';

@@ -1,2 +0,2 @@

/*! @algolia/autocomplete-preset-algolia 1.0.0-alpha.38 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
/*! @algolia/autocomplete-preset-algolia 1.0.0-alpha.39 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
(function (global, factory) {

@@ -43,40 +43,46 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
function parseAttribute(_ref) {
var highlightedValue = _ref.highlightedValue,
_ref$ignoreEscape = _ref.ignoreEscape,
ignoreEscape = _ref$ignoreEscape === void 0 ? [] : _ref$ignoreEscape;
var unescapedHtmlRegex = new RegExp("[".concat(Object.keys(htmlEscapes).filter(function (character) {
return ignoreEscape.indexOf(character) === -1;
}).join(''), "]"), 'g');
var hasUnescapedHtmlRegex = RegExp(unescapedHtmlRegex.source);
/**
* Creates a data structure that allows to concatenate similar highlighting
* parts in a single value.
*/
function createAttributeSet() {
var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var value = initialValue;
return {
get: function get() {
return value;
},
add: function add(part) {
var lastPart = value[value.length - 1];
function escape(value) {
return hasUnescapedHtmlRegex.test(value) ? value.replace(unescapedHtmlRegex, function (key) {
return htmlEscapes[key];
}) : value;
}
if ((lastPart === null || lastPart === void 0 ? void 0 : lastPart.isHighlighted) === part.isHighlighted) {
value[value.length - 1] = {
value: lastPart.value + part.value,
isHighlighted: lastPart.isHighlighted
};
} else {
value.push(part);
}
}
};
}
var splitByPreTag = highlightedValue.split(HIGHLIGHT_PRE_TAG);
var firstValue = splitByPreTag.shift();
var elements = !firstValue ? [] : [{
value: escape(firstValue),
function parseAttribute(_ref) {
var highlightedValue = _ref.highlightedValue;
var preTagParts = highlightedValue.split(HIGHLIGHT_PRE_TAG);
var firstValue = preTagParts.shift();
var parts = createAttributeSet(firstValue ? [{
value: firstValue,
isHighlighted: false
}];
splitByPreTag.forEach(function (split) {
var splitByPostTag = split.split(HIGHLIGHT_POST_TAG);
elements.push({
value: escape(splitByPostTag[0]),
}] : []);
preTagParts.forEach(function (part) {
var postTagParts = part.split(HIGHLIGHT_POST_TAG);
parts.add({
value: postTagParts[0],
isHighlighted: true
});
if (splitByPostTag[1] !== '') {
elements.push({
value: escape(splitByPostTag[1]),
if (postTagParts[1] !== '') {
parts.add({
value: postTagParts[1],
isHighlighted: false

@@ -86,3 +92,3 @@ });

});
return elements;
return parts.get();
}

@@ -92,4 +98,3 @@

var hit = _ref.hit,
attribute = _ref.attribute,
ignoreEscape = _ref.ignoreEscape;
attribute = _ref.attribute;
var path = "_highlightResult.".concat(attribute, ".value");

@@ -104,4 +109,3 @@ var highlightedValue = getAttributeValueByPath(hit, path);

return parseAttribute({
highlightedValue: highlightedValue,
ignoreEscape: ignoreEscape
highlightedValue: highlightedValue
});

@@ -159,2 +163,33 @@ }

var htmlEscapes = {
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&#39;': "'"
};
var hasAlphanumeric = new RegExp(/\w/i);
var regexEscapedHtml = /&(amp|quot|lt|gt|#39);/g;
var regexHasEscapedHtml = RegExp(regexEscapedHtml.source);
function unescape(value) {
return value && regexHasEscapedHtml.test(value) ? value.replace(regexEscapedHtml, function (character) {
return htmlEscapes[character];
}) : value;
}
function isPartHighlighted(parts, i) {
var _parts, _parts2;
var current = parts[i];
var isNextHighlighted = ((_parts = parts[i + 1]) === null || _parts === void 0 ? void 0 : _parts.isHighlighted) || true;
var isPreviousHighlighted = ((_parts2 = parts[i - 1]) === null || _parts2 === void 0 ? void 0 : _parts2.isHighlighted) || true;
if (!hasAlphanumeric.test(unescape(current.value)) && isPreviousHighlighted === isNextHighlighted) {
return isPreviousHighlighted;
}
return current.isHighlighted;
}
function reverseHighlightedParts(parts) {

@@ -172,5 +207,5 @@ // We don't want to highlight the whole word when no parts match.

return parts.map(function (part) {
return parts.map(function (part, i) {
return _objectSpread2(_objectSpread2({}, part), {}, {
isHighlighted: !part.isHighlighted
isHighlighted: !isPartHighlighted(parts, i)
});

@@ -186,4 +221,3 @@ });

var hit = _ref.hit,
attribute = _ref.attribute,
ignoreEscape = _ref.ignoreEscape;
attribute = _ref.attribute;
var path = "_snippetResult.".concat(attribute, ".value");

@@ -198,4 +232,3 @@ var highlightedValue = getAttributeValueByPath(hit, path);

return parseAttribute({
highlightedValue: highlightedValue,
ignoreEscape: ignoreEscape
highlightedValue: highlightedValue
});

@@ -208,3 +241,3 @@ }

var version = '1.0.0-alpha.38';
var version = '1.0.0-alpha.39';

@@ -211,0 +244,0 @@ function search(_ref) {

@@ -1,3 +0,3 @@

/*! @algolia/autocomplete-preset-algolia 1.0.0-alpha.38 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-preset-algolia"]={})}(this,(function(e){"use strict";function t(e,t){return t.split(".").reduce((function(e,t){return e&&e[t]}),e)}var i="__aa-highlight__",r="__/aa-highlight__",n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function u(e){var t=e.highlightedValue,u=e.ignoreEscape,o=void 0===u?[]:u,a=new RegExp("[".concat(Object.keys(n).filter((function(e){return-1===o.indexOf(e)})).join(""),"]"),"g"),l=RegExp(a.source);function c(e){return l.test(e)?e.replace(a,(function(e){return n[e]})):e}var s=t.split(i),g=s.shift(),h=g?[{value:c(g),isHighlighted:!1}]:[];return s.forEach((function(e){var t=e.split(r);h.push({value:c(t[0]),isHighlighted:!0}),""!==t[1]&&h.push({value:c(t[1]),isHighlighted:!1})})),h}function o(e){var i=e.hit,r=e.attribute,n=e.ignoreEscape,o="_highlightResult.".concat(r,".value"),a=t(i,o);return"string"!=typeof a&&(a=t(i,r)||""),u({highlightedValue:a,ignoreEscape:n})}function a(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function l(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,r)}return i}function c(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?l(Object(i),!0).forEach((function(t){a(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):l(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function s(e){return e.some((function(e){return e.isHighlighted}))?e.map((function(e){return c(c({},e),{},{isHighlighted:!e.isHighlighted})})):e.map((function(e){return c(c({},e),{},{isHighlighted:!1})}))}function g(e){var i=e.hit,r=e.attribute,n=e.ignoreEscape,o="_snippetResult.".concat(r,".value"),a=t(i,o);return"string"!=typeof a&&(a=t(i,r)||""),u({highlightedValue:a,ignoreEscape:n})}function h(e){var t=e.searchClient,n=e.queries;return"function"==typeof t.addAlgoliaAgent&&t.addAlgoliaAgent("autocomplete-core","1.0.0-alpha.38"),t.search(n.map((function(e){var t=e.indexName,n=e.query,u=e.params;return{indexName:t,query:n,params:c({hitsPerPage:5,highlightPreTag:i,highlightPostTag:r},u)}})))}e.getAlgoliaHits=function(e){return h({searchClient:e.searchClient,queries:e.queries}).then((function(e){return e.results.map((function(e){return e.hits.map((function(t){return c(c({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))}))}))},e.getAlgoliaResults=function(e){return h({searchClient:e.searchClient,queries:e.queries}).then((function(e){return e.results}))},e.parseAlgoliaHitHighlight=o,e.parseAlgoliaHitReverseHighlight=function(e){return s(o(e))},e.parseAlgoliaHitReverseSnippet=function(e){return s(g(e))},e.parseAlgoliaHitSnippet=g,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @algolia/autocomplete-preset-algolia 1.0.0-alpha.39 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete.js */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/autocomplete-preset-algolia"]={})}(this,(function(e){"use strict";function t(e,t){return t.split(".").reduce((function(e,t){return e&&e[t]}),e)}var i="__aa-highlight__",n="__/aa-highlight__";function r(e){var t=e.highlightedValue.split(i),r=t.shift(),u=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{get:function(){return e},add:function(t){var i=e[e.length-1];(null==i?void 0:i.isHighlighted)===t.isHighlighted?e[e.length-1]={value:i.value+t.value,isHighlighted:i.isHighlighted}:e.push(t)}}}(r?[{value:r,isHighlighted:!1}]:[]);return t.forEach((function(e){var t=e.split(n);u.add({value:t[0],isHighlighted:!0}),""!==t[1]&&u.add({value:t[1],isHighlighted:!1})})),u.get()}function u(e){var i=e.hit,n=e.attribute,u="_highlightResult.".concat(n,".value"),l=t(i,u);return"string"!=typeof l&&(l=t(i,n)||""),r({highlightedValue:l})}function l(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function o(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function a(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?o(Object(i),!0).forEach((function(t){l(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):o(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var g={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},h=new RegExp(/\w/i),s=/&(amp|quot|lt|gt|#39);/g,c=RegExp(s.source);function f(e,t){var i,n,r,u=e[t],l=(null===(i=e[t+1])||void 0===i?void 0:i.isHighlighted)||!0,o=(null===(n=e[t-1])||void 0===n?void 0:n.isHighlighted)||!0;return h.test((r=u.value)&&c.test(r)?r.replace(s,(function(e){return g[e]})):r)||o!==l?u.isHighlighted:o}function p(e){return e.some((function(e){return e.isHighlighted}))?e.map((function(t,i){return a(a({},t),{},{isHighlighted:!f(e,i)})})):e.map((function(e){return a(a({},e),{},{isHighlighted:!1})}))}function d(e){var i=e.hit,n=e.attribute,u="_snippetResult.".concat(n,".value"),l=t(i,u);return"string"!=typeof l&&(l=t(i,n)||""),r({highlightedValue:l})}function v(e){var t=e.searchClient,r=e.queries;return"function"==typeof t.addAlgoliaAgent&&t.addAlgoliaAgent("autocomplete-core","1.0.0-alpha.39"),t.search(r.map((function(e){var t=e.indexName,r=e.query,u=e.params;return{indexName:t,query:r,params:a({hitsPerPage:5,highlightPreTag:i,highlightPostTag:n},u)}})))}e.getAlgoliaHits=function(e){return v({searchClient:e.searchClient,queries:e.queries}).then((function(e){return e.results.map((function(e){return e.hits.map((function(t){return a(a({},t),{},{__autocomplete_indexName:e.index,__autocomplete_queryID:e.queryID})}))}))}))},e.getAlgoliaResults=function(e){return v({searchClient:e.searchClient,queries:e.queries}).then((function(e){return e.results}))},e.parseAlgoliaHitHighlight=u,e.parseAlgoliaHitReverseHighlight=function(e){return p(u(e))},e.parseAlgoliaHitReverseSnippet=function(e){return p(d(e))},e.parseAlgoliaHitSnippet=d,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@algolia/autocomplete-preset-algolia",
"description": "Presets for building autocomplete experiences with Algolia.",
"version": "1.0.0-alpha.38",
"version": "1.0.0-alpha.39",
"license": "MIT",

@@ -34,3 +34,3 @@ "homepage": "https://github.com/algolia/autocomplete.js",

"dependencies": {
"@algolia/autocomplete-shared": "1.0.0-alpha.38"
"@algolia/autocomplete-shared": "1.0.0-alpha.39"
},

@@ -37,0 +37,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc