generated from vivid-lapin/ts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser.ts
65 lines (62 loc) · 1.5 KB
/
parser.ts
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
63
64
65
export const COLOR_MAP: { [key: string]: string } = {
red: "#e54256",
pink: "#ff8080",
orange: "#ffc000",
yellow: "#ffe133",
green: "#64dd17",
cyan: "#39ccff",
blue: "#0000ff",
purple: "#d500f9",
black: "#000000",
white: "#ffffff",
white2: "#cccc99",
niconicowhite: "#cccc99",
red2: "#cc0033",
truered: "#cc0033",
pink2: "#ff33cc",
orange2: "#ff6600",
passionorange: "#ff6600",
yellow2: "#999900",
madyellow: "#999900",
green2: "#00cc66",
elementalgreen: "#00cc66",
cyan2: "#00cccc",
blue2: "#3399ff",
marineblue: "#3399ff",
purple2: "#6633cc",
nobleviolet: "#6633cc",
black2: "#666666",
}
export const POSITION_MAP: { [key: string]: string } = {
naka: "right",
ue: "top",
shita: "bottom",
}
export const SIZE_MAP: { [key: string]: string } = {
small: "small",
medium: "medium",
big: "big",
}
export const parseMail = (mail?: string) => {
let color: string | undefined = undefined
let position: string | undefined = undefined
let size: string | undefined = undefined
const commands = mail?.split(" ") || []
for (const command of commands) {
if (COLOR_MAP[command]) {
color ||= command
}
if (POSITION_MAP[command]) {
position ||= command
}
// サイズ変更はsmall以外禁止する
if (command === "small") {
size ||= SIZE_MAP[command]
}
// #から始まっていればカラーコードとみなす
if (command.startsWith("#")) {
color ||= command
}
}
return { color, position, size }
}