// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { parse } from "./parse.ts";

/**
 * 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"));
 * ```
 *
 * @param version The version string to check
 * @returns `true` if the string can be parsed as SemVer, `false` otherwise
 */
export function canParse(version: string): boolean {
  try {
    parse(version);
    return true;
  } catch (err) {
    if (!(err instanceof TypeError)) {
      throw err;
    }
    return false;
  }
}

// denoCacheMetadata={"headers":{"report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=S6ERN%2B5Wv7ON7qQlYpMVUc%2BTAXtFgGpqcN2eR4%2BqcgE7WtP4pf%2BtHLQhQ3ftVKE1FVUS1BRJLlzNzNCEG0AxfDjLlzsTZi7I5xV2qm%2B4Dn%2FSCbKD068p0lU%3D\"}]}","accept-ranges":"bytes","cf-cache-status":"HIT","cache-control":"public, max-age=31536000, immutable","x-robots-tag":"noindex","vary":"Origin","content-type":"text/typescript","set-cookie":"__cf_bm=6guvAg0ideRw66ZaPcMRv5IykKOLYr.AWmOCaLAGTec-1785241875.1714325-1.0.1.1-hduCPEkPwUjbcqbJuyRZobpVHsExS3wNQtyXVPiAD336jm3YD79YBYruyeld4.AuckGhF7fvRL36u8Y1montZ6eAo5p01v_r2bqXoLIfgSh9azE_uwVlTO.ADMcuCHAD; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cross-origin-resource-policy":"cross-origin","age":"36703","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","alt-svc":"h3=\":443\"; ma=86400","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","x-jsr-backend":"modules","content-length":"754","x-content-type-options":"nosniff","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","access-control-expose-headers":"*","cf-ray":"a223e657ca8f7db6-LAX","etag":"\"4c49e37ae098fd70a8476697fc29b8d6\"","server":"cloudflare"},"url":"https://jsr.io/@std/semver/0.224.3/can_parse.ts","time":1785241875}