1
>
/*---------------------------------------------------------------------------------------------
extpath.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { CharCode } from './charCode.js';
7
>
import { isAbsolute, join, normalize, posix, sep } from './path.js';
8
>
import { isWindows } from './platform.js';
9
>
import { equalsIgnoreCase, rtrim, startsWithIgnoreCase } from './strings.js';
10
>
import { isNumber } from './types.js';
11
>
12
>
export function isPathSeparator(code: number) {
13
return code === CharCode.Slash || code === CharCode.Backslash;
14
}
16
>
/**
17
>
* Takes a Windows OS path and changes backward slashes to forward slashes.
18
>
* This should only be done for OS paths from Windows (or user provided paths potentially from Windows).
19
>
* Using it on a Linux or MaxOS path might change it.
20
>
*/
21
>
export function toSlashes(osPath: string) {
22
return osPath.replace(/[\\/]/g, posix.sep);
23
}
25
>
/**
26
>
* Takes a Windows OS path (using backward or forward slashes) and turns it into a posix path:
27
>
* - turns backward slashes into forward slashes
28
>
* - makes it absolute if it starts with a drive letter
29
>
* This should only be done for OS paths from Windows (or user provided paths potentially from Windows).
30
>
* Using it on a Linux or MaxOS path might change it.
31
>
*/
32
>
export function toPosixPath(osPath: string) {
33
if (osPath.indexOf('/') === -1) {
34
osPath = toSlashes(osPath);