// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Range, SemVer } from "./types.ts";
import { testComparatorSet } from "./_test_comparator_set.ts";

/**
 * Test to see if the version satisfies the range.
 *
 * @example Usage
 * ```ts
 * import { parse, parseRange, satisfies } from "@std/semver";
 * import { assert, assertFalse } from "@std/assert";
 *
 * const version = parse("1.2.3");
 * const range0 = parseRange(">=1.0.0 <2.0.0");
 * const range1 = parseRange(">=1.0.0 <1.3.0");
 * const range2 = parseRange(">=1.0.0 <1.2.3");
 *
 * assert(satisfies(version, range0));
 * assert(satisfies(version, range1));
 * assertFalse(satisfies(version, range2));
 * ```
 * @param version The version to test
 * @param range The range to check
 * @returns true if the version is in the range
 */
export function satisfies(
  version: SemVer,
  range: Range,
): boolean {
  return range.some((set) => testComparatorSet(version, set));
}

// denoCacheMetadata={"headers":{"cross-origin-resource-policy":"cross-origin","alt-svc":"h3=\":443\"; ma=86400","content-type":"text/typescript","cache-control":"public, max-age=31536000, immutable","vary":"Origin","access-control-allow-origin":"*","access-control-expose-headers":"*","accept-ranges":"bytes","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';","etag":"\"9f1d5c7d71e2c97ed9bb8594840a54c8\"","cf-ray":"a223e657ca6e7db6-LAX","content-length":"970","x-content-type-options":"nosniff","set-cookie":"__cf_bm=zgFeU8VggFEw_lUI0ZT.PR58JRv2tbn8.BIcZd8_cKw-1785241875.1628282-1.0.1.1-kxTLi0HL.WSYnzGye.l2b2BiHgQYeUFpmkF4I3SmNswrGJsQa47uqDuBmPA0wZlYJ69JCUG5b3hg7.4I5bY1_9HzJvqDkxGBfMdXUb.v2ZYZbmPZH6LEi.zdEuUiHtg6; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","age":"1908149","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=096kX6f8vgvq0IcHUlbwKzHU86Cs1tZ4y%2BT%2BGtr%2FEA0fjY4yYnkkN8IOG9KHUT66Tr9c1Gog7Yr4a6W1%2BIoNVlemhHfG9CVl8l6UpF2UfGRF4uIEG5EJ8sY%3D\"}]}","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","server":"cloudflare","cf-cache-status":"HIT","x-jsr-backend":"modules","x-robots-tag":"noindex"},"url":"https://jsr.io/@std/semver/0.224.3/satisfies.ts","time":1785241875}