// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { isWindows } from "./_os.ts";
import { relative as posixRelative } from "./posix/relative.ts";
import { relative as windowsRelative } from "./windows/relative.ts";

/**
 * Return the relative path from `from` to `to` based on current working
 * directory.
 *
 * @example Usage
 * ```ts
 * import { relative } from "@std/path/relative";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * if (Deno.build.os === "windows") {
 *   const path = relative("C:\\foobar\\test\\aaa", "C:\\foobar\\impl\\bbb");
 *   assertEquals(path, "..\\..\\impl\\bbb");
 * } else {
 *   const path = relative("/data/foobar/test/aaa", "/data/foobar/impl/bbb");
 *   assertEquals(path, "../../impl/bbb");
 * }
 * ```
 *
 * @param from Path in current working directory.
 * @param to Path in current working directory.
 * @returns The relative path from `from` to `to`.
 */
export function relative(from: string, to: string): string {
  return isWindows ? windowsRelative(from, to) : posixRelative(from, to);
}

// denoCacheMetadata={"headers":{"cross-origin-resource-policy":"cross-origin","vary":"Origin","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';","alt-svc":"h3=\":443\"; ma=86400","cf-cache-status":"HIT","cf-ray":"a223e658bd567db6-LAX","accept-ranges":"bytes","access-control-expose-headers":"*","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=9sZkkirjEgEFHClfj4Y1A3IeyuozL%2B6%2BdtbU3LWfegF8dUfOfWro4CJlD51nYknXiLMqK7TIzXTqFm9ociPBJRmtzePfn9arnFhctLKiexG2gmpTCHuQWFA%3D\"}]}","access-control-allow-origin":"*","x-content-type-options":"nosniff","age":"126790","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","set-cookie":"__cf_bm=MdBdLHu7LuBaX3eJlnZJ7hQH.mfZ8IjmBvApcYditqY-1785241875.3201237-1.0.1.1-Fq7SUIE.B3gPqxPuZ.gpfMcOKuvPRT.oHmJz5na8UWwOwblt0xFSdNXELvj9GFwqRpjsOdKfAeIWYOAphKOPq_ZTKul52GHec8N2XzMpqLpNqxvqsqDTm07myGUxFTy1; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","x-jsr-backend":"modules","etag":"\"8773031626e738754c0c12d4d4684032\"","cache-control":"public, max-age=31536000, immutable","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-type":"text/typescript","content-length":"1122","server":"cloudflare","x-robots-tag":"noindex"},"url":"https://jsr.io/@std/path/1.0.0-rc.2/relative.ts","time":1785241875}