2024-01-01 21:11:32 +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.
|
2023-10-24 04:39:55 +00:00
|
|
|
import { parse } from "./parse.ts";
|
|
|
|
|
2024-05-27 10:03:20 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the string can be parsed as SemVer.
|
|
|
|
*
|
|
|
|
* @example Usage
|
|
|
|
* ```ts
|
|
|
|
* import { canParse } from "@std/semver/can-parse";
|
|
|
|
* import { assert, assertFalse } from "@std/assert";
|
|
|
|
*
|
|
|
|
* assert(canParse("1.2.3"));
|
|
|
|
* assertFalse(canParse("invalid"));
|
|
|
|
* ```
|
|
|
|
*
|
2024-08-19 04:33:42 +00:00
|
|
|
* @param value The version string to check
|
2024-05-27 10:03:20 +00:00
|
|
|
* @returns `true` if the string can be parsed as SemVer, `false` otherwise
|
|
|
|
*/
|
2024-08-19 04:33:42 +00:00
|
|
|
export function canParse(value: string): boolean {
|
2023-10-24 04:39:55 +00:00
|
|
|
try {
|
2024-08-19 04:33:42 +00:00
|
|
|
parse(value);
|
2023-10-24 04:39:55 +00:00
|
|
|
return true;
|
2024-07-31 04:01:17 +00:00
|
|
|
} catch {
|
2023-10-24 04:39:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|