jargons.dev icon indicating copy to clipboard operation
jargons.dev copied to clipboard

Create `getBranchNameFromRef` utility function

Open babblebey opened this issue 10 months ago • 2 comments

Create a utility function named getBranchNameFromRef that extracts the branch name from a branch reference string. This function should take a string parameter representing the branch reference and return the branch name. The function should perform the operation branchRef.split("/").slice(2).join("/") to extract the branch name.

Task

  1. Create a new utility function named getBranchNameFromRef in the src/lib/utils/index.js file.
  2. Implement the function to extract the branch name from the branch reference string.
  3. Integrate the getBranchNameFromRef function in the writeNewWord and editExistingWord functions in the word-editor script located in the src/lib directory. Replace the line const branch = repoBranchRef.split("/").slice(2).join("/"); in both functions with const branch = getBranchNameFromRef(repoBranchRef);.

Example

// Function implementation
function getBranchNameFromRef(branchRef) {
  return branchRef.split("/").slice(2).join("/");
}

// Usage example
const branchRef = "refs/heads/main";
const branchName = getBranchNameFromRef(branchRef);
console.log(branchName); // Output: "main"

Guidelines

  • Follow the existing code style and formatting conventions.
  • Add jsdoc please to aid auto-complete

Additional Information

  • Related Files:
    • src/lib/utils/index.js
    • src/lib/word-editor.js
  • Feel free to ask any questions away 😉

babblebey avatar Apr 03 '24 05:04 babblebey