Skip to content

Commit

Permalink
Extract string normalization to a partial script
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico committed Mar 26, 2024
1 parent 37662fa commit 76edff5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
9 changes: 1 addition & 8 deletions views/conflict.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
</main>
<%- include('./partials/footer'); %>
<%- include('./partials/scripts/general'); %>
<%- include('./partials/scripts/normalize') %>
<%- include('./partials/scripts/hljs'); %>
<script src="/socket.io/socket.io.js"></script>
<script>
Expand All @@ -353,14 +354,6 @@
const redirect = () => window.location.replace("/conflicts");
const toast = (element) => new bootstrap.Toast(element).show();
const normalize = (name) => {
const coalesced = name ?? "";
const normalized = coalesced.replaceAll(/\s+/g, " ");
const lowercase = normalized.toLowerCase();
const trimmed = lowercase.trim();
return (trimmed.length === 0) ? null : trimmed;
};
const addOption = (label) => {
const search = normalize(labelFilter.value);
const options = labelInstanceSelect.options;
Expand Down
9 changes: 1 addition & 8 deletions views/label.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
</main>
<%- include('./partials/footer'); %>
<%- include('./partials/scripts/general'); %>
<%- include('./partials/scripts/normalize') %>
<%- include('./partials/scripts/table-download'); %>
<script src="/socket.io/socket.io.js"></script>
<script>
Expand All @@ -324,14 +325,6 @@
const toast = (element) => new bootstrap.Toast(element).show();
const normalize = (name) => {
const coalesced = name ?? "";
const normalized = coalesced.replaceAll(/\s+/g, " ");
const lowercase = normalized.toLowerCase();
const trimmed = lowercase.trim();
return (trimmed.length === 0) ? null : trimmed;
};
renameModalForm.addEventListener("submit", (event) => {
event.preventDefault();
const form = event.target;
Expand Down
9 changes: 9 additions & 0 deletions views/partials/scripts/normalize.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
const normalize = (name) => {
const coalesced = name ?? "";
const normalized = coalesced.replaceAll(/\s+/g, " ");
const lowercase = normalized.toLowerCase();
const trimmed = lowercase.trim();
return (trimmed.length === 0) ? null : trimmed;
};
</script>
9 changes: 1 addition & 8 deletions views/review.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
</main>
<%- include('./partials/footer'); %>
<%- include('./partials/scripts/general'); %>
<%- include('./partials/scripts/normalize') %>
<%- include('./partials/scripts/hljs'); %>
<% if (!!reviewer && !!instance) { %>
<script src="/socket.io/socket.io.js"></script>
Expand All @@ -234,14 +235,6 @@
const refresh = () => history.go();
const toast = (element) => new bootstrap.Toast(element).show();
const normalize = (name) => {
const coalesced = name ?? "";
const normalized = coalesced.replaceAll(/\s+/g, " ");
const lowercase = normalized.toLowerCase();
const trimmed = lowercase.trim();
return (trimmed.length === 0) ? null : trimmed;
};
const addOption = (label) => {
const search = normalize(labelFilter.value);
const options = labelInstanceSelect.options;
Expand Down

0 comments on commit 76edff5

Please sign in to comment.