index.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /// <reference types="node" />
  2. import { Minimatch } from 'minimatch';
  3. export interface KnownProps {
  4. end_of_line?: 'lf' | 'crlf' | 'unset';
  5. indent_style?: 'tab' | 'space' | 'unset';
  6. indent_size?: number | 'tab' | 'unset';
  7. insert_final_newline?: true | false | 'unset';
  8. tab_width?: number | 'unset';
  9. trim_trailing_whitespace?: true | false | 'unset';
  10. charset?: string | 'unset';
  11. }
  12. interface UnknownMap {
  13. [index: string]: unknown;
  14. }
  15. export type Props = KnownProps & UnknownMap;
  16. export interface ECFile {
  17. name: string;
  18. contents?: Buffer;
  19. }
  20. type SectionGlob = Minimatch | null;
  21. type GlobbedProps = [SectionName, Props, SectionGlob][];
  22. export interface ProcessedFileConfig {
  23. root: boolean;
  24. name: string;
  25. config: GlobbedProps;
  26. notfound?: true;
  27. }
  28. export interface Visited {
  29. fileName: string;
  30. glob: string;
  31. }
  32. export interface Cache {
  33. get(path: string): ProcessedFileConfig | undefined;
  34. set(path: string, config: ProcessedFileConfig): this;
  35. }
  36. export interface ParseOptions {
  37. config?: string;
  38. version?: string;
  39. root?: string;
  40. files?: Visited[];
  41. cache?: Cache;
  42. }
  43. export type SectionName = string | null;
  44. export interface SectionBody {
  45. [key: string]: string;
  46. }
  47. export type ParseStringResult = [SectionName, SectionBody][];
  48. /**
  49. * Parse a buffer using the faster one-ini WASM approach into something
  50. * relatively easy to deal with in JS.
  51. *
  52. * @param data UTF8-encoded bytes.
  53. * @returns Parsed contents. Will be truncated if there was a parse error.
  54. */
  55. export declare function parseBuffer(data: Buffer): ParseStringResult;
  56. /**
  57. * Parses a string. If possible, you should always use ParseBuffer instead,
  58. * since this function does a UTF16-to-UTF8 conversion first.
  59. *
  60. * @param data String to parse.
  61. * @returns Parsed contents. Will be truncated if there was a parse error.
  62. * @deprecated Use {@link ParseBuffer} instead.
  63. */
  64. export declare function parseString(data: string): ParseStringResult;
  65. /**
  66. * Low-level interface, which exists only for backward-compatibility.
  67. * Deprecated.
  68. *
  69. * @param filepath The name of the target file, relative to process.cwd().
  70. * @param files A promise for a list of objects describing the files.
  71. * @param options All options
  72. * @returns The properties found for filepath
  73. * @deprecated
  74. */
  75. export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<Props>;
  76. /**
  77. * Low-level interface, which exists only for backward-compatibility.
  78. * Deprecated.
  79. *
  80. * @param filepath The name of the target file, relative to process.cwd().
  81. * @param files A list of objects describing the files.
  82. * @param options All options
  83. * @returns The properties found for filepath
  84. * @deprecated
  85. */
  86. export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): Props;
  87. /**
  88. * Find all of the properties from matching sections in config files in the
  89. * same directory or toward the root of the filesystem.
  90. *
  91. * @param filepath The target file name, relative to process.cwd().
  92. * @param options All options
  93. * @returns Combined properties for the target file
  94. */
  95. export declare function parse(filepath: string, options?: ParseOptions): Promise<Props>;
  96. /**
  97. * Find all of the properties from matching sections in config files in the
  98. * same directory or toward the root of the filesystem. Synchronous.
  99. *
  100. * @param filepath The target file name, relative to process.cwd().
  101. * @param options All options
  102. * @returns Combined properties for the target file
  103. */
  104. export declare function parseSync(filepath: string, options?: ParseOptions): Props;
  105. export {};