From fa4b959c575aeb6f36720c6e67ce6bfef2dacb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Wed, 9 Sep 2020 17:34:35 +0200 Subject: [PATCH] feat(algolia): type highlighting utils --- .../src/highlight.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/autocomplete-preset-algolia/src/highlight.ts b/packages/autocomplete-preset-algolia/src/highlight.ts index 6f8b36bd5..6b06cf983 100644 --- a/packages/autocomplete-preset-algolia/src/highlight.ts +++ b/packages/autocomplete-preset-algolia/src/highlight.ts @@ -80,17 +80,17 @@ function reverseHighlightedParts(parts: ParsedAttribute[]) { return parts.map((part) => ({ ...part, isHighlighted: !part.isHighlighted })); } -type SharedParseAttributeParams = { - hit: any; - attribute: string; +type SharedParseAttributeParams = { + hit: TItem; + attribute: keyof TItem; ignoreEscape?: string[]; }; -export function parseAlgoliaHitHighlight({ +export function parseAlgoliaHitHighlight({ hit, attribute, ignoreEscape, -}: SharedParseAttributeParams): ParsedAttribute[] { +}: SharedParseAttributeParams): ParsedAttribute[] { const highlightedValue = getAttributeValueByPath( hit, `_highlightResult.${attribute}.value` @@ -102,17 +102,17 @@ export function parseAlgoliaHitHighlight({ }); } -export function parseAlgoliaHitReverseHighlight( - props: SharedParseAttributeParams +export function parseAlgoliaHitReverseHighlight( + props: SharedParseAttributeParams ): ParsedAttribute[] { - return reverseHighlightedParts(parseAlgoliaHitHighlight(props)); + return reverseHighlightedParts(parseAlgoliaHitHighlight(props)); } -export function parseAlgoliaHitSnippet({ +export function parseAlgoliaHitSnippet({ hit, attribute, ignoreEscape, -}: SharedParseAttributeParams): ParsedAttribute[] { +}: SharedParseAttributeParams): ParsedAttribute[] { const highlightedValue = getAttributeValueByPath( hit, `_snippetResult.${attribute}.value` @@ -124,8 +124,8 @@ export function parseAlgoliaHitSnippet({ }); } -export function parseAlgoliaHitReverseSnippet( - props: SharedParseAttributeParams +export function parseAlgoliaHitReverseSnippet( + props: SharedParseAttributeParams ): ParsedAttribute[] { - return reverseHighlightedParts(parseAlgoliaHitSnippet(props)); + return reverseHighlightedParts(parseAlgoliaHitSnippet(props)); }