-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
62 lines (57 loc) · 1.77 KB
/
utils.ts
File metadata and controls
62 lines (57 loc) · 1.77 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { JoinForm, LoginForm, OptionCreator } from "./types";
export const cls = (...classes: (string | undefined | boolean)[]) =>
classes.filter((className) => className).join(" ");
export const cycler = (cycle: number) => (num: number) =>
((num % cycle) + cycle) % cycle;
export const attachComma = (num: number) =>
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
export const optionCreator: OptionCreator =
(option) =>
(customOpts = {}) => {
const [name, opts] = option;
return [name, { ...opts, ...customOpts }];
};
export const regOptLogin = {
email: optionCreator<LoginForm>([
"email",
{
required: "email이 입력되지 않았습니다.",
pattern: {
value:
/[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]$/i,
message: "email 형식을 확인해주세요",
},
},
]),
password: optionCreator<LoginForm>([
"password",
{
required: "비밀번호를 입력해주세요",
pattern: {
value: /(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])/i,
message: "영문, 숫자, 특수문자를 조합해서 입력해주세요.",
},
minLength: {
value: 8,
message: "비밀번호는 최소 8자 이상 입력해 주세요",
},
maxLength: {
value: 16,
message: "비밀번호는 최대 16자 까지만 입력해 주세요",
},
},
]),
};
export const regOptJoin = {
...regOptLogin,
size: optionCreator<JoinForm>(["size", {}]),
age: [
optionCreator<JoinForm>(["age.0", {}]),
optionCreator<JoinForm>(["age.1", {}]),
optionCreator<JoinForm>(["age.2", {}]),
],
notification: [
optionCreator<JoinForm>(["notification.0", {}]),
optionCreator<JoinForm>(["notification.1", {}]),
],
};