-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
26 lines (20 loc) · 914 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const inputText = document.querySelector("#inputText");
const branchName = document.querySelector("#branchName");
const copyButton = document.querySelector("#copyButton");
function convertToBranchName(input) {
// Trim leading and trailing whitespace and non-alphanumeric characters
let trimmedText = input.trim().replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "");
// Convert to lowercase
let lowercaseText = trimmedText.toLowerCase();
// Replace whitespace and non-alphanumeric characters with a dash
let convertedName = lowercaseText.replace(/[^a-z0-9]+/g, "-");
return convertedName;
}
inputText.addEventListener("input", function () {
const inputValue = inputText.value;
const convertedValue = convertToBranchName(inputValue);
branchName.value = convertedValue;
});
copyButton.addEventListener("click", function () {
navigator.clipboard.writeText(branchName.value);
});