import { Either , left , right } from '@/shared' ; import { InvalidTitleError } from '@/entities/errors' ; export class Title { public readonly value : string ; private constructor ( title ) { this . value = title ; Object . freeze ( this ) ; } public static create ( title ) { if ( valid ( title ) ) { return right ( new Title ( title ) ) ; } return left ( new InvalidTitleError ( title ) ) ; } } function valid ( title ) { if ( emptyOrTooLittle ( title ) || tooLarge ( title ) ) { return false ; } return true ; } function emptyOrTooLittle ( title ) { return ! title || title . trim ( ) . length < 3 ; } function tooLarge ( title ) { return title . length > 256 ; }