2024-01-23 04:04:12 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-10 02:43:44 +00:00
|
|
|
// This module is browser compatible.
|
2024-01-23 04:04:12 +00:00
|
|
|
import { compare } from "./compare.ts";
|
|
|
|
import type { SemVer } from "./types.ts";
|
|
|
|
|
|
|
|
/**
|
2024-06-28 05:47:34 +00:00
|
|
|
* Returns `true` if both SemVers are equivalent.
|
2024-01-23 04:04:12 +00:00
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* This is equal to `compare(version1, version2) === 0`.
|
2024-05-27 10:03:20 +00:00
|
|
|
*
|
|
|
|
* @example Usage
|
|
|
|
* ```ts
|
|
|
|
* import { parse, equals } from "@std/semver";
|
2024-06-28 05:47:34 +00:00
|
|
|
* import { assert } from "@std/assert";
|
2024-05-27 10:03:20 +00:00
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* const version1 = parse("1.2.3");
|
|
|
|
* const version2 = parse("1.2.3");
|
2024-05-27 10:03:20 +00:00
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* assert(equals(version1, version2));
|
|
|
|
* assert(!equals(version1, parse("1.2.4")));
|
2024-05-27 10:03:20 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* @param version1 The first SemVer to compare
|
|
|
|
* @param version2 The second SemVer to compare
|
|
|
|
* @returns `true` if `version1` is equal to `version2`, `false` otherwise
|
2024-01-23 04:04:12 +00:00
|
|
|
*/
|
2024-08-19 04:33:42 +00:00
|
|
|
export function equals(version1: SemVer, version2: SemVer): boolean {
|
|
|
|
return compare(version1, version2) === 0;
|
2024-01-23 04:04:12 +00:00
|
|
|
}
|