Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

path.d.ts 5.8KB

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