4lessandrodev / rich-domain

A lib to help you create a robust project based on domain driven-design (ddd) principles with typescript and zero dependencies.
https://www.npmjs.com/package/rich-domain
MIT License
122 stars 5 forks source link

Feat/util #31

Closed 4lessandrodev closed 1 year ago

4lessandrodev commented 1 year ago

1.16.2 - 2022-01-19

Added

Example:


// remove spaces from string

const text = " Some Text With Space ";

const result = Utils.string(text).removeSpaces();

> "SomeTextWithSpace"

// remove special chars

const text = "Some #Text @With Special&* Chars";

const result = Utils.string(text).removeSpecialChars();

> "Some Text With Special Chars"

// calculate values as number

const result = Utils.number(100).multiplyBy(3);

> 300

// also works case leak value as string

const result = Utils.number("100").multiplyBy("3");

> 300

// instance available on domain instances

interface Props { value: number };

class Example extends ValueObject<Props>{

  private constructor(props: Props){
    super(props)
  }

  sum(x: number): number {
     const current = this.props.value;
     return this.util.number(current).sum(x);
  }

}