index.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import * as typeFest from 'type-fest';
  2. import normalize = require('normalize-package-data');
  3. declare namespace readPkg {
  4. interface Options {
  5. /**
  6. [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
  7. @default true
  8. */
  9. readonly normalize?: boolean;
  10. /**
  11. Current working directory.
  12. @default process.cwd()
  13. */
  14. readonly cwd?: string;
  15. }
  16. interface NormalizeOptions extends Options {
  17. readonly normalize?: true;
  18. }
  19. type NormalizedPackageJson = PackageJson & normalize.Package;
  20. type PackageJson = typeFest.PackageJson;
  21. }
  22. declare const readPkg: {
  23. /**
  24. @returns The parsed JSON.
  25. @example
  26. ```
  27. import readPkg = require('read-pkg');
  28. (async () => {
  29. console.log(await readPkg());
  30. //=> {name: 'read-pkg', …}
  31. console.log(await readPkg({cwd: 'some-other-directory'});
  32. //=> {name: 'unicorn', …}
  33. })();
  34. ```
  35. */
  36. (options?: readPkg.NormalizeOptions): Promise<readPkg.NormalizedPackageJson>;
  37. (options: readPkg.Options): Promise<readPkg.PackageJson>;
  38. /**
  39. @returns The parsed JSON.
  40. @example
  41. ```
  42. import readPkg = require('read-pkg');
  43. console.log(readPkg.sync());
  44. //=> {name: 'read-pkg', …}
  45. console.log(readPkg.sync({cwd: 'some-other-directory'});
  46. //=> {name: 'unicorn', …}
  47. ```
  48. */
  49. sync(options?: readPkg.NormalizeOptions): readPkg.NormalizedPackageJson;
  50. sync(options: readPkg.Options): readPkg.PackageJson;
  51. };
  52. export = readPkg;