OptionsNormalizer.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 { SeedRule } from './normalizer-rules/SeedRule';
  11. import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
  12. import { SourceMapBaseUrlRule } from './normalizer-rules/SourceMapBaseUrlRule';
  13. import { SourceMapFileNameRule } from './normalizer-rules/SourceMapFileNameRule';
  14. import { SplitStringsChunkLengthRule } from './normalizer-rules/SplitStringsChunkLengthRule';
  15. import { StringArrayRule } from './normalizer-rules/StringArrayRule';
  16. import { StringArrayEncodingRule } from './normalizer-rules/StringArrayEncodingRule';
  17. import { StringArrayThresholdRule } from './normalizer-rules/StringArrayThresholdRule';
  18. import { StringArrayWrappersChainedCallsRule } from './normalizer-rules/StringArrayWappersChainedCalls';
  19. @injectable()
  20. export class OptionsNormalizer implements IOptionsNormalizer {
  21. /**
  22. * @type {TOptionsNormalizerRule[]}
  23. */
  24. private static readonly normalizerRules: TOptionsNormalizerRule[] = [
  25. ControlFlowFlatteningThresholdRule,
  26. DeadCodeInjectionRule,
  27. DeadCodeInjectionThresholdRule,
  28. DomainLockRule,
  29. InputFileNameRule,
  30. SeedRule,
  31. SelfDefendingRule,
  32. SourceMapBaseUrlRule,
  33. SourceMapFileNameRule,
  34. SplitStringsChunkLengthRule,
  35. StringArrayRule,
  36. StringArrayEncodingRule,
  37. StringArrayThresholdRule,
  38. StringArrayWrappersChainedCallsRule,
  39. ];
  40. /**
  41. * @param {IOptions} options
  42. * @returns {IOptions}
  43. */
  44. public normalize (options: IOptions): IOptions {
  45. let normalizedOptions: IOptions = {
  46. ...options
  47. };
  48. for (const normalizerRule of OptionsNormalizer.normalizerRules) {
  49. normalizedOptions = normalizerRule(normalizedOptions);
  50. }
  51. return normalizedOptions;
  52. }
  53. }