OptionsPresetSanitizer.ts 640 B

123456789101112131415161718192021
  1. import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
  2. import { OptionsPreset } from '../../enums/options/presets/OptionsPreset';
  3. /**
  4. * @param {string} value
  5. * @returns {string}
  6. */
  7. export const OptionsPresetSanitizer: TCLISanitizer <string> = (value: string): string => {
  8. const isCorrectOptionsPreset: boolean = Object
  9. .keys(OptionsPreset)
  10. .some((key: string): boolean => {
  11. return OptionsPreset[<keyof typeof OptionsPreset>key] === value;
  12. });
  13. if (!isCorrectOptionsPreset) {
  14. throw new ReferenceError('Invalid value of `--options-preset` option');
  15. }
  16. return value;
  17. };