All files / src/templates/custom-nodes AtobTemplate.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2
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      1x 5x                                              
/**
 * @returns {string}
 */
export function AtobTemplate (): string {
    return `
        (function () {
            var getGlobal = Function('return (function () ' + '{}.constructor("return this")()' + ');');
 
            var object = getGlobal();
            var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
 
            object.atob || (
                object.atob = function(input) {
                    var str = String(input).replace(/=+$/, '');
                    for (
                        var bc = 0, bs, buffer, idx = 0, output = '';
                        buffer = str.charAt(idx++);
                        ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
                            bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
                    ) {
                        buffer = chars.indexOf(buffer);
                    }
                return output;
            });
        })();
    `;
}