src/main/core.js/format
function format(originalText, originalOptions) {
  let { hasBOM, text, options } = normalizeInputAndOptions(
    originalText,
    normalizeOptions(originalOptions)
  );

  const selectedParser = parser.resolveParser(options);
  const hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  if (options.requirePragma && !hasPragma) {
    return {
      formatted: originalText,
      cursorOffset: originalOptions.cursorOffset,
    };
  }

  let result;

  if (options.rangeStart > 0 || options.rangeEnd < text.length) {
    result = formatRange(text, options);
  } else {
    if (!hasPragma && options.insertPragma && options.printer.insertPragma) {
      text = options.printer.insertPragma(text);
    }
    result = coreFormat(text, options);
  }

  if (hasBOM) {
    result.formatted = BOM + result.formatted;

    if (result.cursorOffset >= 0) {
      result.cursorOffset++;
    }
  }

  return result;
}