NgIoUtil.adjustTsExamplePathForDart = function()

in public/resources/js/util.js [17:47]


    NgIoUtil.adjustTsExamplePathForDart = function (_path) {
        /* Convert a TS example path into a Dart example path. E.g.,
         *
         * - app/main.ts -> web/main.dart
         * - displaying-data/ts/app/app.component.2.ts -> displaying-data/dart/lib/app_component.dart
         *
         * Notice that the '.2' is dropped from the name.
         */
        if (!_path) return _path;
        var path = _path.trim();
        var folder = NgIoUtil.folderName(path);
        var ext = NgIoUtil.extname(path);
        var baseNameNoExt = NgIoUtil.basename(path, ext);
        var inWebFolder = baseNameNoExt.match(/^(main|index)(\.\d)?$/);

        // Adjust the folder path, e.g., '/ts/' -> '/dart/'
        folder = folder
            .replace(/(^|\/)ts($|\/)/, '$1dart$2')
            .replace(/(^|\/)app($|\/)/, inWebFolder ? '$1web$2' : '$1lib$2');

        // Special case not handled above: e.g., index.html -> web/index.html
        if (baseNameNoExt.match(/^(index|styles)(\.\d)?$/) && !folder.match(/web$/))
            folder = (folder ? folder + '/' : '') + 'web';

        // In file name, replace special characters with underscore
        baseNameNoExt = baseNameNoExt.replace(/[\-\.]/g, '_');

        // Adjust the file extension
        if (ext == '.ts') ext = '.dart';
        return (folder ? folder + '/' : '') + baseNameNoExt + ext;
    };