Skip to content

JavaScript

Taiizor edited this page Mar 1, 2023 · 2 revisions

JsExtension Class

JsExtension is a static class that provides methods to minify and beautify JavaScript code. The class is defined in the Skylark.Standard.Extension.Js namespace.

Methods

ToMinify(string Js = MJJM.Js) : string

This method minifies the JavaScript code passed in as a string. It uses the CrockfordJsMinifier class from the NUglify.JavaScript namespace to perform the minification.

Parameters:

  • Js: The JavaScript code to minify. If no code is provided, the default code specified in the MJJM.Js field is used.

Return Value:

A string containing the minified JavaScript code.

Exceptions:

  • Skylark.Exception: If an error occurs during the minification process, an exception is thrown with the error message.

Example:

string jsCode = "function foo() { return 'Hello, world!'; }";
string minifiedJs = JsExtension.ToMinify(jsCode);

ToMinifyAsync(string Js = MJJM.Js) : Task<string>

This method is the asynchronous version of ToMinify.

Parameters:

  • Js: The JavaScript code to minify. If no code is provided, the default code specified in the MJJM.Js field is used.

Return Value:

A Task<string> object that represents the asynchronous operation. The Task object returns a string containing the minified JavaScript code.

ToBeauty(string Js = MJJM.Js) : string

This method beautifies the JavaScript code passed in as a string. It uses the Uglify.Js method from the NUglify namespace to perform the beautification.

Parameters:

  • Js: The JavaScript code to beautify. If no code is provided, the default code specified in the MJJM.Js field is used.

Return Value:

A string containing the beautified JavaScript code.

Exceptions:

  • Skylark.Exception: If an error occurs during the beautification process, an exception is thrown with the error message.

Example:

string jsCode = "function foo() { return 'Hello, world!'; }";
string beautifiedJs = JsExtension.ToBeauty(jsCode);

ToBeautyAsync(string Js = MJJM.Js) : Task<string>

This method is the asynchronous version of ToBeauty.

Clone this wiki locally