All files / rusted-chromium/utils sort.utils.ts

50% Statements 18/36
50% Branches 2/4
29.41% Functions 5/17
53.84% Lines 14/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 674x   4x           4x                               4x 8x   8x 6x   2x 2x                 4x         8x         4x 9x           9x                  
import { ComparableVersion } from '../commons/ComparableVersion'
import type { MappedVersion } from '../commons/MappedVersion'
import { Compared } from '../interfaces/enums'
import type { IListStore } from '../interfaces/store.interfaces'
 
/**
 * Ascending sort comparator for ComparableVersion 
 */
export function sortAscendingComparableVersions(a: ComparableVersion, b: ComparableVersion): -1 | 0 | 1 {
    const compared = ComparableVersion.compare(a, b)
 
    Iif (compared === Compared.GREATER) {
        return 1
    }
    Iif (compared === Compared.LESS) {
        return -1
    }
 
    return 0
}
 
/**
 * Descending sort comparator for ComparableVersion 
 */
export function sortDescendingComparableVersions(a: ComparableVersion, b: ComparableVersion): -1 | 0 | 1 {
    const compared = ComparableVersion.compare(a, b)
 
    if (compared === Compared.LESS) {
        return 1
    }
    if (compared === Compared.GREATER) {
        return -1
    }
 
    return 0
}
 
/**
 * Ascending sort comparator for MappedVersion
 */
export const sortAscendingMappedVersions = (a: MappedVersion, b: MappedVersion): -1 | 0 | 1 => sortAscendingComparableVersions(a.comparable, b.comparable)
 
/**
* Descending sort comparator for MappedVersion
*/
export const sortDescendingMappedVersions = (a: MappedVersion, b: MappedVersion): -1 | 0 | 1 => sortDescendingComparableVersions(a.comparable, b.comparable)
 
/**
* Immutally sorts the entries of the given Store
*/
export function sortStoreEntries(store: IListStore): IListStore {
    return {
        win: {
            x64: [...store.win.x64].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
            x86: [...store.win.x86].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
        },
        linux: {
            x64: [...store.linux.x64].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
            x86: [...store.linux.x86].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
        },
        mac: {
            x64: [...store.mac.x64].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
            arm: [...store.mac.arm].map(v => new ComparableVersion(v)).sort(sortAscendingComparableVersions).map(c => c.toString()),
        },
    }
}