char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somgenerate path typedefs from typescript impl83ff6f3

main
2.2 KiB86 linesraw
1import {
2  format,
3  fromFileUrl,
4  join,
5  parse,
6  posix,
7  relative,
8  resolve,
9  sep,
10  toFileUrl,
11  win32,
12  type ParsedPath,
13  type Path,
14  type PathObject,
15} from "avril:path";
16import {
17  delimiter as posixDelimiter,
18  format as posixFormat,
19  join as posixJoin,
20  parse as posixParse,
21  sep as posixSep,
22  toFileUrl as posixToFileUrl,
23} from "avril:path/posix";
24import {
25  delimiter as win32Delimiter,
26  join as win32Join,
27  sep as win32Sep,
28} from "avril:path/win32";
29
30const parsed: ParsedPath = parse("/a/b/c.txt");
31const dir: string = parsed.dir;
32const formatted: string = format({ dir: "/a/b", base: "c.txt" });
33const flavor: Path = posix;
34const joined: string = join("a", "b");
35const resolved: string = resolve("/a", "b");
36const related: string = relative("/a", "/a/b");
37const obj: PathObject = { root: "/", base: "x" };
38
39// The flavors pin their separators as literals.
40const posixSeparator: "/" = posixSep;
41const posixDelim: ":" = posixDelimiter;
42const win32Separator: "\\" = win32Sep;
43const win32Delim: ";" = win32Delimiter;
44// @ts-expect-error posix sep is a forward slash.
45const wrongPosixSep: "/" = win32Sep;
46// @ts-expect-error win32 sep is a backslash.
47const wrongWin32Sep: "\\" = posixSep;
48// @ts-expect-error posix delimiter is a colon.
49const wrongPosixDelim: ":" = win32Delimiter;
50// The native flavor varies by host, so its separators stay `string`: this
51// passes only for plain `string` and fails for `"/"` and `"\\"` alike.
52const arbitrary: typeof sep = "any string";
53const nativePosix: Path = posix;
54const nativeWin32: Path = win32;
55
56const url = toFileUrl("/a/b");
57const back: string = fromFileUrl(url);
58const posixUrl = posixToFileUrl("/a/b");
59const posixJoined: string = posixJoin("a", "b");
60const win32Joined: string = win32Join("a", "b");
61const posixFormatted: string = posixFormat({ dir: "a", base: "b" });
62const posixParsed: ParsedPath = posixParse("a/b");
63void parsed;
64void formatted;
65void flavor;
66void joined;
67void resolved;
68void related;
69void obj;
70void posixSeparator;
71void posixDelim;
72void win32Separator;
73void win32Delim;
74void wrongPosixSep;
75void wrongWin32Sep;
76void wrongPosixDelim;
77void arbitrary;
78void nativePosix;
79void nativeWin32;
80void url;
81void back;
82void posixUrl;
83void posixJoined;
84void win32Joined;
85void posixFormatted;
86void posixParsed;