All files / path / _common / to_file_url.ts

100.00% Branches 2/2
100.00% Functions 1/1
100.00% Lines 13/13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
 
x68
x68
x68
x68
x68
x68
x68
x68
 
x68
x73
x16
x73
x73















// Copyright 2018-2026 the Deno authors. 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;
  });
}