4b5110c47359a4bdcc9a3e7693798bf77df0f02e0e1507d4d5481b7b22acf4dfd417312900fd369c654e1a9de446a8a90edc1aa995f8b7e2bd86004f2edac2 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. declare module "path/posix" {
  2. import path = require("path");
  3. export = path;
  4. }
  5. declare module "path/win32" {
  6. import path = require("path");
  7. export = path;
  8. }
  9. /**
  10. * The `node:path` module provides utilities for working with file and directory
  11. * paths. It can be accessed using:
  12. *
  13. * ```js
  14. * import path from 'node:path';
  15. * ```
  16. * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/path.js)
  17. */
  18. declare module "path" {
  19. namespace path {
  20. /**
  21. * A parsed path object generated by path.parse() or consumed by path.format().
  22. */
  23. interface ParsedPath {
  24. /**
  25. * The root of the path such as '/' or 'c:\'
  26. */
  27. root: string;
  28. /**
  29. * The full directory path such as '/home/user/dir' or 'c:\path\dir'
  30. */
  31. dir: string;
  32. /**
  33. * The file name including extension (if any) such as 'index.html'
  34. */
  35. base: string;
  36. /**
  37. * The file extension (if any) such as '.html'
  38. */
  39. ext: string;
  40. /**
  41. * The file name without extension (if any) such as 'index'
  42. */
  43. name: string;
  44. }
  45. interface FormatInputPathObject {
  46. /**
  47. * The root of the path such as '/' or 'c:\'
  48. */
  49. root?: string | undefined;
  50. /**
  51. * The full directory path such as '/home/user/dir' or 'c:\path\dir'
  52. */
  53. dir?: string | undefined;
  54. /**
  55. * The file name including extension (if any) such as 'index.html'
  56. */
  57. base?: string | undefined;
  58. /**
  59. * The file extension (if any) such as '.html'
  60. */
  61. ext?: string | undefined;
  62. /**
  63. * The file name without extension (if any) such as 'index'
  64. */
  65. name?: string | undefined;
  66. }
  67. interface PlatformPath {
  68. /**
  69. * Normalize a string path, reducing '..' and '.' parts.
  70. * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
  71. *
  72. * @param path string path to normalize.
  73. * @throws {TypeError} if `path` is not a string.
  74. */
  75. normalize(path: string): string;
  76. /**
  77. * Join all arguments together and normalize the resulting path.
  78. *
  79. * @param paths paths to join.
  80. * @throws {TypeError} if any of the path segments is not a string.
  81. */
  82. join(...paths: string[]): string;
  83. /**
  84. * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
  85. *
  86. * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
  87. *
  88. * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
  89. * until an absolute path is found. If after using all {from} paths still no absolute path is found,
  90. * the current working directory is used as well. The resulting path is normalized,
  91. * and trailing slashes are removed unless the path gets resolved to the root directory.
  92. *
  93. * @param paths A sequence of paths or path segments.
  94. * @throws {TypeError} if any of the arguments is not a string.
  95. */
  96. resolve(...paths: string[]): string;
  97. /**
  98. * The `path.matchesGlob()` method determines if `path` matches the `pattern`.
  99. * @param path The path to glob-match against.
  100. * @param pattern The glob to check the path against.
  101. * @returns Whether or not the `path` matched the `pattern`.
  102. * @throws {TypeError} if `path` or `pattern` are not strings.
  103. * @since v22.5.0
  104. */
  105. matchesGlob(path: string, pattern: string): boolean;
  106. /**
  107. * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
  108. *
  109. * If the given {path} is a zero-length string, `false` will be returned.
  110. *
  111. * @param path path to test.
  112. * @throws {TypeError} if `path` is not a string.
  113. */
  114. isAbsolute(path: string): boolean;
  115. /**
  116. * Solve the relative path from {from} to {to} based on the current working directory.
  117. * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
  118. *
  119. * @throws {TypeError} if either `from` or `to` is not a string.
  120. */
  121. relative(from: string, to: string): string;
  122. /**
  123. * Return the directory name of a path. Similar to the Unix dirname command.
  124. *
  125. * @param path the path to evaluate.
  126. * @throws {TypeError} if `path` is not a string.
  127. */
  128. dirname(path: string): string;
  129. /**
  130. * Return the last portion of a path. Similar to the Unix basename command.
  131. * Often used to extract the file name from a fully qualified path.
  132. *
  133. * @param path the path to evaluate.
  134. * @param suffix optionally, an extension to remove from the result.
  135. * @throws {TypeError} if `path` is not a string or if `ext` is given and is not a string.
  136. */
  137. basename(path: string, suffix?: string): string;
  138. /**
  139. * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
  140. * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.
  141. *
  142. * @param path the path to evaluate.
  143. * @throws {TypeError} if `path` is not a string.
  144. */
  145. extname(path: string): string;
  146. /**
  147. * The platform-specific file separator. '\\' or '/'.
  148. */
  149. readonly sep: "\\" | "/";
  150. /**
  151. * The platform-specific file delimiter. ';' or ':'.
  152. */
  153. readonly delimiter: ";" | ":";
  154. /**
  155. * Returns an object from a path string - the opposite of format().
  156. *
  157. * @param path path to evaluate.
  158. * @throws {TypeError} if `path` is not a string.
  159. */
  160. parse(path: string): ParsedPath;
  161. /**
  162. * Returns a path string from an object - the opposite of parse().
  163. *
  164. * @param pathObject path to evaluate.
  165. */
  166. format(pathObject: FormatInputPathObject): string;
  167. /**
  168. * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
  169. * If path is not a string, path will be returned without modifications.
  170. * This method is meaningful only on Windows system.
  171. * On POSIX systems, the method is non-operational and always returns path without modifications.
  172. */
  173. toNamespacedPath(path: string): string;
  174. /**
  175. * Posix specific pathing.
  176. * Same as parent object on posix.
  177. */
  178. readonly posix: PlatformPath;
  179. /**
  180. * Windows specific pathing.
  181. * Same as parent object on windows
  182. */
  183. readonly win32: PlatformPath;
  184. }
  185. }
  186. const path: path.PlatformPath;
  187. export = path;
  188. }
  189. declare module "node:path" {
  190. import path = require("path");
  191. export = path;
  192. }
  193. declare module "node:path/posix" {
  194. import path = require("path/posix");
  195. export = path;
  196. }
  197. declare module "node:path/win32" {
  198. import path = require("path/win32");
  199. export = path;
  200. }