Skip to content

Commit 58e25ce

Browse files
committed
refactor: move the validator functions into a seperate file
1 parent 46d6d89 commit 58e25ce

File tree

11 files changed

+54
-54
lines changed

11 files changed

+54
-54
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ If you would like to use other themes, and add one for yourself and others, plea
7474
## ❗ Important
7575
- We suggest you not put too many badges inside one card, because the loading time can be too slow, and it can overflow the 15s limit, which results in a card that's not displayed. The maximum amount of badges inside one card should be around 16. If you want to display more, do it in two or three cards.
7676
- If you use our [Demo Website](https://github-readme-tech-stack.vercel.app) to generate and customize your card, and it displays an empty screen, it's because your browser cached the previously deployed names of the JS bundles. In order to resolve this issue, clear your browser's cache or open the site in incognito mode.
77+
- If you use a badge that has an invalid icon, it results in an inappropriate badge alignment. Please use badges that have valid icons. You can browse between the icons [here](https://simpleicons.org/).
7778

7879
<hr>
7980

client/build/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.384a4c78.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

client/build/static/js/main.b185e28e.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.384a4c78.js.LICENSE.txt renamed to client/build/static/js/main.b185e28e.js.LICENSE.txt

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.384a4c78.js.map renamed to client/build/static/js/main.b185e28e.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/components/popups/LinePopup.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FiSave } from "react-icons/fi";
55
import SecondaryButton from "../buttons/SecondaryButton";
66
import Input from "../input/Input";
77
import ColorInput from "../input/ColorInput";
8+
import { validateHex, validateIconAndLabel } from "../../utils/validate";
89

910
interface LinePopupProps {
1011
isActive: boolean;
@@ -18,31 +19,6 @@ const LinePopup: FC<LinePopupProps> = (props) => {
1819
const [label, setLabel] = useState<string>("react");
1920
const [color, setColor] = useState<string>("#3498db");
2021

21-
const validateIconAndLabel = (
22-
val: string,
23-
iorl: "icon" | "label"
24-
): string => {
25-
if (val.length < 3 || val.length > 32) {
26-
return `The ${iorl} should be between 2 and 32 characters.`;
27-
}
28-
29-
return "";
30-
};
31-
32-
const validateHex = (val: string): string => {
33-
if (val === "auto") {
34-
return "";
35-
}
36-
37-
// starts with #, 3 or 6 characters long, contains only hexadecimal values
38-
const hexColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
39-
if (!hexColorRegex.test(val)) {
40-
return "The color should be a valid hexadecimal color or the value auto.";
41-
}
42-
43-
return "";
44-
};
45-
4622
const handleSave = () => {
4723
props.addBadge({
4824
color: color,

client/src/pages/Options.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import NumberInput from "../components/input/NumberInput";
1212
import TrueFalseInput from "../components/input/TrueFalseInput";
1313
import Input from "../components/input/Input";
1414
import SecondaryButton from "../components/buttons/SecondaryButton";
15+
import { validateBorderRadius } from "../utils/validate";
1516

1617
interface OptionsProps {
1718
setLink: (link: string) => void;
@@ -56,24 +57,6 @@ const Options: FC<OptionsProps> = (props) => {
5657
setCard({ ...card, lines: lines });
5758
};
5859

59-
const validateBorderRadius = (val: string): string => {
60-
const num = parseInt(val);
61-
62-
if (val.trim() === "") {
63-
return "Please provide a border radius!";
64-
}
65-
66-
if (!val.split("").every((x) => "0123456789.".includes(x))) {
67-
return "Please provide a valid number!";
68-
}
69-
70-
if (num > 50 || num < 0) {
71-
return "Please provide a value between 0 and 50";
72-
}
73-
74-
return "";
75-
};
76-
7760
return (
7861
<section
7962
className="border border-solid border-gh-border rounded-md

client/src/utils/validate.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export const validateHex = (val: string): string => {
2+
if (val === "auto") {
3+
return "";
4+
}
5+
6+
// starts with #, 3 or 6 characters long, contains only hexadecimal values
7+
const hexColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
8+
if (!hexColorRegex.test(val)) {
9+
return "The color should be a valid hexadecimal color or the value auto.";
10+
}
11+
12+
return "";
13+
};
14+
15+
export const validateIconAndLabel = (
16+
val: string,
17+
iorl: "icon" | "label"
18+
): string => {
19+
if (val.length < 3 || val.length > 32) {
20+
return `The ${iorl} should be between 2 and 32 characters.`;
21+
}
22+
23+
return "";
24+
};
25+
26+
export const validateBorderRadius = (val: string): string => {
27+
const num = parseInt(val);
28+
29+
if (val.trim() === "") {
30+
return "Please provide a border radius!";
31+
}
32+
33+
if (!val.split("").every((x) => "0123456789.".includes(x))) {
34+
return "Please provide a valid number!";
35+
}
36+
37+
if (num > 50 || num < 0) {
38+
return "Please provide a value between 0 and 50";
39+
}
40+
41+
return "";
42+
};

0 commit comments

Comments
 (0)