CommonJS to ES6 migration exports. to export

First look at what it's invoked with:

(exports.OutputFormat || (exports.OutputFormat = {}));
  • If exports.OutputFormat is truthy, it'll be the parameter
  • Otherwise, the following expression will be the parameter: exports.OutputFormat = {}, which will:
    • create an empty object
    • assign that empty object to exports.OutputFormat
    • evaluate to that empty object

Unless OutputFormat is referenced elsewhere in this module, which seems unlikely, you can turn it into ES6 module syntax with:

export const OutputFormat = {
  PNG: 1,
  1: "PNG",
  JPEG: 2,
  2: "JPEG",
};

While you can also export an empty object and then run

OutputFormat[OutputFormat["PNG"] = 1] = "PNG";
OutputFormat[OutputFormat["JPEG"] = 2] = "JPEG";

, those lines of code are much more confusing than they need to be, so I'd refactor them to the above.

(or you could iterate over an array of [["PNG", 1], ["JPEG", 2]] and assign)