diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index e379134d..b84572e1 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -39,3 +39,33 @@ export function calculateAge(birthDate: Date | null | string) { return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `; } } + +export function moveItemUp(items: unknown[], index: number) { + if (index > 0) { + const temp = items[index]; + items[index] = items[index - 1]; + items[index - 1] = temp; + } +} + +export function moveItemDown(items: unknown[], index: number) { + if (index < items.length - 1) { + const temp = items[index]; + items[index] = items[index + 1]; + items[index + 1] = temp; + } +} + +export function deleteItem(items: unknown[], index: number) { + if (!items) return; + if (index >= 0 && index < items.length) { + items.splice(index, 1); + } +} + +export function formatNumberDecimal(num: number, point: number): string { + return num.toLocaleString('en-US', { + minimumFractionDigits: point, + maximumFractionDigits: point, + }); +}