Skip to content

Commit 07af3d8

Browse files
docs(README.md): update.
1 parent 554be0e commit 07af3d8

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Manages an [`Error`][js-error] of validation.
195195

196196
![update]
197197

198-
A template of the error message guarded by [`string`][js-string] type with the replaceable `[problem]` and `[fix]` words. By default, it's set to `Problem: [problem] => Fix: [fix]`. It can be set directly or by the [`setTemplate()`][error-method-settemplate] and [`setMessage()`][error-method-setmessage] method.
198+
A template of the error message guarded by [`string`][js-string] type with the replaceable `[problem]` and `[fix]` words. By default, it's set to `Problem: [problem] => Fix: [fix]`. It can be set directly or by the [`setTemplate()`][error-method-settemplate] and [`setMessage()`][error-method-setmessage] method. The value is being checked against the existence of `[problem]` and `[fix]` words.
199199

200200
```typescript
201201
static get template(): string {
@@ -910,10 +910,51 @@ throw validationError;
910910

911911
<br>
912912

913-
### Complete usage of `ValidationError`
913+
### Another example usage of `ValidationError`
914914

915915
```typescript
916-
//
916+
// Example usage.
917+
import { ValidationError } from '@angular-package/error';
918+
919+
// Declare shape of the person.
920+
interface Person {
921+
firstName: string;
922+
lastName: string;
923+
}
924+
925+
// Initialize an instance.
926+
const validationErrorOfPerson = new ValidationError();
927+
928+
// Define a fix.
929+
const fix = 'Please, provide only alphabetical characters.';
930+
931+
// Create an object.
932+
const personError = {
933+
firstName: validationErrorOfPerson.setMessage({
934+
problem: 'Provided the first name cannot include special characters.',
935+
fix
936+
}),
937+
lastName: validationErrorOfPerson.setMessage({
938+
problem: 'Provided the last name cannot include special characters.',
939+
fix
940+
})
941+
};
942+
943+
944+
const addPerson = (person: Person) => {
945+
if (person.firstName.includes('#')) {
946+
personError.firstName.throw();
947+
}
948+
if (person.firstName.includes('#')) {
949+
personError.lastName.throw();
950+
}
951+
};
952+
953+
addPerson({
954+
firstName: '#',
955+
lastName: '#'
956+
});
957+
917958
```
918959

919960
<br>

0 commit comments

Comments
 (0)