apps-script-utils 2.1.1 Help

versionCompare

function versionCompare(version1: string, version2: string): number;

Each dot-separated group is compared as a number, so 1.10 is above 1.2 — which a string comparison gets backwards. A missing group counts as zero, which makes "2" and "2.0" equal.

Both arguments must satisfy isValidVersion: digits and dots only, no pre-release suffix.

Parameters

Parameter

Type

Description

version1

string

The first version.

version2

string

The second version.

Returns

number — -1 when the first is lower, 0 when they are equal, 1 when the first is higher.

Throws

Exception

Condition

TypeError

either argument is not a valid version string.

Examples

Comparing

versionCompare("1.2.0", "1.10.0"); // => -1 versionCompare("2.0", "2"); // => 0 versionCompare("1.2.3", "1.2.3-beta"); // throws TypeError

See also

Source

src/lang/string/versionCompare.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.