## @strpc 기존 RPC를 package화 ### @strpc/express express의 middleware + router 결함 ## @sammo 게임 전체 - server, client - gateway_server, gateway_client
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { unwrap } from "./unwrap.js";
|
|
|
|
export function isEmail(addr: string): boolean {
|
|
return String(addr)
|
|
.toLowerCase()
|
|
.match(
|
|
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
) !== null;
|
|
}
|
|
|
|
export function isIPAddr4(addr: string): boolean {
|
|
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(addr)) {
|
|
return (true)
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function hexToRgb(hex: string): { r: number; g: number; b: number; } | null {
|
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
return result ? {
|
|
r: parseInt(result[1], 16),
|
|
g: parseInt(result[2], 16),
|
|
b: parseInt(result[3], 16)
|
|
} : null;
|
|
}
|
|
|
|
export function isBrightColor(color: string): boolean {
|
|
const cv = unwrap(hexToRgb(color));
|
|
if ((cv.r * 0.299 + cv.g * 0.587 + cv.b * 0.114) > 140) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|