path.d.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. export class Path {
  2. /**
  3. * Creates a new path based on the argument type. If the argument is a string,
  4. * it is assumed to be a file or directory path and is converted to a Path
  5. * instance. If the argument is a URL, it is assumed to be a file URL and is
  6. * converted to a Path instance. If the argument is a Path instance, it is
  7. * copied into a new Path instance. If the argument is an array, it is assumed
  8. * to be the steps of a path and is used to create a new Path instance.
  9. * @param {string|URL|Path|Array<string>} pathish The value to convert to a Path instance.
  10. * @returns {Path} A new Path instance.
  11. * @throws {TypeError} When pathish is not a string, URL, Path, or Array.
  12. * @throws {TypeError} When pathish is a string and is empty.
  13. */
  14. static from(pathish: string | URL | Path | Array<string>): Path;
  15. /**
  16. * Creates a new Path instance from a string.
  17. * @param {string} fileOrDirPath The file or directory path to convert.
  18. * @returns {Path} A new Path instance.
  19. * @deprecated Use Path.from() instead.
  20. */
  21. static fromString(fileOrDirPath: string): Path;
  22. /**
  23. * Creates a new Path instance from a URL.
  24. * @param {URL} url The URL to convert.
  25. * @returns {Path} A new Path instance.
  26. * @throws {TypeError} When url is not a URL instance.
  27. * @throws {TypeError} When url.pathname is empty.
  28. * @throws {TypeError} When url.protocol is not "file:".
  29. * @deprecated Use Path.from() instead.
  30. */
  31. static fromURL(url: URL): Path;
  32. /**
  33. * Creates a new instance.
  34. * @param {Iterable<string>} [steps] The steps to use for the path.
  35. * @throws {TypeError} When steps is not iterable.
  36. */
  37. constructor(steps?: Iterable<string>);
  38. /**
  39. * Adds steps to the end of the path.
  40. * @param {...string} steps The steps to add to the path.
  41. * @returns {void}
  42. */
  43. push(...steps: string[]): void;
  44. /**
  45. * Removes the last step from the path.
  46. * @returns {string} The last step in the path.
  47. */
  48. pop(): string;
  49. /**
  50. * Returns an iterator for steps in the path.
  51. * @returns {IterableIterator<string>} An iterator for the steps in the path.
  52. */
  53. steps(): IterableIterator<string>;
  54. /**
  55. * Sets the name (the last step) of the path.
  56. * @type {string}
  57. */
  58. set name(value: string);
  59. /**
  60. * Retrieves the name (the last step) of the path.
  61. * @type {string}
  62. */
  63. get name(): string;
  64. /**
  65. * Retrieves the size of the path.
  66. * @type {number}
  67. */
  68. get size(): number;
  69. /**
  70. * Returns the path as a string.
  71. * @returns {string} The path as a string.
  72. */
  73. toString(): string;
  74. /**
  75. * Returns an iterator for the steps in the path.
  76. * @returns {IterableIterator<string>} An iterator for the steps in the path.
  77. */
  78. [Symbol.iterator](): IterableIterator<string>;
  79. #private;
  80. }
  81. export type HfsImpl = import("@humanfs/types").HfsImpl;
  82. export type HfsDirectoryEntry = import("@humanfs/types").HfsDirectoryEntry;