-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
path-utils.ts
35 lines (32 loc) · 918 Bytes
/
path-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as path from 'path'
/**
* toPosixPath converts the given path to the posix form. On Windows, \\ will be
* replaced with /.
*
* @param pth. Path to transform.
* @return string Posix path.
*/
export function toPosixPath(pth: string): string {
return pth.replace(/[\\]/g, '/')
}
/**
* toWin32Path converts the given path to the win32 form. On Linux, / will be
* replaced with \\.
*
* @param pth. Path to transform.
* @return string Win32 path.
*/
export function toWin32Path(pth: string): string {
return pth.replace(/[/]/g, '\\')
}
/**
* toPlatformPath converts the given path to a platform-specific path. It does
* this by replacing instances of / and \ with the platform-specific path
* separator.
*
* @param pth The path to platformize.
* @return string The platform-specific path.
*/
export function toPlatformPath(pth: string): string {
return pth.replace(/[/\\]/g, path.sep)
}