Extract regex to constant in module scope

This commit is contained in:
Josh Goldberg 2023-04-13 12:59:33 -04:00
Родитель c29a11a8d7
Коммит 11f27cd8a3
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -158,6 +158,8 @@ function getFileUrlVolumeSeparatorEnd(url: string, start: number) {
return -1;
}
const dataApplicationRegex = /^(data:(?:[a-z0-9]+(?:\/[a-z0-9]+))?(?:;base64)?,)./;
/**
* Returns length of the root part of a path or URL (i.e. length of "/", "x:/", "//server/share/, file:///user/files").
* If the root is part of a URL, the twos-complement of the root length is returned.
@ -215,7 +217,7 @@ function getEncodedRootLength(path: string): number {
}
// Data: "data:application/typescript,42"
const match = path.match(/*regexp*/ /^(data:(?:[a-z0-9]+(?:\/[a-z0-9]+))?(?:;base64)?,)./);
const match = dataApplicationRegex.exec(path);
if (match) {
return ~match[1].length;
}