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 type { SemVer } from "./types.ts";
|
|
|
|
import { compare } from "./compare.ts";
|
|
|
|
|
|
|
|
/**
|
2024-06-28 05:47:34 +00:00
|
|
|
* Less than or equal to comparison for two SemVers.
|
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, lessOrEqual } from "@std/semver";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +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.4");
|
2024-06-28 05:47:34 +00:00
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* assert(lessOrEqual(version1, version2));
|
|
|
|
* assert(!lessOrEqual(version2, version1));
|
|
|
|
* assert(lessOrEqual(version1, version1));
|
2024-05-27 10:03:20 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* @param version1 the first version to compare
|
|
|
|
* @param version2 the second version to compare
|
|
|
|
* @returns `true` if `version1` is less than or equal to `version2`, `false` otherwise
|
2024-01-23 04:04:12 +00:00
|
|
|
*/
|
2024-08-19 04:33:42 +00:00
|
|
|
export function lessOrEqual(version1: SemVer, version2: SemVer): boolean {
|
|
|
|
return compare(version1, version2) <= 0;
|
2024-01-23 04:04:12 +00:00
|
|
|
}
|