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

import type { FormatInputPathObject } from "../_interface.ts";

export function _format(
  sep: string,
  pathObject: FormatInputPathObject,
): string {
  const dir: string | undefined = pathObject.dir || pathObject.root;
  const base: string = pathObject.base ||
    (pathObject.name || "") + (pathObject.ext || "");
  if (!dir) return base;
  if (base === sep) return dir;
  if (dir === pathObject.root) return dir + base;
  return dir + sep + base;
}

export function assertArg(pathObject: FormatInputPathObject) {
  if (pathObject === null || typeof pathObject !== "object") {
    throw new TypeError(
      `The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`,
    );
  }
}

// denoCacheMetadata={"headers":{"nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cf-ray":"a223e6589cbf7db6-LAX","date":"Tue, 28 Jul 2026 12:31:15 GMT","accept-ranges":"bytes","age":"2869020","x-robots-tag":"noindex","set-cookie":"__cf_bm=H_N1CUzvXVofgaBedbys0U.TU.DiKCeXTDobYowzkxg-1785241875.293417-1.0.1.1-2douQdN4Eq2ncqDGDJfkp_938zzCGmOX4RosfSaAArwW7qiOAPPCjWUnir.TfMnd4IPHvy_4APbkvcGJX5fkY2QWbK3iMUYDsZN_JOusL0gOJ6MMY1eckNb4NPyd0iMd; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cf-cache-status":"HIT","vary":"Origin","server":"cloudflare","content-type":"text/typescript","cross-origin-resource-policy":"cross-origin","content-length":"827","cache-control":"public, max-age=31536000, immutable","x-content-type-options":"nosniff","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=MgseLiBkMYcfI80CilghhFDu2lh8pfK1PYGrrkYi%2BNIaS6MHisnuIw1I1oNXcCQr%2B5Y1kevnBxjX2gwLlvXR3zPUFhbj%2FcXLFABRnyvUYFEK%2FCvD%2BRMWGy8%3D\"}]}","etag":"\"7cebbe047e5b02bcb4a1136d3f879a94\"","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';","access-control-allow-origin":"*","access-control-expose-headers":"*","x-jsr-backend":"modules"},"url":"https://jsr.io/@std/path/0.224.0/_common/format.ts","time":1785241875}