Skip to content

Commit f8a07d9

Browse files
Merge pull request #8 from angular-package/2.0.x
2.0.1
2 parents 33ef75e + 49fdc9c commit f8a07d9

File tree

5 files changed

+65
-27
lines changed

5 files changed

+65
-27
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/)
77
and this project adheres to [Semantic Versioning](http://semver.org/).
88

9+
## [2.0.1] - 2021-08-12
10+
11+
### 2.0.1 Fix
12+
13+
- [`c77f3cf`][c77f3cf]
14+
Fix JS documentation of `ValidationError`.
15+
16+
- [`bc8e965`][bc8e965]
17+
Fix documentation of `README.md`.
18+
19+
[c77f3cf]: https://github.com/angular-package/error/commit/c77f3cfc8f7958dbfa29022d2e564d6095c2dc65
20+
[bc8e965]: https://github.com/angular-package/error/commit/bc8e9653bd5e5546f2a3df2d6d6f18bcefea192b
21+
922
## [2.0.0] - 2021-08-12
1023

1124
### 2.0.0 Added

README.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ Manages an [`Error`][js-error] of validation.
146146
| ValidationError.prototype. | Description |
147147
| :------------------------------------------ | :---------- |
148148
| [`fix: string`][error-property-fix] | A possible solution to the described [`problem`][error-property-problem] of validation that is guarded by a [`string`][js-string] type. |
149-
| [`message: string`][error-property-message] | A validation error message guarded by a [`string`][js-string] type that can be built with the [`problem`][error-property-problem] and [`fix`][error-property-fix] of [`ValidationError`](#validationerror) by the [`throw()`][error-method-throw] and [`setMessage()`][error-method-setmessage] method. |
149+
| [`message: string`][error-property-message] | A validation error message guarded by a [`string`][js-string] type that can be built with the [`problem`][error-property-problem] and [`fix`][error-property-fix] of [`ValidationError`](#validationerror) on the [`template`][error-property-template] by the [`throw()`][error-method-throw] and [`setMessage()`][error-method-setmessage] method. |
150150
| [`name: string`][error-property-name] | Error name of a [`string`][js-string] type that is being thrown. |
151-
| [`problem: string`][error-property-problem] | Description of a validation problem guarded by a [`string`][js-string] type. |
151+
| [`problem: string`][error-property-problem] | Description of a validation [`problem`][error-property-problem] guarded by a [`string`][js-string] type. |
152152

153153
[error-property-fix]: #validationerrorprototypefix
154154
[error-property-message]: #validationerrorprototypemessage
@@ -173,7 +173,7 @@ Manages an [`Error`][js-error] of validation.
173173
| :---------------------------------------------- | :---------- |
174174
| [`setFix()`][error-method-setfix] | Sets the fix a possible solution to the described [`problem`][error-property-problem]. |
175175
| [`setMessage()`][error-method-setmessage] | Sets the validation error message of a [`string`][js-string] type from the provided `message` of the [`ErrorMessage`](#errormessage) interface. |
176-
| [`setProblem()`][error-method-setproblem] | Sets description problem of a [`ValidationError`](#validationerror). |
176+
| [`setProblem()`][error-method-setproblem] | Sets description problem of a validation. |
177177
| [`setTemplate()`][error-method-settemplate] | Sets the template of validation error message. |
178178
| [`throw()`][error-method-throw] | Throws an error of [`ValidationError`](#validationerror) with actual settings. |
179179
| [`updateMessage()`][error-method-updatemessage] | Updates the message with a stored [`fix`][error-property-fix], [`problem`][error-property-problem], and [`template`][error-property-template]. |
@@ -195,7 +195,7 @@ Manages an [`Error`][js-error] of validation.
195195

196196
![update]
197197

198-
**`2.0.0`:** Uses static private property `#template` and guards the value with private static method `#guardTemplate()` to be `string` type that contains `[fix]` and `[problem]` words.
198+
**`2.0.0`:** Uses static private property `#template` and guards the value with private static method `#guardTemplate()` to be [`string`][js-string] type that contains `[fix]` and `[problem]` words.
199199

200200
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.
201201

@@ -239,7 +239,7 @@ public set fix(value: string) {
239239

240240
![update]
241241

242-
**`2.0.0`:** Uses inherited from `Error` property and guards the value to be a [`string`][js-string] type.
242+
**`2.0.0`:** Uses inherited from [`Error`][js-error] property and guards the value to be a [`string`][js-string] type.
243243

244244
A validation error message guarded by a [`string`][js-string] type that can be build from the [`problem`][error-property-problem] and [`fix`][error-property-fix] of [`ValidationError`](#validationerror) on the [`template`][error-property-template]. It can be set directly or by the [`throw()`][error-method-throw] and [`setMessage()`][error-method-setmessage] method.
245245

@@ -672,7 +672,7 @@ console.log(validationError.message);
672672

673673
![new]
674674

675-
Sets description [`problem`][error-property-problem] of a validation error.
675+
Sets description [`problem`][error-property-problem] of a validation.
676676

677677
```typescript
678678
public setProblem(
@@ -690,8 +690,8 @@ public setProblem(
690690

691691
| Name: type | Description |
692692
| :------------------------------------------- | :---------- |
693-
| `fix: string` | A possible solution to the described [`problem`][error-property-problem] guarded by a [`string`][js-string] type. |
694-
| `callback?: ResultCallback<CallbackPayload>` | An optional callback function of [`ResultCallback`][package-callback-resultcallback] type to handle the check whether the provided `fix` is a [`string`][js-string]. By default, it uses an internal callback under the `'setProblem'` name, which can be initially set by the optional `callback` parameter that gives access to the internal instance of [`Callback`][callback-github-readme]. |
693+
| `problem: string` | Description of a validation [`problem`][error-property-problem] guarded by a [`string`][js-string] type. |
694+
| `callback?: ResultCallback<CallbackPayload>` | An optional callback function of [`ResultCallback`][package-callback-resultcallback] type to handle the check whether the provided `problem` is a [`string`][js-string]. By default, it uses an internal callback under the `'setProblem'` name, which can be initially set by the optional `callback` parameter that gives access to the internal instance of [`Callback`][callback-github-readme]. |
695695

696696
**Returns:**
697697

@@ -856,6 +856,26 @@ const validationError = new ValidationError({ fix, problem, template });
856856
validationError.throw();
857857
```
858858

859+
```typescript
860+
// Example usage.
861+
import { ValidationError } from '@angular-package/error';
862+
863+
// Define a fix.
864+
const fix = 'There is no solution to the described problem.';
865+
866+
// Define a problem.
867+
const problem = 'The problem has no solution.';
868+
869+
// Define a template.
870+
const template = 'PROBLEM: [problem] FIX: [fix]';
871+
872+
// Initialize an instance.
873+
const validationError = new ValidationError();
874+
875+
// Throw an error with message.
876+
validationError.throw({ fix, problem, template });
877+
```
878+
859879
<br>
860880

861881
#### `ValidationError.prototype.updateMessage()`
@@ -990,14 +1010,14 @@ export interface ErrorMessage {
9901010
**Properties:**
9911011

9921012
**`fix: string`**
993-
Possible solution to the described problem of a [`string`][js-string] type.
1013+
A possible solution to the described problem of a [`string`][js-string] type.
9941014

9951015
**`problem: string`**
9961016
Description of validation problem of a [`string`][js-string] type.
9971017

9981018
**`template?: string`**
9991019
![new]
1000-
An optional message template of a [`string`][js-string] type.
1020+
An optional error message template of a [`string`][js-string] type.
10011021

10021022
<br>
10031023

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-package/error",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Manages an error.",
55
"author": "Angular Package <angular-package@wvvw.dev> (https://wvvw.dev)",
66
"homepage": "https://github.com/angular-package/error#readme",
@@ -22,8 +22,13 @@
2222
"@angular",
2323
"@angular-package",
2424
"@angular-package/error",
25+
"Error",
2526
"angular-package",
26-
"Error"
27+
"error fix",
28+
"error message",
29+
"error problem",
30+
"error template",
31+
"validation error"
2732
],
2833
"repository": {
2934
"type": "git",

src/lib/validation-error.class.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export class ValidationError extends Error {
5151

5252
/**
5353
* A template of the error message guarded by a `string` type with the replaceable `[problem]` and `[fix]` words.
54+
* By default, it's set to `Problem: [problem] => Fix: [fix]`. It can be set directly or by the `setTemplate()` and `setMessage()` method.
5455
* The value is being checked against the existence of `[problem]` and `[fix]` words.
55-
* By default, it's set to `Problem: [problem] => Fix: [fix]`.
5656
*/
5757
static get template(): string {
5858
return ValidationError.#template;
@@ -66,7 +66,7 @@ export class ValidationError extends Error {
6666
//#region instance public properties.
6767
/**
6868
* A possible solution to the described `problem` of validation that is guarded by a `string` type.
69-
* By default, it's an empty `string`.
69+
* By default, it's an empty `string`. It can be set directly or by the `setTemplate()` and `setMessage()` method
7070
*/
7171
public get fix(): string {
7272
return this.#fix;
@@ -76,8 +76,8 @@ export class ValidationError extends Error {
7676
}
7777

7878
/**
79-
* A validation error message guarded by a `string` type that can be built with the `problem` and `fix` of `ValidationError` by the
80-
* `throw()` and `setMessage()` method.
79+
* A validation error message guarded by a `string` type that can be built from the `problem` and `fix` of `ValidationError` on the
80+
* `template`. It can be set directly or by the `throw()` or `setMessage()` method.
8181
*/
8282
public set message(value: string) {
8383
super.message = guard.string(value) ? value : super.message;
@@ -87,14 +87,13 @@ export class ValidationError extends Error {
8787
}
8888

8989
/**
90-
* Error name of a `string` type that is being thrown.
91-
* By default, it's `ValidationError`.
90+
* Error name of a `string` type that is being thrown. By default, it's `ValidationError`.
9291
*/
9392
public name = ValidationError.name;
9493

9594
/**
96-
* Description of a validation problem guarded by a `string` type.
97-
* By default, it's an empty `string`.
95+
* Description of a validation problem guarded by a `string` type. By default, it's an empty `string`.
96+
* It can be set directly or by the `setProblem()` and `setMessage()` method.
9897
*/
9998
public get problem(): string {
10099
return this.#problem;
@@ -107,7 +106,7 @@ export class ValidationError extends Error {
107106
//#region static public methods
108107
/**
109108
* Defines the validation error message of a `string` type from the provided `message` of the `ErrorMessage` interface.
110-
* @param message An object of an `ErrorMessage` interface to build the message of a `string` type. The value is checked against
109+
* @param message An object of an `ErrorMessage` interface to build a message of a `string` type. The value is checked against
111110
* the proper `object`.
112111
* @param callback An optional callback function of `ResultCallback` type to handle the check whether the provided message contains
113112
* required `problem` and `fix` properties.
@@ -171,7 +170,7 @@ export class ValidationError extends Error {
171170
/**
172171
* Creates a new instance with the message. If the provided `message` is an `object`, then its properties are assigned
173172
* to the instance.
174-
* @param message The message of a `string` type or of an `ErrorMessage` interface to throw with an `Error`.
173+
* @param message The message of a `string` type or of an `ErrorMessage` interface that is used to throw with an `Error`.
175174
* @param callback An optional function to handle the internal instance of `Callback`.
176175
* @angularpackage
177176
*/
@@ -246,8 +245,8 @@ export class ValidationError extends Error {
246245
}
247246

248247
/**
249-
* Sets description problem of a validation error.
250-
* @param problem Description of a problem of validation error guarded by a `string` type.
248+
* Sets description problem of a validation.
249+
* @param problem Description of validation problem guarded by a `string` type.
251250
* @param callback An optional callback function of `ResultCallback` type to handle the check whether the provided `problem` is a
252251
* `string`. By default, it uses an internal callback under the `'setProblem'` name, which can be initially set by the optional `callback`
253252
* parameter that gives access to the internal instance of `Callback`.
@@ -287,7 +286,8 @@ export class ValidationError extends Error {
287286
/**
288287
* Throws an error of `ValidationError` with the message built from the stored `fix`, `problem` and `template` or optionally from
289288
* the provided `message`.
290-
* @param message An optional
289+
* @param message An optional object of an `ErrorMessage` interface to build the message of a `string` type.
290+
* The value is checked against the proper object.
291291
* @angularpackage
292292
*/
293293
public throw(message?: string | ErrorMessage): void {

0 commit comments

Comments
 (0)