Skip to main content
Utility functions for working with semantic version strings and determining version relationships.

compareVersions()

Compares two version strings.
function compareVersions(v1: string, v2: string): -1 | 0 | 1

Parameters

v1
string
required
First version string to compare (e.g., "1.2.0")
v2
string
required
Second version string to compare (e.g., "1.3.0")

Returns

return
-1 | 0 | 1
  • -1 if v1 < v2
  • 0 if versions are equal
  • 1 if v1 > v2

Examples

import { compareVersions } from 'react-native-nitro-version-check';

compareVersions("1.2.0", "1.3.0") // -1 (v1 is older)
compareVersions("2.0.0", "1.9.9") //  1 (v1 is newer)
compareVersions("1.0.0", "1.0.0") //  0 (equal)

Behavior

  • Versions are parsed as semantic version triplets (major.minor.patch)
  • Missing parts default to 0 (e.g., "1.2" is treated as "1.2.0")
  • Comparison is performed left-to-right (major, then minor, then patch)
  • Non-numeric parts are coerced to 0

Type Definitions

UpdateLevel

type UpdateLevel = "major" | "minor" | "patch"
Defines the granularity of version comparison:
  • "major" — Major version changes (X.0.0)
  • "minor" — Minor version changes (0.X.0)
  • "patch" — Patch version changes (0.0.X)
Used by needsUpdate() to filter update checks by significance level.

Build docs developers (and LLMs) love