javascript – CommonJS to ES6 migration exports. to export

I’m migrating a Nativescript project from version 6.8 to 8.1. This involves converting modules from CommonJS to ES6, which is mostly just converting function exports, so that

exports.foo = function(args) { ... }

becomes

export function foo(args) { ... }

and if you invoke the function from within the module, exports.foo() becomes just foo().

In addition to my own code I’m finding I’m having to migrate some of the plugins I use as newer versions aren’t available. So far so good, except for this block of code:

/**
 * List of outout formats.
 */
(function (OutputFormat) {
    /**
     * PNG
     */
    OutputFormat[OutputFormat["PNG"] = 1] = "PNG";
    /**
     * JPEG
     */
    OutputFormat[OutputFormat["JPEG"] = 2] = "JPEG";
})(exports.OutputFormat || (exports.OutputFormat = {}));
var OutputFormat = exports.OutputFormat;

I’m having a hard time following what this does, much less converting it to ES6 syntax. For context, here’s the type definition:

export declare enum OutputFormat {
    /**
     * PNG
     */
    PNG = 1,
    /**
     * JPEG
     */
    JPEG = 2,
} 

I’d welcome any suggestions on how to convert this.

Read more here: Source link