import { Transform } from 'class-transformer';

export const OptionalStringToStringsArray = (defaultValue: string[] = [], acceptEmptyString = false) =>
    Transform(({ value }) => {
        return (value && typeof value === 'string') || (acceptEmptyString && value === '')
            ? (value as string).split(',').filter(Boolean)
            : defaultValue;
    });
