All files / src/builder revision.ts

90% Statements 9/10
100% Branches 5/5
100% Functions 1/1
90% Lines 9/10

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 231x   7x 2x       5x 2x       3x 3x   3x 3x            
export function getNextRevision(currentRevision: string) {
  // If the string is empty or can't be parsed with parseInt(), return "1".
  if (!currentRevision || isNaN(parseInt(currentRevision, 10))) {
    return "1";
  }
 
  // If the string is like an integer, increment it by 1 and return the value.
  if (currentRevision.indexOf(".") === -1) {
    return (parseInt(currentRevision, 10) + 1).toString();
  }
 
  // If the string is a semver, parse the patch version out of it, increment it by one and return it.
  const parts = currentRevision.split(".");
  const lastPart = parseInt(parts[parts.length - 1], 10);
 
  if (!isNaN(lastPart)) {
    return (lastPart + 1).toString();
  }
 
  // If the string can't be parsed as a semver, return "1".
  return "1";
}