# All files / src JavaScriptObfuscator.ts

94.12% Statements 16/17
87.5% Branches 7/8
100% Functions 0/0
94.12% Lines 16/17

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    491x

    1x

    1x

    1x

    1x
    1x
    1x

    1x

    1810x
    1810x
    1810x

    1810x
    12x

    1810x

    1810x

    10x

     import 'reflect-metadata';

    Iif (!(<any>global)._babelPolyfill) {
        require('babel-polyfill');
    }

    import { ServiceIdentifiers } from './container/ServiceIdentifiers';

    import { Chance } from 'chance';

    import { TInputOptions } from './types/options/TInputOptions';

    import { IInversifyContainerFacade } from './interfaces/container/IInversifyContainerFacade';
    import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
    import { IObfuscationResult } from './interfaces/IObfuscationResult';
    import { IOptions } from './interfaces/options/IOptions';

    import { InversifyContainerFacade } from './container/InversifyContainerFacade';
    import { JavaScriptObfuscatorCLI } from './cli/JavaScriptObfuscatorCLI';
    import { RandomGeneratorUtils } from './utils/RandomGeneratorUtils';

    export class JavaScriptObfuscator {
        /**
         * @param sourceCode
         * @param inputOptions
         * @returns {string}
         */
        public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscationResult {
            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(inputOptions);
            const options: IOptions = inversifyContainerFacade.get<IOptions>(ServiceIdentifiers.IOptions);

            if (options.seed !== 0) {
                RandomGeneratorUtils.setRandomGenerator(new Chance(options.seed));
            }

            const javaScriptObfuscator: IJavaScriptObfuscator = inversifyContainerFacade
                .get<IJavaScriptObfuscator>(ServiceIdentifiers.IJavaScriptObfuscator);

            return javaScriptObfuscator.obfuscate(sourceCode);
        }

        /**
         * @param argv
         */
        public static runCLI (argv: string[]): void {
            new JavaScriptObfuscatorCLI(argv).run();
        }
    }