All files / diff/src/format colors.ts

100% Statements 3/3
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

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                              13x 141486x  
import type {DiffColors} from './types';
 
/**
 * Wraps one piece of output in a {@link DiffColors} escape, or leaves it alone
 * when the writer was given no palette.
 *
 * The reset is passed separately rather than read off the palette on every call
 * because a writer resolves it once per diff, and because a palette with an
 * `open` but no `reset` must still be usable — a caller emitting HTML has no
 * single closing string.
 *
 * @param open The escape for this piece, from a {@link DiffColors} field.
 * @param text The piece, without its terminator.
 * @param reset Written after `text`; `''` when the palette named none.
 */
export const paint = (open: string | undefined, text: string, reset: string): string =>
  open === undefined ? text : open + text + reset;