MCPcopy
hub / github.com/prettier/prettier / normalizeInputAndOptions

Function normalizeInputAndOptions

src/main/core.js:268–310  ·  view source on GitHub ↗
(text, options)

Source from the content-addressed store, hash-verified

266}
267
268function normalizeInputAndOptions(text, options) {
269 let { cursorOffset, rangeStart, rangeEnd, endOfLine } = normalizeIndexes(
270 text,
271 options,
272 );
273
274 const hasBOM = text.charAt(0) === BOM;
275
276 if (hasBOM) {
277 text = text.slice(1);
278 cursorOffset--;
279 rangeStart--;
280 rangeEnd--;
281 }
282
283 if (endOfLine === "auto") {
284 endOfLine = guessEndOfLine(text);
285 }
286
287 // get rid of CR/CRLF parsing
288 if (text.includes("\r")) {
289 const countCrlfBefore = (index) =>
290 countEndOfLineCharacters(text.slice(0, Math.max(index, 0)), "\r\n");
291
292 cursorOffset -= countCrlfBefore(cursorOffset);
293 rangeStart -= countCrlfBefore(rangeStart);
294 rangeEnd -= countCrlfBefore(rangeEnd);
295
296 text = normalizeEndOfLine(text);
297 }
298
299 return {
300 hasBOM,
301 text,
302 options: normalizeIndexes(text, {
303 ...options,
304 cursorOffset,
305 rangeStart,
306 rangeEnd,
307 endOfLine,
308 }),
309 };
310}
311
312async function hasPragma(text, options) {
313 const selectedParser = await resolveParser(options);

Callers 2

formatWithCursorFunction · 0.85
parseFunction · 0.85

Calls 4

guessEndOfLineFunction · 0.90
normalizeEndOfLineFunction · 0.90
normalizeIndexesFunction · 0.85
countCrlfBeforeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…