tstosc
Version:
A transpiler that convert TypeScript to SuperCollider's SCLang.
83 lines (81 loc) • 3.59 kB
TypeScript
declare const isValidPath__posix_default_option: isValidPath_PosixOption;
declare const isValidPath__windows_default_option: isValidPath_WindowsOption;
/**
* Test if the given string is a valid path.
*
* Reference:
* * https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
* * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
* * https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
*
* @param s Any string that might be a path.
*/
declare function isValidPath(s: string, option?: isValidPath_Option): boolean;
/**
* Test if the given string is a valid path in Windows system.
* Notice that too long path is considered invalid, unless set in `option`.
*
* Reference:
* * https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
* * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
* * https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
*
* @param s Any string that might be a path.
*/
declare function isValidWindowsPath(s: string, option: isValidPath_Option & isValidPath_WindowsOption): boolean;
type isValidPath_Option = {
type?: "dir" | "file";
platform?: "posix" | "windows";
} & Partial<(isValidPath_PosixOption | isValidPath_WindowsOption)>;
type isValidPath_PosixOption = {
platform: "posix";
length_limit?: number;
};
type isValidPath_WindowsOption = {
platform: "windows";
/**
* Notice that the limit check might fail,
* because `\\?\` prefix has chance to be extended to a longer string.
*
* @reference https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
*/
length_limit?: undefined | 260 | 32767 | number;
is_forward_slash_valid_separator?: boolean;
};
declare function checkPOSIXPathType(s: string, option: isValidPath_PosixOption): POSIXPathType;
declare enum POSIXPathType {
/** Path like `/tmp/a/b`. */
absolute_path = 0,
/** Path like `a/b`, `./a/b` or `../a/b`. */
working_directory_relative_path = 1,
/** Path like `~/a`. */
home_directory_relative_path = 2,
/** Represent a path failed to parse. */
invalid = 3
}
/**
* @param s Path string to check.
* @reference https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#identify-the-path
*/
declare function checkWindowsPathType(s: string, option: isValidPath_WindowsOption): WindowsPathType;
declare enum WindowsPathType {
/** Path like `\\.\CON` or `\\?\C:\path\file.txt`. */
device_path = 0,
/** Path like `\\server\shared.txt`. Start with two `\`, but not followed by `.` or `?`. */
unc_path = 1,
/** Path like `C:\Windows\test.txt`. Start with drive name. */
dos_path = 2,
/** Path like `CON`, `COM`, or `LPT1`. */
legacy_device = 3,
/** Path like `\path\file.txt` (that might be `C:\path\file.txt`), relative to current drive's root. */
root_relative_path = 4,
/** Path like `D:path\file.txt`, relative to current working directory, but in another specified drive. */
drive_relative_path = 5,
/** Path like `path\file.txt`, `.\path\file.txt`, or `..\test.txt`. */
working_directory_relative_path = 6,
/** Represent a path failed to parse. */
invalid = 7,
/** Path like `C:\Windows\test.txt`. Start with drive name. */
trivial_path = 2
}
export { POSIXPathType, WindowsPathType, checkPOSIXPathType, checkWindowsPathType, isValidPath, type isValidPath_Option, isValidPath__posix_default_option, isValidPath__windows_default_option, isValidWindowsPath };