index.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Config, CosmiconfigResult, Loaders, LoadersSync } from './types';
  2. type LoaderResult = Config | null;
  3. export type Loader = ((filepath: string, content: string) => Promise<LoaderResult>) | LoaderSync;
  4. export type LoaderSync = (filepath: string, content: string) => LoaderResult;
  5. export type Transform = ((CosmiconfigResult: CosmiconfigResult) => Promise<CosmiconfigResult>) | TransformSync;
  6. export type TransformSync = (CosmiconfigResult: CosmiconfigResult) => CosmiconfigResult;
  7. interface OptionsBase {
  8. packageProp?: string | Array<string>;
  9. searchPlaces?: Array<string>;
  10. ignoreEmptySearchPlaces?: boolean;
  11. stopDir?: string;
  12. cache?: boolean;
  13. }
  14. export interface Options extends OptionsBase {
  15. loaders?: Loaders;
  16. transform?: Transform;
  17. }
  18. export interface OptionsSync extends OptionsBase {
  19. loaders?: LoadersSync;
  20. transform?: TransformSync;
  21. }
  22. export interface PublicExplorerBase {
  23. clearLoadCache: () => void;
  24. clearSearchCache: () => void;
  25. clearCaches: () => void;
  26. }
  27. export interface PublicExplorer extends PublicExplorerBase {
  28. search: (searchFrom?: string) => Promise<CosmiconfigResult>;
  29. load: (filepath: string) => Promise<CosmiconfigResult>;
  30. }
  31. export interface PublicExplorerSync extends PublicExplorerBase {
  32. search: (searchFrom?: string) => CosmiconfigResult;
  33. load: (filepath: string) => CosmiconfigResult;
  34. }
  35. export declare const metaSearchPlaces: string[];
  36. declare const defaultLoaders: Readonly<{
  37. readonly '.mjs': Loader;
  38. readonly '.cjs': Loader;
  39. readonly '.js': Loader;
  40. readonly '.json': Loader;
  41. readonly '.yaml': Loader;
  42. readonly '.yml': Loader;
  43. readonly noExt: Loader;
  44. }>;
  45. declare const defaultLoadersSync: Readonly<{
  46. readonly '.cjs': Loader;
  47. readonly '.js': Loader;
  48. readonly '.json': Loader;
  49. readonly '.yaml': Loader;
  50. readonly '.yml': Loader;
  51. readonly noExt: Loader;
  52. }>;
  53. declare function cosmiconfig(moduleName: string, options?: Options): PublicExplorer;
  54. declare function cosmiconfigSync(moduleName: string, options?: OptionsSync): PublicExplorerSync;
  55. export { cosmiconfig, cosmiconfigSync, defaultLoaders, defaultLoadersSync };
  56. //# sourceMappingURL=index.d.ts.map