HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/current/node_modules/uglyfly-js/demo/demo.js
(function (require) {
    'use strict';
    require.config({
        //baseUrl: '../lib', //if using raw version of uglyfly's core code (many unminified files)
        baseUrl: '../build', //if using built version of uglyfly's core code (a single minified file)
        paths: {
            get_uglyfly_api: 'get_uglyfly_api_built.min', //comment this out if using raw version
            uglyfly: '../demo/uglyfly',
            bluebird: '../demo/vendor/bluebird',
            sourceMap: '../demo/vendor/sourceMap',
            domReady: '../demo/vendor/domReady'
        }
    });

    require(['uglyfly', 'domReady'], function (uglyfly, domReady) {
        domReady(function () {
            var doc = document,
                elems = {
                    btnMinify: doc.getElementById('btnMinify'),
                    btnBeautify: doc.getElementById('btnBeautify'),
                    inpJsInputFilepath: doc.getElementById('inpJsInputFilepath'),
                    inpJsOutputFilepath: doc.getElementById('inpJsOutputFilepath'),
                    inpSourceMapOutputFilepath: doc.getElementById('inpSourceMapOutputFilepath'),
                    taJsInputCode: doc.getElementById('taJsInputCode'),
                    taJsOutputCode: doc.getElementById('taJsOutputCode'),
                    taOutputSourceMap: doc.getElementById('taOutputSourceMap')
                };
            setInputJs(
                '\n' +
                'function hi() {\n' +
                '    var hello = "world";\n' +
                '    return hello;\n' +
                '}\n');
            setJsInputFilepath('example.js');
            setJsOutputFilepath('example.min.js');
            setSourceMapOutputFilepath('example.min.js.map');

            function getJsInputFilepath() {
                var filepath = elems.inpJsInputFilepath.value;
                return filepath;
            }
            function setJsInputFilepath(inputFilepath) {
                elems.inpJsInputFilepath.value = inputFilepath;
            }

            function getJsOutputFilepath() {
                var filepath = elems.inpJsOutputFilepath.value;
                return filepath;
            }
            function setJsOutputFilepath(outFilepath) {
                elems.inpJsOutputFilepath.value = outFilepath;
            }

            function getSourceMapOutputFilepath() {
                var filepath = elems.inpSourceMapOutputFilepath.value;
                return filepath;
            }
            function setSourceMapOutputFilepath(outFilepath) {
                elems.inpSourceMapOutputFilepath.value = outFilepath;
            }
            function getInputJs() {
                return elems.taJsInputCode.value;
            }
            function setInputJs(inputJs) {
                elems.taJsInputCode.value = inputJs;
            }

            function getOutputJs() {
                return elems.taJsOutputCode.value;
            }
            function setOutputJs(outputJs) {
                elems.taJsOutputCode.value = outputJs || "";
            }

            function getOutputSourceMapText() {
                return elems.taOutputSourceMap.value;
            }
            function setOutputSourceMapText(outputSourceMapText) {
                elems.taOutputSourceMap.value = outputSourceMapText || "";
            }

            function getSourceMapURL() {
                return getJsInputFilepath() + '.map';
            }

            function getFile() {
                var file;
                file = {
                    path: getJsInputFilepath(),
                    contents: getInputJs()
                };
                return file;
            }

            function getMinifyOptions () {
                var options = {
                    outSourceMap: true,
                    sourceMapURL: getSourceMapURL()
                };
                return options;
            }
            function getBeautifyOptions () {
                var options = {
                    outSourceMap: true,
                    sourceMapURL: getSourceMapURL()
                };
                return options;
            }

            function showError(err) {
                alert(err);
                console.log(err);
            }

            function clearOutputs() {
                setOutputJs();
                setOutputSourceMapText();
            }

            function beautifyJsonString(jsonString) {
                return JSON.stringify(JSON.parse(jsonString), null, 2)
            }

            function minify(file, options) {
                clearOutputs();
                uglyfly.minify(file, options, function (err, results) {
                    if (err) {
                        showError(err);
                        return;
                    }
                    setOutputJs(results.code);
                    if (results.map) {
                        setOutputSourceMapText(beautifyJsonString(results.map));
                    }
                });
            }

            function beautify(file, options) {
                clearOutputs();
                uglyfly.beautify(file, options, function (err, results) {
                    if (err) {
                        showError(err);
                        return;
                    }
                    setOutputJs(results.code);
                    if (results.map) {
                        setOutputSourceMapText(beautifyJsonString(results.map))
                    }
                });
            }

            elems.btnMinify.addEventListener('click', function () {
                minify(getFile(), getMinifyOptions());
            });

            elems.btnBeautify.addEventListener('click', function () {
                beautify(getFile(), getBeautifyOptions());
            });
        });

    });
}(window.require));