OptionsNormalizer.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { injectable } from 'inversify';
  2. import { TOptionsNormalizerRule } from '../types/options/TOptionsNormalizerRule';
  3. import { IOptions } from '../interfaces/options/IOptions';
  4. import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
  5. import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFlowFlatteningThresholdRule';
  6. import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
  7. import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
  8. import { DomainLockRule } from './normalizer-rules/DomainLockRule';
  9. import { InputFileNameRule } from './normalizer-rules/InputFileNameRule';
  10. import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
  11. import { SourceMapBaseUrlRule } from './normalizer-rules/SourceMapBaseUrlRule';
  12. import { SourceMapFileNameRule } from './normalizer-rules/SourceMapFileNameRule';
  13. import { StringArrayRule } from './normalizer-rules/StringArrayRule';
  14. import { StringArrayEncodingRule } from './normalizer-rules/StringArrayEncodingRule';
  15. import { StringArrayThresholdRule } from './normalizer-rules/StringArrayThresholdRule';
  16. @injectable()
  17. export class OptionsNormalizer implements IOptionsNormalizer {
  18. /**
  19. * @type {TOptionsNormalizerRule[]}
  20. */
  21. private static readonly normalizerRules: TOptionsNormalizerRule[] = [
  22. ControlFlowFlatteningThresholdRule,
  23. DeadCodeInjectionRule,
  24. DeadCodeInjectionThresholdRule,
  25. DomainLockRule,
  26. InputFileNameRule,
  27. SelfDefendingRule,
  28. SourceMapBaseUrlRule,
  29. SourceMapFileNameRule,
  30. StringArrayRule,
  31. StringArrayEncodingRule,
  32. StringArrayThresholdRule,
  33. ];
  34. /**
  35. * @param {IOptions} options
  36. * @returns {IOptions}
  37. */
  38. public normalize (options: IOptions): IOptions {
  39. let normalizedOptions: IOptions = {
  40. ...options
  41. };
  42. for (const normalizerRule of OptionsNormalizer.normalizerRules) {
  43. normalizedOptions = normalizerRule(normalizedOptions);
  44. }
  45. return normalizedOptions;
  46. }
  47. }