path.d.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. declare module 'path' {
  10. namespace path {
  11. /**
  12. * A parsed path object generated by path.parse() or consumed by path.format().
  13. */
  14. interface ParsedPath {
  15. /**
  16. * The root of the path such as '/' or 'c:\'
  17. */
  18. root: string;
  19. /**
  20. * The full directory path such as '/home/user/dir' or 'c:\path\dir'
  21. */
  22. dir: string;
  23. /**
  24. * The file name including extension (if any) such as 'index.html'
  25. */
  26. base: string;
  27. /**
  28. * The file extension (if any) such as '.html'
  29. */
  30. ext: string;
  31. /**
  32. * The file name without extension (if any) such as 'index'
  33. */
  34. name: string;
  35. }
  36. interface FormatInputPathObject {
  37. /**
  38. * The root of the path such as '/' or 'c:\'
  39. */
  40. root?: string;
  41. /**
  42. * The full directory path such as '/home/user/dir' or 'c:\path\dir'
  43. */
  44. dir?: string;
  45. /**
  46. * The file name including extension (if any) such as 'index.html'
  47. */
  48. base?: string;
  49. /**
  50. * The file extension (if any) such as '.html'
  51. */
  52. ext?: string;
  53. /**
  54. * The file name without extension (if any) such as 'index'
  55. */
  56. name?: string;
  57. }
  58. interface PlatformPath {
  59. /**
  60. * Normalize a string path, reducing '..' and '.' parts.
  61. * 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.
  62. *
  63. * @param p string path to normalize.
  64. */
  65. normalize(p: string): string;
  66. /**
  67. * Join all arguments together and normalize the resulting path.
  68. * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
  69. *
  70. * @param paths paths to join.
  71. */
  72. join(...paths: string[]): string;
  73. /**
  74. * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
  75. *
  76. * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
  77. *
  78. * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
  79. * until an absolute path is found. If after using all {from} paths still no absolute path is found,
  80. * the current working directory is used as well. The resulting path is normalized,
  81. * and trailing slashes are removed unless the path gets resolved to the root directory.
  82. *
  83. * @param pathSegments string paths to join. Non-string arguments are ignored.
  84. */
  85. resolve(...pathSegments: string[]): string;
  86. /**
  87. * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
  88. *
  89. * @param path path to test.
  90. */
  91. isAbsolute(p: string): boolean;
  92. /**
  93. * Solve the relative path from {from} to {to}.
  94. * 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.
  95. */
  96. relative(from: string, to: string): string;
  97. /**
  98. * Return the directory name of a path. Similar to the Unix dirname command.
  99. *
  100. * @param p the path to evaluate.
  101. */
  102. dirname(p: string): string;
  103. /**
  104. * Return the last portion of a path. Similar to the Unix basename command.
  105. * Often used to extract the file name from a fully qualified path.
  106. *
  107. * @param p the path to evaluate.
  108. * @param ext optionally, an extension to remove from the result.
  109. */
  110. basename(p: string, ext?: string): string;
  111. /**
  112. * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
  113. * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
  114. *
  115. * @param p the path to evaluate.
  116. */
  117. extname(p: string): string;
  118. /**
  119. * The platform-specific file separator. '\\' or '/'.
  120. */
  121. readonly sep: string;
  122. /**
  123. * The platform-specific file delimiter. ';' or ':'.
  124. */
  125. readonly delimiter: string;
  126. /**
  127. * Returns an object from a path string - the opposite of format().
  128. *
  129. * @param pathString path to evaluate.
  130. */
  131. parse(p: string): ParsedPath;
  132. /**
  133. * Returns a path string from an object - the opposite of parse().
  134. *
  135. * @param pathString path to evaluate.
  136. */
  137. format(pP: FormatInputPathObject): string;
  138. /**
  139. * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
  140. * If path is not a string, path will be returned without modifications.
  141. * This method is meaningful only on Windows system.
  142. * On POSIX systems, the method is non-operational and always returns path without modifications.
  143. */
  144. toNamespacedPath(path: string): string;
  145. /**
  146. * Posix specific pathing.
  147. * Same as parent object on posix.
  148. */
  149. readonly posix: PlatformPath;
  150. /**
  151. * Windows specific pathing.
  152. * Same as parent object on windows
  153. */
  154. readonly win32: PlatformPath;
  155. }
  156. }
  157. const path: path.PlatformPath;
  158. export = path;
  159. }