Skip to content

Commit 8b0f8e3

Browse files
committed
feat: Utils 4개 영역 스캐폴드 추가
1 parent 4e55133 commit 8b0f8e3

5 files changed

Lines changed: 69 additions & 7 deletions

File tree

packages/core/src/utils/date.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export function formatIsoDate(value: Date): string {
2+
return value.toISOString().slice(0, 10);
3+
}
4+
5+
export function startOfDay(value: Date): Date {
6+
const result = new Date(value);
7+
result.setHours(0, 0, 0, 0);
8+
return result;
9+
}
10+
11+
export function endOfDay(value: Date): Date {
12+
const result = new Date(value);
13+
result.setHours(23, 59, 59, 999);
14+
return result;
15+
}
16+
17+
export function addDays(value: Date, days: number): Date {
18+
const result = new Date(value);
19+
result.setDate(result.getDate() + days);
20+
return result;
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function toHex(buffer: ArrayBuffer): string {
2+
const bytes = new Uint8Array(buffer);
3+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
4+
}
5+
6+
export async function sha256Hex(value: string): Promise<string> {
7+
const encoded = new TextEncoder().encode(value);
8+
const digest = await crypto.subtle.digest("SHA-256", encoded);
9+
return toHex(digest);
10+
}
11+
12+
export function maskSecret(value: string, visibleSuffix = 4): string {
13+
if (value.length <= visibleSuffix) {
14+
return "*".repeat(value.length);
15+
}
16+
17+
const maskedLength = value.length - visibleSuffix;
18+
return `${"*".repeat(maskedLength)}${value.slice(-visibleSuffix)}`;
19+
}

packages/core/src/utils/format.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function formatCurrency(amount: number, currency = "USD", locale = "en-US"): string {
2+
return new Intl.NumberFormat(locale, {
3+
style: "currency",
4+
currency,
5+
maximumFractionDigits: 2,
6+
}).format(amount);
7+
}
8+
9+
export function formatPercent(value: number, locale = "en-US"): string {
10+
return new Intl.NumberFormat(locale, {
11+
style: "percent",
12+
maximumFractionDigits: 2,
13+
}).format(value);
14+
}

packages/core/src/utils/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
export function formatIsoDate(value: Date): string {
2-
return value.toISOString().slice(0, 10);
3-
}
4-
5-
export function isNonEmpty(value: string): boolean {
6-
return value.trim().length > 0;
7-
}
1+
export * from "./date";
2+
export * from "./format";
3+
export * from "./validation";
4+
export * from "./encryption";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function isNonEmpty(value: string): boolean {
2+
return value.trim().length > 0;
3+
}
4+
5+
export function isEmail(value: string): boolean {
6+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
7+
}
8+
9+
export function isStrongPassword(value: string): boolean {
10+
return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/.test(value);
11+
}

0 commit comments

Comments
 (0)