@@ -152,10 +152,17 @@ Manages an [`Error`][js-error] of the validation.
152152
153153#### ` ValidationError.template `
154154
155- Template of the error message with the replaceable ` [problem] ` and ` [fix] ` . By default, it's set to ` Problem: [problem] => Fix: [fix] ` .
155+ A template of the error message guarded by [ ` string ` ] [ js-string ] type with the replaceable ` [problem] ` and ` [fix] ` . By default, it's set to ` Problem: [problem] => Fix: [fix] ` .
156156
157157``` typescript
158- static template = ` Problem: [problem] => Fix: [fix] ` ;
158+ static get template (): string {
159+ return this .#template ;
160+ }
161+ static set template (value : string ) {
162+ if (guard .string (value )) {
163+ this .#template = value ;
164+ }
165+ }
159166```
160167
161168<br >
@@ -248,6 +255,57 @@ const problem = 'The problem has no solution.';
248255const errorMessage = ValidationError .defineMessage ({ fix , problem });
249256```
250257
258+ ``` typescript
259+ // Example usage: create an error message of a string type from the provided object with a different template.
260+ import { ValidationError } from ' @angular-package/error' ;
261+
262+ const fix = ' There is no solution to the described problem.' ;
263+ const problem = ' The problem has no solution.' ;
264+ const template = ` [problem] ... [fix] ` ;
265+
266+ /**
267+ * Returns
268+ * --------
269+ * The problem has no solution. ... There is no solution to the described problem.
270+ */
271+ const errorMessage = ValidationError .defineMessage ({ fix , problem , template });
272+ ```
273+
274+ ``` typescript
275+ // Example usage: create an error message of a string type from the provided object and the changed template.
276+ import { ValidationError } from ' @angular-package/error' ;
277+
278+ // Change the template by directly assign a new value.
279+ ValidationError .template = ` \n PROBLEM: [problem]\n FIX: [fix] ` ;
280+
281+ const fix = ' There is no solution to the described problem.' ;
282+ const problem = ' The problem has no solution.' ;
283+
284+ /**
285+ * Returns
286+ * --------
287+ * PROBLEM: The problem has no solution.
288+ * FIX: There is no solution to the described problem.
289+ */
290+ const errorMessage = ValidationError .defineMessage ({ fix , problem });
291+ ```
292+
293+ ``` typescript
294+ // Example usage: create an error message of a string type from the provided object and the changed template.
295+ import { ValidationError } from ' @angular-package/error' ;
296+
297+ const fix = ' There is no solution to the described problem.' ;
298+ const problem = ' The problem has no solution.' ;
299+
300+ const errorMessage = ValidationError .defineMessage (
301+ { fix , problem },
302+ (result , payload ) => {
303+ // Do something with the `result` of the `message` check and `payload`.
304+ return result ;
305+ }
306+ );
307+ ```
308+
251309<br >
252310
253311### ` ValidationError ` constructor
@@ -295,6 +353,14 @@ const validationError = new ValidationError({ fix, problem });
295353
296354<br >
297355
356+ ### Complete usage of ` ValidationError `
357+
358+ ``` typescript
359+ //
360+ ```
361+
362+ <br >
363+
298364## Interface
299365
300366### Common
@@ -355,7 +421,7 @@ import { MessageBuilder } from '@angular-package/error';
355421 */
356422const messageMethodBuilder = new MessageBuilder (' method' );
357423
358- // Build the class method.
424+ // Build the method of any class .
359425messageMethodBuilder
360426 .setMethodName (' setPerson' )
361427 .setParam (' value' , ' string' )
@@ -374,7 +440,7 @@ import { MessageBuilder } from '@angular-package/error';
374440 */
375441const messageClassBuilder = new MessageBuilder (' class' );
376442
377- // Build the class.
443+ // Build the method of a specified class.
378444messageClassBuilder
379445 .setClassName (' Person.prototype.' )
380446 .setMethodName (' setPerson' )
0 commit comments