create.d.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import type { StructuredPatch, DiffLinesOptionsAbortable, DiffLinesOptionsNonabortable, AbortableDiffOptions } from '../types.js';
  2. type StructuredPatchCallbackAbortable = (patch: StructuredPatch | undefined) => void;
  3. type StructuredPatchCallbackNonabortable = (patch: StructuredPatch) => void;
  4. interface _StructuredPatchOptionsAbortable extends Pick<DiffLinesOptionsAbortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
  5. /**
  6. * describes how many lines of context should be included.
  7. * You can set this to `Number.MAX_SAFE_INTEGER` or `Infinity` to include the entire file content in one hunk.
  8. * @default 4
  9. */
  10. context?: number;
  11. callback?: StructuredPatchCallbackAbortable;
  12. }
  13. export type StructuredPatchOptionsAbortable = _StructuredPatchOptionsAbortable & AbortableDiffOptions;
  14. export interface StructuredPatchOptionsNonabortable extends Pick<DiffLinesOptionsNonabortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
  15. context?: number;
  16. callback?: StructuredPatchCallbackNonabortable;
  17. }
  18. interface StructuredPatchCallbackOptionAbortable {
  19. /**
  20. * If provided, the diff will be computed in async mode to avoid blocking the event loop while the diff is calculated.
  21. * The value of the `callback` option should be a function and will be passed the computed diff or patch as its first argument.
  22. */
  23. callback: StructuredPatchCallbackAbortable;
  24. }
  25. interface StructuredPatchCallbackOptionNonabortable {
  26. /**
  27. * If provided, the diff will be computed in async mode to avoid blocking the event loop while the diff is calculated.
  28. * The value of the `callback` option should be a function and will be passed the computed diff or patch as its first argument.
  29. */
  30. callback: StructuredPatchCallbackNonabortable;
  31. }
  32. /**
  33. * returns an object with an array of hunk objects.
  34. *
  35. * This method is similar to createTwoFilesPatch, but returns a data structure suitable for further processing.
  36. * @param oldFileName String to be output in the filename section of the patch for the removals
  37. * @param newFileName String to be output in the filename section of the patch for the additions
  38. * @param oldStr Original string value
  39. * @param newStr New string value
  40. * @param oldHeader Optional additional information to include in the old file header.
  41. * @param newHeader Optional additional information to include in the new file header.
  42. */
  43. export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchCallbackNonabortable): undefined;
  44. export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsAbortable & StructuredPatchCallbackOptionAbortable): undefined;
  45. export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsNonabortable & StructuredPatchCallbackOptionNonabortable): undefined;
  46. export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: StructuredPatchOptionsAbortable): StructuredPatch | undefined;
  47. export declare function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: StructuredPatchOptionsNonabortable): StructuredPatch;
  48. /**
  49. * creates a unified diff patch.
  50. * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
  51. */
  52. export declare function formatPatch(patch: StructuredPatch | StructuredPatch[]): string;
  53. type CreatePatchCallbackAbortable = (patch: string | undefined) => void;
  54. type CreatePatchCallbackNonabortable = (patch: string) => void;
  55. interface _CreatePatchOptionsAbortable extends Pick<DiffLinesOptionsAbortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
  56. context?: number;
  57. callback?: CreatePatchCallbackAbortable;
  58. }
  59. export type CreatePatchOptionsAbortable = _CreatePatchOptionsAbortable & AbortableDiffOptions;
  60. export interface CreatePatchOptionsNonabortable extends Pick<DiffLinesOptionsNonabortable, 'ignoreWhitespace' | 'stripTrailingCr'> {
  61. context?: number;
  62. callback?: CreatePatchCallbackNonabortable;
  63. }
  64. interface CreatePatchCallbackOptionAbortable {
  65. callback: CreatePatchCallbackAbortable;
  66. }
  67. interface CreatePatchCallbackOptionNonabortable {
  68. callback: CreatePatchCallbackNonabortable;
  69. }
  70. /**
  71. * creates a unified diff patch by first computing a diff with `diffLines` and then serializing it to unified diff format.
  72. * @param oldFileName String to be output in the filename section of the patch for the removals
  73. * @param newFileName String to be output in the filename section of the patch for the additions
  74. * @param oldStr Original string value
  75. * @param newStr New string value
  76. * @param oldHeader Optional additional information to include in the old file header.
  77. * @param newHeader Optional additional information to include in the new file header.
  78. */
  79. export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchCallbackNonabortable): undefined;
  80. export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable & CreatePatchCallbackOptionAbortable): undefined;
  81. export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsNonabortable & CreatePatchCallbackOptionNonabortable): undefined;
  82. export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable): string | undefined;
  83. export declare function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: CreatePatchOptionsNonabortable): string;
  84. /**
  85. * creates a unified diff patch.
  86. *
  87. * Just like createTwoFilesPatch, but with oldFileName being equal to newFileName.
  88. * @param fileName String to be output in the filename section of the patch
  89. * @param oldStr Original string value
  90. * @param newStr New string value
  91. * @param oldHeader Optional additional information to include in the old file header.
  92. * @param newHeader Optional additional information to include in the new file header.
  93. */
  94. export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchCallbackNonabortable): undefined;
  95. export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable & CreatePatchCallbackOptionAbortable): undefined;
  96. export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsNonabortable & CreatePatchCallbackOptionNonabortable): undefined;
  97. export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string | undefined, newHeader: string | undefined, options: CreatePatchOptionsAbortable): string | undefined;
  98. export declare function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader?: string, newHeader?: string, options?: CreatePatchOptionsNonabortable): string;
  99. export {};
  100. //# sourceMappingURL=create.d.ts.map