# All files / src SourceMapInjector.ts

37.5% Statements 3/8
0% Branches 0/3
100% Functions 0/0
37.5% Lines 3/8

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    1x

    1x

    1x

     import { TSourceMapModes } from "./types/TSourceMapModes";

    import { SourceMapMode } from "./enums/SourceMapMode";

    import { Utils } from "./Utils";

    export class SourceMapInjector {
        /**
         * @param sourceCode
         * @param url
         * @param mode
         * @returns {string}
         */
        public static inject (sourceCode: string, url: string, mode: TSourceMapModes): string {
            let sourceMappingUrl: string = '//# sourceMappingURL=';

            switch (mode) {
                case SourceMapMode.Inline:
                    sourceMappingUrl += `data:application/json;base64,${Utils.btoa(url, false)}`;

                    break;

                case SourceMapMode.Separate:
                default:
                    sourceMappingUrl += url;
            }

            return `${sourceCode}\n${sourceMappingUrl}`;
        }
    }