All files / sorting/src defaultSortDirectionCycler.ts

100% Statements 7/7
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6

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                            6x 6x 2x 4x 3x   1x      
import { SortDirectionCycler } from "./_types";
 
/**
 * Cycles though {@link SortDirection}s from `undefined` to `'asc'` to `'desc'`.
 *
 * @example
 * ```ts
 * const result = defaultSortDirectionCycler('desc');
 * console.log(result); // undefined
 * ```
 *
 * @param direction - the {@link SortDirection} to cycle
 * @returns the new {@link SortDirection}
 */
export const defaultSortDirectionCycler: SortDirectionCycler = (direction) => {
  if (!direction) {
    return "asc";
  } else if (direction === "asc") {
    return "desc";
  } else {
    return undefined;
  }
};