OptionsNormalizer.ts 2.3 KB

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