Skip to content

Commit 54d5d4c

Browse files
author
Paulo Vinicius Ferreira Lima
committed
feat: add methods remover caracters specials in
custom-string value object
1 parent 42c074a commit 54d5d4c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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;

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)