// TODO: Add it from UI-Utils
/** Comparator for Array.sort when sorting arrays of objects by given key with optional order. */
export function compareBy(key, order = 'asc') {
    const ord = order === 'asc' ? 1 : -1;
    return (item1, item2) => {
        if (order === null)
            return 0;
        const a = item1[key];
        const b = item2[key];
        if (typeof a === 'string' && typeof b === 'string') {
            return a.localeCompare(b) * ord;
        }
        else if (typeof a === 'number' && typeof b === 'number') {
            return a > b ? ord : a < b ? -ord : 0;
        }
        return 0;
    };
}
// TODO: Add it from UI-Utils
/** Adds given item to the array if it wasn't there yet, or removes it otherwise. */
export function toggleItem(array, item) {
    return array.includes(item) ? array.filter(it => it !== item) : [...array, item];
}
//# sourceMappingURL=array.js.map