All files / lib/commands generic-transformers.ts

100% Statements 19/19
100% Branches 4/4
100% Functions 7/7
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x 31x     1x 180x     1x 10x     1x 18x     1x 1x               1x 17x   17x 2x     17x 2x     17x               1x 14x          
export function transformReplyNumber(reply: number): number {
    return reply;
}
 
export function transformReplyString(reply: string): string {
    return reply;
}
 
export function transformReplyStringArray(reply: Array<string>): Array<string> {
    return reply;
}
 
export function transformReplyBoolean(reply: number): boolean {
    return reply === 1;
}
 
export function transformReplyBooleanArray(reply: Array<number>): Array<boolean> {
    return reply.map(transformReplyBoolean);
}
 
export interface ScanOptions {
    MATCH?: string;
    COUNT?: number;
}
 
export function transformScanArguments(cursor: number, options?: ScanOptions): Array<string> {
    const args = [cursor.toString()];
 
    if (options?.MATCH) {
        args.push('MATCH', options.MATCH);
    }
 
    if (options?.COUNT) {
        args.push('COUNT', options.COUNT.toString());
    }
    
    return args;
}
 
export interface ScanReply {
    cursor: number;
    keys: Array<string>
}
 
export function transformScanReply([cursor, keys]: [string, Array<string>]): ScanReply {
    return {
        cursor: Number(cursor),
        keys
    };
}