// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
// This module is browser compatible.

export function stripTrailingSeparators(
  segment: string,
  isSep: (char: number) => boolean,
): string {
  if (segment.length <= 1) {
    return segment;
  }

  let end = segment.length;

  for (let i = segment.length - 1; i > 0; i--) {
    if (isSep(segment.charCodeAt(i))) {
      end = i;
    } else {
      break;
    }
  }

  return segment.slice(0, end);
}

// denoCacheMetadata={"headers":{"age":"2869020","set-cookie":"__cf_bm=WJezT4syYyFQKYHuJ.H.Fvp6r4lYcvPBAfhQIP6Qzog-1785241875.2806208-1.0.1.1-Rn2ldc67gTZ2dBO2M8SBW0Hsg7mZv4iqIJziQl2hlMrGm1geNHc.3_7dZ9.09d5sLhCYJdmsdEOKZY9Tz.lEy7MJD_rXxH1WQ0Ok.CIv4M1xWflmHGMIc7UqAh5wljCB; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cf-cache-status":"HIT","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';","content-type":"text/typescript","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=2eCFg5zHjRV6SM2ye1NBB%2BXRoXJrGQ8urI47F18BENhYpMVrumaQoY%2BgbDEIFOIxJrru83dNXv7jaqiRSQEmWKPbhRuQd%2BFAznFRAkXxGzhhq72OFFTFUa8%3D\"}]}","x-jsr-backend":"modules","etag":"\"4f57deda21d8130960095805a8fe4059\"","date":"Tue, 28 Jul 2026 12:31:15 GMT","server":"cloudflare","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","x-content-type-options":"nosniff","cache-control":"public, max-age=31536000, immutable","content-length":"592","cf-ray":"a223e6587c867db6-LAX","access-control-allow-origin":"*","access-control-expose-headers":"*","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","vary":"Origin","accept-ranges":"bytes"},"url":"https://jsr.io/@std/path/0.224.0/_common/strip_trailing_separators.ts","time":1785241875}