@type-ddd/username
Version:
This package provides TypeScript type definitions for handling User Name in Domain-Driven Design contexts
86 lines (85 loc) • 2.38 kB
TypeScript
import { Result, ValueObject } from 'rich-domain';
export declare class UserName extends ValueObject<string> {
protected static readonly MAX_LENGTH: number;
protected static readonly MIN_LENGTH: number;
protected static readonly MESSAGE: string;
private constructor();
/**
* @returns capitalized full name
*/
value(): string;
/**
*
* @returns capitalize full name as string
*/
static capitalize(fullName: string): string;
/**
* @description get upper case name from instance
* @returns upperCase full name as string
*/
upperCase(): string;
/**
* @description get lower case name from instance
* @returns lowerCase full name as string
*/
lowerCase(): string;
/**
*
* @returns check if has a second name
*/
hasMiddleName(): boolean;
title(title: string): {
firstName: () => string;
fullName: () => string;
lastName: () => string;
middleName: () => string;
};
/**
*
* @returns check if has last name `first middle last`
*/
hasLastName(): boolean;
/**
*
* @returns first name
*/
firstName(title?: string): string;
/**
*
* @returns middle name if it has more than 2 names, else returns a empty string
*/
middleName(): string;
/**
*
* @returns last name if exists else return the name
*/
lastName(): string;
/**
* @returns initials as string
* @param separator as string char to separate letters
* @default separator (empty)
* @example
* for a name "Thomas A. Anderson" = "TAA"
*/
initials(separator?: string): string;
/**
*
* @param value value as string
* @returns instance of UserName or throw an error
*/
static init(value: string): UserName;
/**
* @description check name length min(2) max(40)
* @param value name as string
* @returns true if provided value is valid and false if not
*/
static isValid(value: string): boolean;
/**
* @description check name length min(2) max(40)
* @param value name as string
* @returns true if provided value is valid and false if not
*/
static isValidProps(value: string): boolean;
static create(value: string): Result<UserName | null>;
}
export default UserName;