-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpath.d.ts
111 lines (111 loc) · 3.77 KB
/
path.d.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { BaseException } from '../exception';
import { TemplateTag } from '../utils/literals';
export declare class InvalidPathException extends BaseException {
constructor(path: string);
}
export declare class PathMustBeAbsoluteException extends BaseException {
constructor(path: string);
}
export declare class PathCannotBeFragmentException extends BaseException {
constructor(path: string);
}
/**
* A Path recognized by most methods in the DevKit.
*/
export type Path = string & {
__PRIVATE_DEVKIT_PATH: void;
};
/**
* A Path fragment (file or directory name) recognized by most methods in the DevKit.
*/
export type PathFragment = Path & {
__PRIVATE_DEVKIT_PATH_FRAGMENT: void;
};
/**
* The Separator for normalized path.
*/
export declare const NormalizedSep: Path;
/**
* The root of a normalized path.
*/
export declare const NormalizedRoot: Path;
/**
* Split a path into multiple path fragments. Each fragments except the last one will end with
* a path separator.
* @param {Path} path The path to split.
* @returns {Path[]} An array of path fragments.
*/
export declare function split(path: Path): PathFragment[];
/**
*
*/
export declare function extname(path: Path): string;
/**
* Return the basename of the path, as a Path. See path.basename
*/
export declare function basename(path: Path): PathFragment;
/**
* Return the dirname of the path, as a Path. See path.dirname
*/
export declare function dirname(path: Path): Path;
/**
* Join multiple paths together, and normalize the result. Accepts strings that will be
* normalized as well (but the original must be a path).
*/
export declare function join(p1: Path, ...others: string[]): Path;
/**
* Returns true if a path is absolute.
*/
export declare function isAbsolute(p: Path): boolean;
/**
* Returns a path such that `join(from, relative(from, to)) == to`.
* Both paths must be absolute, otherwise it does not make much sense.
*/
export declare function relative(from: Path, to: Path): Path;
/**
* Returns a Path that is the resolution of p2, from p1. If p2 is absolute, it will return p2,
* otherwise will join both p1 and p2.
*/
export declare function resolve(p1: Path, p2: Path): Path;
export declare function fragment(path: string): PathFragment;
/**
* Reset the cache. This is only useful for testing.
* @private
*/
export declare function resetNormalizeCache(): void;
/**
* Normalize a string into a Path. This is the only mean to get a Path type from a string that
* represents a system path. This method cache the results as real world paths tend to be
* duplicated often.
* Normalization includes:
* - Windows backslashes `\\` are replaced with `/`.
* - Windows drivers are replaced with `/X/`, where X is the drive letter.
* - Absolute paths starts with `/`.
* - Multiple `/` are replaced by a single one.
* - Path segments `.` are removed.
* - Path segments `..` are resolved.
* - If a path is absolute, having a `..` at the start is invalid (and will throw).
* @param path The path to be normalized.
*/
export declare function normalize(path: string): Path;
/**
* The no cache version of the normalize() function. Used for benchmarking and testing.
*/
export declare function noCacheNormalize(path: string): Path;
export declare const path: TemplateTag<Path>;
export type WindowsPath = string & {
__PRIVATE_DEVKIT_WINDOWS_PATH: void;
};
export type PosixPath = string & {
__PRIVATE_DEVKIT_POSIX_PATH: void;
};
export declare function asWindowsPath(path: Path): WindowsPath;
export declare function asPosixPath(path: Path): PosixPath;
export declare function getSystemPath(path: Path): string;