import semver from 'semver'; /** * Whether the iOS APNs message was configured as a background update notification. */ export type CheckOptions = { /** * The semver of your current app version */ curVersion?: string; /** * This will run right after the store version is fetched in case you want to change it before it's compared as a semver */ toSemverConverter?: ( version: SemverVersionCode | SemverVersion ) => SemverVersion; /** * By default this library uses semver behind the scenes to compare the store version with the curVersion value, but you can pass your own version comparator if you want to */ customVersionComparator?: ( v1: SemverVersion, v2: SemverVersion ) => -1 | 0 | 1; /** * ISO 3166-1 country code (iOS only) */ country?: string; }; export type SemverVersion = string; export type SemverVersionCode = number; export const compareVersions = ( versionToCheck: SemverVersion, checkAgainst: SemverVersion ) => { if (versionToCheck && checkAgainst) { // The version consists of 3 parts. // 1 MAJOR, 2 MINOR, 3 LIVE_RELOAD_REV each of which contain 3 digits return semver.compare( // @ts-ignore semver.coerce(versionToCheck), semver.coerce(checkAgainst) ); } if (versionToCheck && checkAgainst == null) { return 1; } if (checkAgainst && versionToCheck == null) { return -1; } return 0; };