With .replaceAll() in place of replace(), the port of ticket_branch.py swaps every space the way Python does. The next line to port, title.strip().rstrip("."), tidies the title. It matters for PAY-2304, "PAY-2304: Retry failed card payments.", because the review bot rejects a commit subject that ends with a full stop, and git rejects a branch name that ends with one.
JavaScript’s string toolkit is smaller than Python’s, and some of the methods you use most are missing. In this lesson, you’ll port the title line, then give PAY-2317’s title the capital letter it lacks.
Strip the Full Stop From PAY-2304
After the helper splits the header at its first colon, PAY-2304’s title is " Retry failed card payments.", leading space included. Here’s how the Python helper tidies it:
key = "PAY-2304"
title = " Retry failed card payments."
title = title.strip().rstrip(".")
print(f"Commit: {key}: {title}")
Python prints Commit: PAY-2304: Retry failed card payments, with no full stop. You already know strip() as .trim() and rstrip() as .trimEnd(), so the port follows line by line:
const key = "PAY-2304";
const rawTitle = " Retry failed card payments.";
const title = rawTitle.trim().trimEnd(".");
console.log(`Commit: ${key}: ${title}`);
Before you run it, predict the output. Does .trimEnd(".") drop the full stop, complain about its argument, or do something else?