|
| 1 | +---@meta mods.ntpath |
| 2 | + |
| 3 | +--- |
| 4 | +---Lexical path operations for Windows/NT-style paths. |
| 5 | +--- |
| 6 | +---## Usage |
| 7 | +--- |
| 8 | +---```lua |
| 9 | +---ntpath = require "mods.ntpath" |
| 10 | +--- |
| 11 | +---print(ntpath.join([[C:\]], "Users", "me")) --> "C:\Users\me" |
| 12 | +---``` |
| 13 | +--- |
| 14 | +---@class mods.ntpath |
| 15 | +local M = {} |
| 16 | + |
| 17 | +-------------------------------------------------------------------------------- |
| 18 | +------------------------- Normalization & Predicates --------------------------- |
| 19 | +-------------------------------------------------------------------------------- |
| 20 | + |
| 21 | +--- |
| 22 | +---Normalize case and separators for NT paths. |
| 23 | +--- |
| 24 | +---```lua |
| 25 | +---ntpath.normcase([[A/B\C]]) --> [[a\b\c]] |
| 26 | +---``` |
| 27 | +--- |
| 28 | +---@param s string Path string to normalize. |
| 29 | +---@return string value Normalized lowercase path with `\` separators. |
| 30 | +---@nodiscard |
| 31 | +function M.normcase(s) end |
| 32 | + |
| 33 | +--- |
| 34 | +---Return `true` when `path` is absolute under NT rules. |
| 35 | +--- |
| 36 | +---```lua |
| 37 | +---ntpath.isabs([[C:\a]]) --> true |
| 38 | +---``` |
| 39 | +--- |
| 40 | +---@param path string Path to inspect. |
| 41 | +---@return boolean value `true` if the path is absolute. |
| 42 | +---@nodiscard |
| 43 | +function M.isabs(path) end |
| 44 | + |
| 45 | +--- |
| 46 | +---Return `true` when `path` points to a mount root. |
| 47 | +--- |
| 48 | +---```lua |
| 49 | +---ntpath.ismount([[C:\]]) --> true |
| 50 | +---``` |
| 51 | +--- |
| 52 | +---@param path string Path to inspect. |
| 53 | +---@return boolean value `true` if the path resolves to a mount root. |
| 54 | +---@nodiscard |
| 55 | +function M.ismount(path) end |
| 56 | + |
| 57 | +--- |
| 58 | +---Return `true` when `path` contains a reserved NT filename. |
| 59 | +--- |
| 60 | +---```lua |
| 61 | +---ntpath.isreserved([[a\CON.txt]]) --> true |
| 62 | +---``` |
| 63 | +--- |
| 64 | +---@param path string Path to inspect. |
| 65 | +---@return boolean value `true` if any component is NT-reserved. |
| 66 | +---@nodiscard |
| 67 | +function M.isreserved(path) end |
| 68 | + |
| 69 | +-------------------------------------------------------------------------------- |
| 70 | +------------------------------ Path Decomposition ------------------------------ |
| 71 | +-------------------------------------------------------------------------------- |
| 72 | + |
| 73 | +--- |
| 74 | +---Join one or more path components. |
| 75 | +--- |
| 76 | +---```lua |
| 77 | +---ntpath.join([[C:\a]], [[b]]) --> [[C:\a\b]] |
| 78 | +---``` |
| 79 | +--- |
| 80 | +---@param path string Base path component. |
| 81 | +---@param ... string Additional path components to append. |
| 82 | +---@return string value Joined NT path. |
| 83 | +---@nodiscard |
| 84 | +function M.join(path, ...) end |
| 85 | + |
| 86 | +--- |
| 87 | +---Split path into directory head and tail component. |
| 88 | +--- |
| 89 | +---```lua |
| 90 | +---ntpath.split([[C:\a\b.txt]]) --> [[C:\a]], "b.txt" |
| 91 | +---``` |
| 92 | +--- |
| 93 | +---@param path string Path to split. |
| 94 | +---@return string head Directory portion of the path. |
| 95 | +---@return string tail Final path component. |
| 96 | +---@nodiscard |
| 97 | +function M.split(path) end |
| 98 | + |
| 99 | +--- |
| 100 | +---Split path into a root and extension. |
| 101 | +--- |
| 102 | +---```lua |
| 103 | +---ntpath.splitext("archive.tar.gz") --> "archive.tar", ".gz" |
| 104 | +---``` |
| 105 | +--- |
| 106 | +---@param path string Path to split. |
| 107 | +---@return string root Path without the final extension. |
| 108 | +---@return string ext Final extension, including the leading dot when present. |
| 109 | +---@nodiscard |
| 110 | +function M.splitext(path) end |
| 111 | + |
| 112 | +--- |
| 113 | +---Split drive prefix from remainder. |
| 114 | +--- |
| 115 | +---```lua |
| 116 | +---ntpath.splitdrive([[C:\a\b]]) --> "C:", [[\a\b]] |
| 117 | +---``` |
| 118 | +--- |
| 119 | +---@param path string Path to split. |
| 120 | +---@return string drive Drive or UNC share prefix. |
| 121 | +---@return string rest Remaining path after the drive prefix. |
| 122 | +---@nodiscard |
| 123 | +function M.splitdrive(path) end |
| 124 | + |
| 125 | +--- |
| 126 | +---Split path into drive, root, and tail components. |
| 127 | +--- |
| 128 | +---```lua |
| 129 | +---ntpath.splitroot([[C:\a\b]]) --> "C:", [[\]], "a\\b" |
| 130 | +---``` |
| 131 | +--- |
| 132 | +---@param path string Path to split. |
| 133 | +---@return string drive Drive or UNC share prefix. |
| 134 | +---@return string root Root separator portion. |
| 135 | +---@return string tail Remaining path after drive and root. |
| 136 | +---@nodiscard |
| 137 | +function M.splitroot(path) end |
| 138 | + |
| 139 | +--- |
| 140 | +---Return final path component. |
| 141 | +--- |
| 142 | +---```lua |
| 143 | +---ntpath.basename([[C:\a\b.txt]]) --> "b.txt" |
| 144 | +---``` |
| 145 | +--- |
| 146 | +---@param path string Path to inspect. |
| 147 | +---@return string value Final component of the path. |
| 148 | +---@nodiscard |
| 149 | +function M.basename(path) end |
| 150 | + |
| 151 | +--- |
| 152 | +---Return directory portion of a path. |
| 153 | +--- |
| 154 | +---```lua |
| 155 | +---ntpath.dirname([[C:\a\b.txt]]) --> [[C:\a]] |
| 156 | +---``` |
| 157 | +--- |
| 158 | +---@param path string Path to inspect. |
| 159 | +---@return string value Directory portion of the path. |
| 160 | +---@nodiscard |
| 161 | +function M.dirname(path) end |
| 162 | + |
| 163 | +-------------------------------------------------------------------------------- |
| 164 | +------------------------------ Environment Expand ------------------------------ |
| 165 | +-------------------------------------------------------------------------------- |
| 166 | + |
| 167 | +--- |
| 168 | +---Expand `~` home segment when available. |
| 169 | +--- |
| 170 | +---```lua |
| 171 | +---ntpath.expanduser([[x\y]]) --> [[x\y]] |
| 172 | +---``` |
| 173 | +--- |
| 174 | +---@param path string Path that may begin with `~`. |
| 175 | +---@return string value Path with the home segment expanded when available. |
| 176 | +---@nodiscard |
| 177 | +function M.expanduser(path) end |
| 178 | + |
| 179 | +-------------------------------------------------------------------------------- |
| 180 | +------------------------------- Derived Paths ---------------------------------- |
| 181 | +-------------------------------------------------------------------------------- |
| 182 | + |
| 183 | +--- |
| 184 | +---Normalize separators and dot segments. |
| 185 | +--- |
| 186 | +---```lua |
| 187 | +---ntpath.normpath([[A/foo/../B]]) --> [[A\B]] |
| 188 | +---``` |
| 189 | +--- |
| 190 | +---@param path string Path to normalize. |
| 191 | +---@return string value Normalized NT path with dot segments resolved lexically. |
| 192 | +---@nodiscard |
| 193 | +function M.normpath(path) end |
| 194 | + |
| 195 | +--- |
| 196 | +---Return normalized absolute path. |
| 197 | +--- |
| 198 | +---```lua |
| 199 | +---ntpath.abspath([[C:\a\..\b]]) --> [[C:\b]] |
| 200 | +---``` |
| 201 | +--- |
| 202 | +---@param path string Path to absolutize. |
| 203 | +---@return string value Normalized absolute NT path. |
| 204 | +---@nodiscard |
| 205 | +function M.abspath(path) end |
| 206 | + |
| 207 | +--- |
| 208 | +---Return `path` relative to optional `start` path. |
| 209 | +--- |
| 210 | +---```lua |
| 211 | +---ntpath.relpath([[C:\a\b\c]], [[C:\a]]) --> [[b\c]] |
| 212 | +---``` |
| 213 | +--- |
| 214 | +---@param path string Target path. |
| 215 | +---@param start? string Optional start path used as the base. |
| 216 | +---@return string value Relative path from `start` to `path`. |
| 217 | +---@nodiscard |
| 218 | +function M.relpath(path, start) end |
| 219 | + |
| 220 | +--- |
| 221 | +---Return longest common sub-path from a path list. |
| 222 | +--- |
| 223 | +---```lua |
| 224 | +---ntpath.commonpath({ [[C:\a\b\c]], [[c:/a/b/d]] }) --> [[C:\a\b]] |
| 225 | +---``` |
| 226 | +--- |
| 227 | +---@param paths string[] Input NT paths. |
| 228 | +---@return string value Longest common sub-path. |
| 229 | +---@nodiscard |
| 230 | +function M.commonpath(paths) end |
| 231 | + |
| 232 | +return M |
0 commit comments