index.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. export interface Options {
  2. /**
  3. The directory to start searching from.
  4. @default process.cwd()
  5. */
  6. readonly cwd?: string;
  7. }
  8. /**
  9. Find the root directory of a Node.js project or npm package.
  10. @returns The project root path or `undefined` if it could not be found.
  11. @example
  12. ```
  13. // /
  14. // └── Users
  15. // └── sindresorhus
  16. // └── foo
  17. // ├── package.json
  18. // └── bar
  19. // ├── baz
  20. // └── example.js
  21. // example.js
  22. import {packageDirectory} from 'pkg-dir';
  23. console.log(await packageDirectory());
  24. //=> '/Users/sindresorhus/foo'
  25. ```
  26. */
  27. export function packageDirectory(options?: Options): Promise<string | undefined>;
  28. /**
  29. Synchronously find the root directory of a Node.js project or npm package.
  30. @returns The project root path or `undefined` if it could not be found.
  31. @example
  32. ```
  33. // /
  34. // └── Users
  35. // └── sindresorhus
  36. // └── foo
  37. // ├── package.json
  38. // └── bar
  39. // ├── baz
  40. // └── example.js
  41. // example.js
  42. import {packageDirectorySync} from 'pkg-dir';
  43. console.log(packageDirectorySync());
  44. //=> '/Users/sindresorhus/foo'
  45. ```
  46. */
  47. export function packageDirectorySync(options?: Options): string | undefined;