All files / src/helpers splitByIndex.ts

16.67% Statements 1/6
0% Branches 0/5
0% Functions 0/2
20% Lines 1/5

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 151x                            
const splitByIndex = (
  value: string,
  index: number,
  format: "space" | "dash" = "space"
): string => {
  const formatString = format === "space" ? " " : "-";
  if (value.length < index) return value;
  return [value.substring(0, index)]
    .concat(splitByIndex(value.substring(index), index, format))
    .filter((chunk) => chunk)
    .join(formatString);
};
 
export default splitByIndex;