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

const WHITESPACE_ENCODINGS: Record<string, string> = {
  "\u0009": "%09",
  "\u000A": "%0A",
  "\u000B": "%0B",
  "\u000C": "%0C",
  "\u000D": "%0D",
  "\u0020": "%20",
};

export function encodeWhitespace(string: string): string {
  return string.replaceAll(/[\s]/g, (c) => {
    return WHITESPACE_ENCODINGS[c] ?? c;
  });
}

// denoCacheMetadata={"headers":{"access-control-allow-origin":"*","etag":"\"64aff84ce5e29c0bbf70641ef0dc1608\"","cross-origin-resource-policy":"cross-origin","cache-control":"public, max-age=31536000, immutable","cf-ray":"a223e6589cd27db6-LAX","access-control-expose-headers":"*","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-content-type-options":"nosniff","x-jsr-backend":"modules","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-type":"text/typescript","vary":"Origin","set-cookie":"__cf_bm=TAxJYWbE0guhVxR4p0Diq47EX.hkMi0AeIRxjOgiiSo-1785241875.2951853-1.0.1.1-m1bHb_Yt94W_YTh.9fh6S9u.DprAF119cUA2jj8sp3JxraXmBxGFr6OWdiT_Fq36Nr3XQetqx1bhfALi.WyoIxGYGQiG_BTs1yyeEXEN3Ths.6zn0IzPrn5qVif_iacO; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-length":"440","accept-ranges":"bytes","x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=pOjqghrwxZ2bxvvcFXkdd%2Fvb2Qi%2FsfCUwaDdGrywS98pmNiLMDaqn1UTgPQiyKAH2AjegvaE8aLd3OiI6RbvoXUJXQPyZ4S4UAwt9JvqnOx3lNW5Ry5Pr80%3D\"}]}","server":"cloudflare","age":"3393906","cf-cache-status":"HIT","alt-svc":"h3=\":443\"; ma=86400"},"url":"https://jsr.io/@std/path/0.224.0/_common/to_file_url.ts","time":1785241875}