Skip to content

Commit f97ddbb

Browse files
docs(README.md): update
1 parent 5e21421 commit f97ddbb

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Manages an [`Error`][js-error] of the validation.
134134

135135
### `ValidationError.template`
136136

137-
Template of the error message with the replaceable `[problem]` and `[fix]`.
137+
Template of the error message with the replaceable `[problem]` and `[fix]`. By default, it's set to `Problem: [problem] => Fix: [fix]`.
138138

139139
```typescript
140140
static template = `Problem: [problem] => Fix: [fix]`;
@@ -156,7 +156,7 @@ public fix = '';
156156

157157
### `ValidationError.prototype.name`
158158

159-
Error name of a string type that is being thrown. By default, it's `ValidationError`.
159+
Error name of a [`string`][js-string] type that is being thrown. By default, it's [`ValidationError`](#validationerror).
160160

161161
```typescript
162162
public name = ValidationError.name;
@@ -166,7 +166,7 @@ public name = ValidationError.name;
166166

167167
### `ValidationError.prototype.problem`
168168

169-
The validation problem of a [`string`][js-string] type. By default, it's an empty string.
169+
The validation problem of a [`string`][js-string] type. By default, it's an empty [`string`][js-string].
170170

171171
```typescript
172172
public problem = '';
@@ -181,25 +181,33 @@ public problem = '';
181181
Defines the validation error message of a [`string`][js-string] type from the provided `message` of the [`ErrorMessage`](#errormessage) interface.
182182

183183
```typescript
184-
static defineMessage(message: ErrorMessage): string {
185-
if (is.objectKey(message, ['fix', 'problem'])) {
186-
return `Problem: ${message.problem}. ${
187-
is.string(message.fix) ? `Fix: ${message.fix}` : ''
188-
}`;
184+
static defineMessage(
185+
message: ErrorMessage,
186+
template: string = ValidationError.template,
187+
callback?: ResultCallback
188+
): string {
189+
if (is.objectKey(message, ['fix', 'problem'], callback)) {
190+
if (is.string(template)) {
191+
return template
192+
.replace(`[fix]`, message.fix)
193+
.replace(`[problem]`, message.problem);
194+
}
189195
}
190196
return '';
191197
}
192198
```
193199

194200
**Parameters:**
195201

196-
| Name: type | Description |
197-
| :---------------------- | :---------- |
198-
| `message: ErrorMessage` | An [`object`][js-object] of the [`ErrorMessage`](#errormessage) interface to build a message of a [`string`][js-string] type. The value is checked against the proper [`object`][js-object] |
202+
| Name: type | Description |
203+
| :-------------------------- | :---------- |
204+
| `message: ErrorMessage` | An [`object`][js-object] of the [`ErrorMessage`](#errormessage) interface to build a message of a [`string`][js-string] type. The value is checked against the proper [`object`][js-object] |
205+
| `template: string` | A message template of a [`string`][js-string] type with replaceable `[problem]` and `[fix]` from the given `message`. The value is checked against a [`string`][js-string]. By default, it's set to `Problem: [problem] => Fix: [fix]` |
206+
| `callback?: ResultCallback` | An optional callback function of [`ResultCallback`][package-type-resultcallback] type to handle the check whether the provided message contains required `problem` and `fix` properties |
199207

200208
**Returns:**
201209

202-
The **return value** is a message of a `string` type created from the provided `message` of [`ErrorMessage`](#errormessage) interface, or it's an empty `string` if the provided message object isn't proper.
210+
The **return value** is a message of a `string` type created from the provided `message` of [`ErrorMessage`](#errormessage) interface, or it's an empty [`string`][js-string] if the provided message [`object`][js-object] isn't proper.
203211

204212
**Usage:**
205213

@@ -209,6 +217,7 @@ import { ValidationError } from '@angular-package/core';
209217

210218
const fix = 'There is no solution to the described problem.';
211219
const problem = 'The problem has no solution.';
220+
212221
/**
213222
* Returns
214223
* --------
@@ -227,9 +236,14 @@ Creates a new instance with the message. If the provided `message` is an [`objec
227236

228237
```typescript
229238
new ValidationError(message: string | ErrorMessage) {
230-
super(is.string(message) ? message : ValidationError.defineMessage(message));
239+
super(
240+
is.string(message) ? message : ValidationError.defineMessage(message)
241+
);
231242
if (is.object(message)) {
232-
Object.assign(this, getProperties(message, ['fix', 'problem']));
243+
Object.assign(this, {
244+
problem: message.problem,
245+
fix: message.fix,
246+
});
233247
}
234248
}
235249
```
@@ -238,7 +252,7 @@ new ValidationError(message: string | ErrorMessage) {
238252

239253
| Name: type | Description |
240254
| :-------------------------------- | :---------- |
241-
| `message: string \| ErrorMessage` | The message of a `string` type or of an [`ErrorMessage`](#errormessage) interface that is used to throw with an [`error`][js-error] |
255+
| `message: string \| ErrorMessage` | The message of a [`string`][js-string] type or of an [`ErrorMessage`](#errormessage) interface that is used to throw with an [`error`][js-error] |
242256

243257
**Returns:**
244258

@@ -276,14 +290,6 @@ interface ErrorMessage {
276290
}
277291
```
278292

279-
### ResultHandler
280-
281-
Function to handle the result of the [`ResultCallback`][package-type-resultcallback] [`function`][js-function] before its result returns.
282-
283-
```typescript
284-
type ResultHandler = (result: boolean, value: any) => void;
285-
```
286-
287293
<br>
288294

289295
## GIT

0 commit comments

Comments
 (0)