Skip to content

Commit dce266b

Browse files
Merge branch 'main' of github.com:ArturHamannRonconi/types-ddd into fix/url-value-object
2 parents 4d5cf90 + 06eb0ce commit dce266b

14 files changed

+133
-26
lines changed

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,53 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
---
8+
### 3.5.0 - 2023-01-21
9+
10+
### Update
11+
12+
- rich-domain: update lib core to 1.17.0
13+
14+
15+
---
16+
### 3.4.7 - 2023-01-19
17+
18+
### Update
19+
20+
- rich-domain: update lib core to 1.16.2
21+
22+
---
23+
### 3.4.6 - 2023-01-18
24+
25+
### Update
26+
27+
- rich-domain: update lib core to 1.16.1
28+
29+
---
30+
### 3.4.5 - 2023-01-14
31+
32+
### Changed
33+
34+
- date.value-object: rename method from `isEqual` to `isEqualDate`
35+
36+
### Update
37+
38+
- rich-domain: update lib core to 1.16.0
39+
- Entity: added method isEqual to compare current instance with another one.
40+
- ValueObject: added method isEqual to compare current instance with another one. [Issue 27](https://github.com/4lessandrodev/rich-domain/issues/27)
41+
42+
---
43+
44+
### 3.4.4 - 2023-01-12
45+
46+
### Added
47+
48+
- custom-string.value-object: By: [VinnyLima](https://github.com/VinnyLima)
49+
- removeSpecialChars and onlyNumbers: [Issue 223](https://github.com/4lessandrodev/types-ddd/issues/223)
50+
- email.value-object: added MESSAGE as customizable value
51+
52+
---
53+
754
### 3.4.3 - 2023-01-05
855

956
### Updated

docs/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,17 +1194,12 @@ You can compare two entities.
11941194

11951195
```ts
11961196

1197-
const isEqual = user1.equal(user2);
1197+
const isEqual = user1.isEqual(user2);
11981198

11991199
console.log(isEqual);
12001200

12011201
> false
12021202

1203-
const isDeepEqual = user1.deepEqual(user2);
1204-
1205-
console.log(isDeepEqual);
1206-
1207-
> false
12081203

12091204
```
12101205

lib/utils/cpf.value-object.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ValueObject } from '../core';
22
import { Result } from '../core';
33
import isValidCpfDigit, {
44
formatValueToCpfPattern,
5-
removeSpecialCharsFromCpf,
65
} from './check-cpf-digit.util';
76
const regexCpf =
87
/^([0-9]{3})[\.]((?!\1)[0-9]{3})[\.]([0-9]{3})[-]([0-9]{2})$|^[0-9]{11}$/;
@@ -36,7 +35,9 @@ export class CPFValueObject extends ValueObject<Prop> {
3635
* @example after "52734865211"
3736
*/
3837
removeSpecialChars(): CPFValueObject {
39-
this.props.value = removeSpecialCharsFromCpf(this.props.value);
38+
this.props.value = this.util
39+
.string(this.props.value)
40+
.removeSpecialChars();
4041
return this;
4142
}
4243

@@ -58,8 +59,10 @@ export class CPFValueObject extends ValueObject<Prop> {
5859
* @example param "527.348.652-11"
5960
*/
6061
compare(cpf: string): boolean {
61-
const formattedCpf = removeSpecialCharsFromCpf(cpf);
62-
const instanceValue = removeSpecialCharsFromCpf(this.props.value);
62+
const formattedCpf = this.util.string(cpf).removeSpecialChars();
63+
const instanceValue = this.util
64+
.string(this.props.value)
65+
.removeSpecialChars();
6366
return instanceValue === formattedCpf;
6467
}
6568

lib/utils/currency.value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CurrencyValueObject extends ValueObject<Prop> {
209209
* @returns boolean true if instance value is positive else false
210210
*/
211211
isPositive(): boolean {
212-
return this.cents >= 0;
212+
return this.validator.number(this.cents).isPositive();
213213
}
214214

215215
validation(_value: any, _key: any): boolean {

lib/utils/custom-string.value-object.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ export class CustomStringValueObject extends ValueObject<Prop> {
6262
);
6363
}
6464

65+
/**
66+
* @returns value without special chars as string
67+
*/
68+
get removeSpecialChars(): string {
69+
return this.props.value.replace(/[^a-zA-Z0-9]/g, '');
70+
}
71+
72+
/**
73+
* @returns value only numbers as string
74+
*/
75+
get onlyNumbers(): string {
76+
return this.props.value.replace(/\D/g, '');
77+
}
78+
6579
/**
6680
* @returns validation
6781
* @method VALIDATOR: function (value: string): boolean;

lib/utils/date-value-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export class DateValueObject extends ValueObject<Prop> {
438438
* @param date as Date
439439
* @returns true or false. True if instance date is equal to provided value
440440
*/
441-
isEqual(date: Date): boolean {
441+
isEqualDate(date: Date): boolean {
442442
const time = date.getTime();
443443
const instanceTime = this.props.value.getTime();
444444
return instanceTime === time;

lib/utils/email.value-object.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class EmailValueObject extends ValueObject<Prop> {
1010
protected static readonly DISABLE_SETTER: boolean = true;
1111
protected static readonly BLOCKED_DOMAINS: Array<string> = [];
1212
protected static readonly VALID_DOMAINS: Array<string> = [];
13+
protected static readonly MESSAGE: string = 'Invalid email';
1314

1415
private constructor(props: Prop) {
1516
super(props, { disableSetters: EmailValueObject.DISABLE_SETTER });
@@ -67,7 +68,7 @@ export class EmailValueObject extends ValueObject<Prop> {
6768

6869
public static create(value: string): Result<EmailValueObject> {
6970
if (!EmailValueObject.isValidProps(value)) {
70-
return Result.fail('Invalid email');
71+
return Result.fail(EmailValueObject.MESSAGE);
7172
}
7273
return Result.Ok(new EmailValueObject({ value }));
7374
}

lib/utils/user-name.value-object.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export class UserNameValueObject extends ValueObject<Prop> {
3838
name[0].toUpperCase() + name.slice(1).toLowerCase();
3939
capitalized.push(lowerCaseName);
4040
}
41-
this.props.value = capitalized.toString().replace(/,/g, ' ');
41+
const value = this.util
42+
.string(capitalized.toString())
43+
.replace(',')
44+
.to(' ');
45+
this.props.value = value;
4246
return this;
4347
}
4448

@@ -94,7 +98,10 @@ export class UserNameValueObject extends ValueObject<Prop> {
9498
getInitials(): string {
9599
const names = this.props.value.split(' ');
96100
const letters = names.map((name) => name[0]);
97-
const initials = letters.toString().replace(/,/g, '.');
101+
const initials = this.util
102+
.string(letters.toString())
103+
.replace(',')
104+
.to('.');
98105
return initials;
99106
}
100107

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "types-ddd",
3-
"version": "3.4.3",
3+
"version": "3.5.0",
44
"description": "This package provide utils file and interfaces to assistant build a complex application with domain driving design",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -61,7 +61,7 @@
6161
"bcrypt": "^5.0.1",
6262
"pino": "^8.8.0",
6363
"pino-pretty": "^9.1.1",
64-
"rich-domain": "^1.15.2"
64+
"rich-domain": "^1.17.0"
6565
},
6666
"devDependencies": {
6767
"@microsoft/tsdoc": "^0.14.1",
@@ -74,7 +74,7 @@
7474
"lint-staged": "^13.0.4",
7575
"madge": "^5.0.1",
7676
"prettier": "^2.8.1",
77-
"rimraf": "^3.0.2",
77+
"rimraf": "^4.1.1",
7878
"ts-jest": "^27.1.4",
7979
"ts-node": "^10.7.0",
8080
"typescript": "^4.9.4"

tests/utils/custom-string.value-object.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ describe('custom-string.value-object', () => {
6363
expect(validation.MAX_LENGTH).toBeDefined();
6464
expect(validation.MIN_LENGTH).toBeDefined();
6565
});
66+
67+
it('should be get string only numbers', () => {
68+
const valueObject =
69+
CustomStringValueObject.create('B2D05E00').value().onlyNumbers;
70+
expect(valueObject).toBe('20500');
71+
});
72+
73+
it('should be get string without chars especial', () => {
74+
const valueObject = CustomStringValueObject.create(
75+
'===[brazil(*-*)free]==='
76+
);
77+
expect(valueObject.value().removeSpecialChars).toBe('brazilfree');
78+
});
6679
});
6780

6881
describe('custom validation', () => {

0 commit comments

Comments
 (0)