jargons.dev
jargons.dev copied to clipboard
Create `getBranchNameFromRef` utility function
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
- Create a new utility function named
getBranchNameFromRef
in thesrc/lib/utils/index.js
file. - Implement the function to extract the branch name from the branch reference string.
- Integrate the
getBranchNameFromRef
function in thewriteNewWord
andeditExistingWord
functions in theword-editor
script located in thesrc/lib
directory. Replace the lineconst branch = repoBranchRef.split("/").slice(2).join("/");
in both functions withconst 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 😉