mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-29 07:50:33 +00:00
27 lines
697 B
JavaScript
27 lines
697 B
JavaScript
export function findByName(list, name, field = 'name') {
|
|
return list.find((item) => item[field] === name);
|
|
}
|
|
|
|
export function findIndexByName(list, name, field = 'name') {
|
|
return list.findIndex((item) => item[field] === name);
|
|
}
|
|
|
|
export function deleteByName(list, name, field = 'name') {
|
|
const idx = findIndexByName(list, name, field);
|
|
list.splice(idx, 1);
|
|
}
|
|
|
|
export function updateByName(list, name, newItem, field = 'name') {
|
|
const idx = findIndexByName(list, name, field);
|
|
list[idx] = newItem;
|
|
}
|
|
|
|
export function insertByPosition(list, item, position = 'bottom') {
|
|
if (position === 'top') {
|
|
list.unshift(item);
|
|
return;
|
|
}
|
|
|
|
list.push(item);
|
|
}
|