feat: utils function move & delete array item
This commit is contained in:
parent
fc002b9ca0
commit
1822051a78
1 changed files with 30 additions and 0 deletions
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue