Presupuestador_web/shared/lib/contexts/common/domain/entities/StringValueObject.ts
2024-04-23 17:29:38 +02:00

23 lines
605 B
TypeScript

import { UndefinedOr } from "../../../../utilities";
import { IValueObjectOptions, ValueObject } from "./ValueObject";
export interface IStringValueObjectOptions extends IValueObjectOptions {}
export class StringValueObject extends ValueObject<UndefinedOr<string>> {
public isEmpty = (): boolean => {
return this.toString().length === 0;
};
public toString = (): string => {
return this.props ? String(this.props) : "";
};
public toPrimitive(): string {
return this.toString();
}
get value(): UndefinedOr<string> {
return !this.isEmpty() ? this.props : undefined;
}
}