Debian Codegraph @

packages/search/lib/commands/SUGGET_WITHSCORES.ts

raw
1 import { SugGetOptions, transformArguments as transformSugGetArguments } from './SUGGET';
2
3 export { IS_READ_ONLY } from './SUGGET';
4
5 export function transformArguments(key: string, prefix: string, options?: SugGetOptions): Array<string> {
6 return [
7 ...transformSugGetArguments(key, prefix, options),
8 'WITHSCORES'
9 ];
10 }
11
12 export interface SuggestionWithScores {
13 suggestion: string;
14 score: number;
15 }
16
17 export function transformReply(rawReply: Array<string> | null): Array<SuggestionWithScores> | null {
18 if (rawReply === null) return null;
19
20 const transformedReply = [];
21 for (let i = 0; i < rawReply.length; i += 2) {
22 transformedReply.push({
23 suggestion: rawReply[i],
24 score: Number(rawReply[i + 1])
25 });
26 }
27
28 return transformedReply;
29 }