interface StringChain {
capitalize(): StringChain;
reverse(): StringChain;
addSuffix(suffix: string): string;
}
class CustomString implements StringChain {
private value: string;
constructor(str: string) {
this.value = str;
}
capitalize(): StringChain {
this.value = this.value.charAt(0).toUpperCase() + this.value.slice(1);
return this;
}
reverse(): StringChain {
this.value = this.value.split('').reverse().join('');
return this;
}
addSuffix(suffix: string): string {
return this.value + suffix;
}
}
let str = 'hello';
let result = new CustomString(str).capitalize().reverse().addSuffix(' world');
console.log(result);