|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: File Parser |
| 4 | +nav_order: 5 |
| 5 | +--- |
| 6 | + |
| 7 | +# file-parser |
| 8 | + |
| 9 | +## Interfaces |
| 10 | + |
| 11 | +### ParseConflictOptions |
| 12 | + |
| 13 | +Defined in: [file-parser.ts:24](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L24) |
| 14 | + |
| 15 | +Options for parsing conflicted content. |
| 16 | + |
| 17 | +#### Properties |
| 18 | + |
| 19 | +##### filename? |
| 20 | + |
| 21 | +> `optional` **filename**: `string` |
| 22 | +
|
| 23 | +Defined in: [file-parser.ts:42](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L42) |
| 24 | + |
| 25 | +Optional filename hint to prioritize parser choice. |
| 26 | +Example: |
| 27 | + |
| 28 | +- `config.yaml` → try `yaml` first. |
| 29 | +- `data.toml` → try `toml` first. |
| 30 | + |
| 31 | +If extension is unknown, falls back to `parsers` or `"json"`. |
| 32 | + |
| 33 | +##### parsers? |
| 34 | + |
| 35 | +> `optional` **parsers**: [`SupportedParsers`](#supportedparsers) \| `"auto"` \| [`SupportedParsers`](#supportedparsers)[] |
| 36 | +
|
| 37 | +Defined in: [file-parser.ts:32](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L32) |
| 38 | + |
| 39 | +Parsers to attempt, in order: |
| 40 | + |
| 41 | +- A single parser (`"json"`, `"yaml"`, custom function, etc.). |
| 42 | +- An array of parsers (e.g. `["yaml", "json5"]`). |
| 43 | + |
| 44 | +Defaults to `"json"`. |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +### ParsedConflict\<T\> |
| 49 | + |
| 50 | +Defined in: [file-parser.ts:6](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L6) |
| 51 | + |
| 52 | +Represents a parsed conflict from a file with `ours` and `theirs` versions. |
| 53 | + |
| 54 | +#### Type Parameters |
| 55 | + |
| 56 | +##### T |
| 57 | + |
| 58 | +`T` = `unknown` |
| 59 | + |
| 60 | +The type of the parsed content. |
| 61 | + |
| 62 | +#### Properties |
| 63 | + |
| 64 | +##### format |
| 65 | + |
| 66 | +> **format**: `string` |
| 67 | +
|
| 68 | +Defined in: [file-parser.ts:12](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L12) |
| 69 | + |
| 70 | +Format used to parse the content (`json`, `yaml`, `toml`, `xml`, or `custom`). |
| 71 | + |
| 72 | +##### ours |
| 73 | + |
| 74 | +> **ours**: `T` |
| 75 | +
|
| 76 | +Defined in: [file-parser.ts:8](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L8) |
| 77 | + |
| 78 | +Parsed content from the "ours" side of the conflict. |
| 79 | + |
| 80 | +##### theirs |
| 81 | + |
| 82 | +> **theirs**: `T` |
| 83 | +
|
| 84 | +Defined in: [file-parser.ts:10](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L10) |
| 85 | + |
| 86 | +Parsed content from the "theirs" side of the conflict. |
| 87 | + |
| 88 | +## Type Aliases |
| 89 | + |
| 90 | +### Parser |
| 91 | + |
| 92 | +> **Parser** = \{ `name`: `string`; `parser`: (`input`: `string`) => `unknown`; \} |
| 93 | +
|
| 94 | +Defined in: [file-parser.ts:16](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L16) |
| 95 | + |
| 96 | +A parser function that takes a raw string and returns parsed content. |
| 97 | + |
| 98 | +#### Properties |
| 99 | + |
| 100 | +##### name |
| 101 | + |
| 102 | +> **name**: `string` |
| 103 | +
|
| 104 | +Defined in: [file-parser.ts:16](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L16) |
| 105 | + |
| 106 | +##### parser() |
| 107 | + |
| 108 | +> **parser**: (`input`: `string`) => `unknown` |
| 109 | +
|
| 110 | +Defined in: [file-parser.ts:16](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L16) |
| 111 | + |
| 112 | +###### Parameters |
| 113 | + |
| 114 | +###### input |
| 115 | + |
| 116 | +`string` |
| 117 | + |
| 118 | +###### Returns |
| 119 | + |
| 120 | +`unknown` |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +### SupportedParsers |
| 125 | + |
| 126 | +> **SupportedParsers** = `"json"` \| `"json5"` \| `"yaml"` \| `"toml"` \| `"xml"` \| [`Parser`](#parser) |
| 127 | +
|
| 128 | +Defined in: [file-parser.ts:19](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L19) |
| 129 | + |
| 130 | +Built-in parser identifiers or a custom parser function. |
| 131 | + |
| 132 | +## Functions |
| 133 | + |
| 134 | +### parseConflictContent() |
| 135 | + |
| 136 | +> **parseConflictContent**\<`T`\>(`content`: `string`, `options`: [`ParseConflictOptions`](#parseconflictoptions)): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`ParsedConflict`](#parsedconflict)\<`T`\>\> |
| 137 | +
|
| 138 | +Defined in: [file-parser.ts:62](https://github.com/react18-tools/git-json-resolver/blob/983ecea05a6699ed0124b500e82e9f563b676c3f/lib/src/file-parser.ts#L62) |
| 139 | + |
| 140 | +Parses a conflicted file's content into separate `ours` and `theirs` objects. |
| 141 | + |
| 142 | +- Preserves non-conflicted lines in both versions. |
| 143 | +- Supports JSON, JSON5, YAML, TOML, and XML. |
| 144 | +- Lazy-loads optional peer dependencies (`json5`, `yaml`, `toml`, `fast-xml-parser`). |
| 145 | +- Parser order is determined by: |
| 146 | + 1. `filename` extension hint (if provided). |
| 147 | + 2. Explicit `parsers` option. |
| 148 | + 3. Default `"json"`. |
| 149 | + |
| 150 | +#### Type Parameters |
| 151 | + |
| 152 | +##### T |
| 153 | + |
| 154 | +`T` = `unknown` |
| 155 | + |
| 156 | +Expected type of parsed content. |
| 157 | + |
| 158 | +#### Parameters |
| 159 | + |
| 160 | +##### content |
| 161 | + |
| 162 | +`string` |
| 163 | + |
| 164 | +Raw file content containing conflict markers. |
| 165 | + |
| 166 | +##### options |
| 167 | + |
| 168 | +[`ParseConflictOptions`](#parseconflictoptions) = `{}` |
| 169 | + |
| 170 | +Parsing options (parsers + filename hint). |
| 171 | + |
| 172 | +#### Returns |
| 173 | + |
| 174 | +[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`ParsedConflict`](#parsedconflict)\<`T`\>\> |
| 175 | + |
| 176 | +Parsed conflict with both sides and detected format. |
| 177 | + |
| 178 | +#### Throws |
| 179 | + |
| 180 | +If parsing fails or conflict markers are invalid. |
0 commit comments