UNPKG

3.14 kBTypeScriptView Raw
1import { Maybe } from './common/types';
2export declare enum Branch {
3 Public = "public",
4 Pretty = "p",
5 Private = "private",
6 PrivateLog = "privateLog",
7 Version = "version"
8}
9export declare enum Kind {
10 Directory = "directory",
11 File = "file"
12}
13export declare type Path = string[];
14export declare type DirectoryPath = {
15 directory: Path;
16};
17export declare type FilePath = {
18 file: Path;
19};
20/**
21 * The primarily used type for paths.
22 */
23export declare type DistinctivePath = DirectoryPath | FilePath;
24/**
25 * Utility function to create a `DirectoryPath`
26 */
27export declare function directory(...args: Path): DirectoryPath;
28/**
29 * Utility function to create a `FilePath`
30 */
31export declare function file(...args: Path): FilePath;
32/**
33 * Utility function to create a root `DirectoryPath`
34 */
35export declare function root(): DirectoryPath;
36/**
37 * Transform a string into a `DistinctivePath`.
38 *
39 * Directories should have the format `path/to/dir/` and
40 * files should have the format `path/to/file`.
41 *
42 * Leading forward slashes are removed too, so you can pass absolute paths.
43 */
44export declare function fromPosix(path: string): DistinctivePath;
45/**
46 * Transform a `DistinctivePath` into a string.
47 *
48 * Directories will have the format `path/to/dir/` and
49 * files will have the format `path/to/file`.
50 */
51export declare function toPosix(path: DistinctivePath, { absolute }?: {
52 absolute: boolean;
53}): string;
54/**
55 * Combine two `DistinctivePath`s.
56 */
57export declare function combine(a: DirectoryPath, b: DistinctivePath): DistinctivePath;
58/**
59 * Is this `DistinctivePath` of the given `Branch`?
60 */
61export declare function isBranch(branch: Branch, path: DistinctivePath): boolean;
62/**
63 * Is this `DistinctivePath` a directory?
64 */
65export declare function isDirectory(path: DistinctivePath): path is DirectoryPath;
66/**
67 * Is this `DistinctivePath` a file?
68 */
69export declare function isFile(path: DistinctivePath): path is FilePath;
70/**
71 * Is this `DirectoryPath` a root directory?
72 */
73export declare function isRootDirectory(path: DirectoryPath): boolean;
74/**
75 * Check if two `DistinctivePath` have the same `Branch`.
76 */
77export declare function isSameBranch(a: DistinctivePath, b: DistinctivePath): boolean;
78/**
79 * Check if two `DistinctivePath` are of the same kind.
80 */
81export declare function isSameKind(a: DistinctivePath, b: DistinctivePath): boolean;
82/**
83 * What `Kind` of path are we dealing with?
84 */
85export declare function kind(path: DistinctivePath): Kind;
86/**
87 * Map a `DistinctivePath`.
88 */
89export declare function map(fn: (p: Path) => Path, path: DistinctivePath): DistinctivePath;
90/**
91 * Get the parent directory of a `DistinctivePath`.
92 */
93export declare function parent(path: DistinctivePath): Maybe<DirectoryPath>;
94/**
95 * Remove the `Branch` of a `DistinctivePath` (ie. the top-level directory)
96 */
97export declare function removeBranch(path: DistinctivePath): DistinctivePath;
98/**
99 * Unwrap a `DistinctivePath`.
100 */
101export declare function unwrap(path: DistinctivePath): Path;
102/**
103 * Render a raw `Path` to a string for logging purposes.
104 */
105export declare function log(path: Path): string;