Skip to content

Commit

Permalink
feat(algolia): type highlighting utils
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Sep 9, 2020
1 parent baabc3a commit fa4b959
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/autocomplete-preset-algolia/src/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ function reverseHighlightedParts(parts: ParsedAttribute[]) {
return parts.map((part) => ({ ...part, isHighlighted: !part.isHighlighted }));
}

type SharedParseAttributeParams = {
hit: any;
attribute: string;
type SharedParseAttributeParams<TItem> = {
hit: TItem;
attribute: keyof TItem;
ignoreEscape?: string[];
};

export function parseAlgoliaHitHighlight({
export function parseAlgoliaHitHighlight<TItem extends object>({
hit,
attribute,
ignoreEscape,
}: SharedParseAttributeParams): ParsedAttribute[] {
}: SharedParseAttributeParams<TItem>): ParsedAttribute[] {
const highlightedValue = getAttributeValueByPath(
hit,
`_highlightResult.${attribute}.value`
Expand All @@ -102,17 +102,17 @@ export function parseAlgoliaHitHighlight({
});
}

export function parseAlgoliaHitReverseHighlight(
props: SharedParseAttributeParams
export function parseAlgoliaHitReverseHighlight<TItem extends object>(
props: SharedParseAttributeParams<TItem>
): ParsedAttribute[] {
return reverseHighlightedParts(parseAlgoliaHitHighlight(props));
return reverseHighlightedParts(parseAlgoliaHitHighlight<TItem>(props));
}

export function parseAlgoliaHitSnippet({
export function parseAlgoliaHitSnippet<TItem extends object>({
hit,
attribute,
ignoreEscape,
}: SharedParseAttributeParams): ParsedAttribute[] {
}: SharedParseAttributeParams<TItem>): ParsedAttribute[] {
const highlightedValue = getAttributeValueByPath(
hit,
`_snippetResult.${attribute}.value`
Expand All @@ -124,8 +124,8 @@ export function parseAlgoliaHitSnippet({
});
}

export function parseAlgoliaHitReverseSnippet(
props: SharedParseAttributeParams
export function parseAlgoliaHitReverseSnippet<TItem extends object>(
props: SharedParseAttributeParams<TItem>
): ParsedAttribute[] {
return reverseHighlightedParts(parseAlgoliaHitSnippet(props));
return reverseHighlightedParts(parseAlgoliaHitSnippet<TItem>(props));
}

0 comments on commit fa4b959

Please sign in to comment.