Skip to content

Commit 955fee6

Browse files
Merge pull request #4 from angular-package/1.0.x
1.0.3
2 parents 3c9fbd3 + 99e9b9a commit 955fee6

12 files changed

+317
-130
lines changed

CHANGELOG.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ 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+
## [1.0.3] - 2021-08-06
10+
11+
### 1.0.3 Added
12+
13+
- [`5752d9e`][5752d9e]
14+
Tests for the `MessageFunctionBuilder`.
15+
- [`488270d`][488270d]
16+
Tests for the `MessageBuilder`.
17+
18+
[5752d9e]: https://github.com/angular-package/error/commit/5752d9e7b3631dcca0d6945e25a92d1fdfb9eee3
19+
[488270d]: https://github.com/angular-package/error/commit/488270d4c88f8575c8289022559e4f8ce1de828b
20+
21+
### 1.0.3 Changed
22+
23+
- [`5bd6a2b`][5bd6a2b]
24+
jsdoc description of the `MessageBuilder`.
25+
- [`1dffd31`][1dffd31]
26+
Updated `README.md`.
27+
28+
[5bd6a2b]: https://github.com/angular-package/error/commit/5bd6a2bf8dc98db6666f8d84bb28771357f17105
29+
[1dffd31]: https://github.com/angular-package/error/commit/1dffd31ab4db736a4f583ac4d3c1994c92da92ea
30+
31+
### 1.0.3 Fixed
32+
33+
- [`5427c65`][5427c65]
34+
Added message builder to api.
35+
36+
[5427c65]: https://github.com/angular-package/error/commit/5427c6585ddebe01bc6e3733425e07b924ec0ca6
37+
38+
----
39+
940
## [1.0.2] - 2021-08-04
1041

1142
### 1.0.2 Update
@@ -17,7 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1748
- [`253dda9`][253dda9]
1849
Fixes the `homepage` link in the `package.json`.
1950

20-
[77f326a]: https://github.com/angular-package/error/commit/253dda9b0cd14d7766f7ac3da33e4aaf35af1193
51+
[253dda9]: https://github.com/angular-package/error/commit/253dda9b0cd14d7766f7ac3da33e4aaf35af1193
2152

2253
## [1.0.1] - 2021-08-04
2354

@@ -26,4 +57,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2657
- [`ab8729f`][ab8729f]
2758
Remove unnecessary peer dependencies.
2859

29-
[77f326a]: https://github.com/angular-package/error/commit/ab8729f3627d63729326ddfd354296c2ae800c33
60+
[ab8729f]: https://github.com/angular-package/error/commit/ab8729f3627d63729326ddfd354296c2ae800c33

README.md

+127-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Manages an [`Error`][js-error].
4343
* [Api](#api)
4444
* [`ValidationError`](#validationerror)
4545
* [Interface](#interface)
46+
* [Experimental](#experimental)
47+
* [Changelog](#changelog)
4648
* [Git](#git)
4749
* [Commit](#commit)
4850
* [Versioning](#versioning)
@@ -63,13 +65,15 @@ Type guard (constrain)
6365
Guards
6466
> It's a **combination** of both above, **constrains** the type of the parameter in the **code editor**, and checks its provided argument.
6567
66-
Sets
67-
> Sets the existing given value in the `object`.
68-
6968
Defines
70-
> Returns defined value from the method of the `object`.
71-
> Defines the new value in the `object`.
72-
> Both above at the same time.
69+
> Returns defined value from a method of an object.
70+
> Defines new value in an object and returns a defined value.
71+
72+
Gets
73+
> Returns a value from an object.
74+
75+
Sets
76+
> Adds or updates an element with a specified key and a value to an object and returns an object.
7377
7478
<br>
7579

@@ -110,6 +114,18 @@ import {
110114
} from '@angular-package/error';
111115
```
112116

117+
```typescript
118+
/*
119+
* Experimental.
120+
*/
121+
import {
122+
// Class.
123+
MessageBuilder,
124+
MessageBuilderTemplate,
125+
MessageFunctionBuilder,
126+
} from '@angular-package/error';
127+
```
128+
113129
<br>
114130

115131
## `ValidationError`
@@ -219,7 +235,7 @@ The **return value** is a message of a `string` type created from the provided `
219235

220236
```typescript
221237
// Example usage.
222-
import { ValidationError } from '@angular-package/core';
238+
import { ValidationError } from '@angular-package/error';
223239

224240
const fix = 'There is no solution to the described problem.';
225241
const problem = 'The problem has no solution.';
@@ -270,7 +286,7 @@ The **return value** is an instance of [`ValidationError`](#validationerror).
270286

271287
```typescript
272288
// Example usage.
273-
import { ValidationError } from '@angular-package/core';
289+
import { ValidationError } from '@angular-package/error';
274290

275291
const fix = 'There is no solution to the described problem.';
276292
const problem = 'The problem has no solution.';
@@ -302,6 +318,108 @@ interface ErrorMessage {
302318

303319
<br>
304320

321+
## Experimental
322+
323+
![experimental]
324+
325+
### Message builder
326+
327+
#### `MessageBuilder`
328+
329+
Message builder for error message of a [`string`][js-string] type.
330+
331+
```typescript
332+
// Example usage of building a function.
333+
import { MessageBuilder } from '@angular-package/error';
334+
335+
/**
336+
* Initialize `MessageBuilder`.
337+
*/
338+
const messageFunctionBuilder = new MessageBuilder('function');
339+
340+
messageFunctionBuilder
341+
.setFunctionName('guardString')
342+
.setParam('value', 'string')
343+
.setReturn('boolean');
344+
345+
// Console returns `guardString(value: string): boolean`
346+
console.log(messageFunctionBuilder.get);
347+
```
348+
349+
```typescript
350+
// Example usage of building a method.
351+
import { MessageBuilder } from '@angular-package/error';
352+
353+
/**
354+
* Initialize `MessageBuilder`.
355+
*/
356+
const messageMethodBuilder = new MessageBuilder('method');
357+
358+
// Build the class method.
359+
messageMethodBuilder
360+
.setMethodName('setPerson')
361+
.setParam('value', 'string')
362+
.setReturn('this');
363+
364+
// Console returns `setPerson(value: string): this`
365+
console.log(messageMethodBuilder.get);
366+
```
367+
368+
```typescript
369+
// Example usage of building a class.
370+
import { MessageBuilder } from '@angular-package/error';
371+
372+
/**
373+
* Initialize `MessageBuilder`.
374+
*/
375+
const messageClassBuilder = new MessageBuilder('class');
376+
377+
// Build the class.
378+
messageClassBuilder
379+
.setClassName('Person.prototype.')
380+
.setMethodName('setPerson')
381+
.setParam('value?', 'object')
382+
.setReturn('object');
383+
384+
// Console returns `Person.prototype.setPerson(value?: object): object`
385+
console.log(messageClassBuilder.get);
386+
```
387+
388+
<br>
389+
390+
#### `MessageFunctionBuilder`
391+
392+
Message function builder for error message of a [`string`][js-string] type.
393+
394+
```typescript
395+
// Example usage of building a function.
396+
import { MessageFunctionBuilder } from '@angular-package/error';
397+
398+
/**
399+
* Initialize `MessageFunctionBuilder`.
400+
*/
401+
const messageFunctionBuilder = new MessageFunctionBuilder();
402+
403+
messageFunctionBuilder
404+
.setName('guardString')
405+
.setParam('value', 'string')
406+
.setReturn('boolean')
407+
.build();
408+
409+
// Console returns `guardString(value: string): boolean`
410+
console.log(messageFunctionBuilder.get);
411+
```
412+
413+
<br>
414+
415+
## Changelog
416+
417+
The **changelog** of this package is based on [*keep a changelog*](https://keepachangelog.com/en/1.0.0/). To read it, click on the [CHANGELOG.md](https://github.com/angular-package/error/blob/main/CHANGELOG.md) link.
418+
419+
> A changelog is a file which contains a curated, chronologically ordered list of notable changes for each version of a project. - [*keep a changelog*](https://keepachangelog.com/en/1.0.0/)
420+
421+
<br>
422+
305423
## GIT
306424

307425
### Commit
@@ -345,6 +463,7 @@ MIT © angular-package ([license][error-license])
345463
[skeleton]: https://github.com/angular-package/skeleton
346464

347465
<!-- Update status -->
466+
[experimental]: https://img.shields.io/badge/-experimental-orange
348467
[fix]: https://img.shields.io/badge/-fix-red
349468
[new]: https://img.shields.io/badge/-new-green
350469
[update]: https://img.shields.io/badge/-update-red

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-package/error",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Manages the callback function.",
55
"author": "Angular Package <[email protected]> (https://wvvw.dev)",
66
"homepage": "https://github.com/angular-package/error#readme",

src/message-builder/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { MessageBuilder } from './src/message-builder.class';
2+
export { MessageBuilderTemplate } from './src/message-builder-template.class';
3+
export { MessageFunctionBuilder } from './src/message-function-builder.class';

src/message-builder/src/message-builder-template.class.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { is } from '@angular-package/type';
33
// Interface.
44
import { MessageTemplate } from '../interface/message-template.interface';
55
/**
6-
*
6+
* MessageBuilderTemplate.
77
*/
88
export class MessageBuilderTemplate {
9+
// argument value is [value.type] type, must be [param.type] type
10+
911
#template: MessageTemplate = {
10-
class: `[class][method]([param.name][param.type])[return]`, // argument value is [value.type] type, must be [param.type] type
12+
class: `[class][method]([param.name][param.type])[return]`,
1113
function: `[function]([param.name][param.type])[return]`,
1214
method: `[method]([param.name][param.type])[return]`
1315
};

src/message-builder/src/message-builder.class.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { is, guard, ResultCallback } from '@angular-package/type';
33
// Class.
44
import { MessageBuilderTemplate } from './message-builder-template.class';
5-
6-
// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type';
7-
5+
/**
6+
* Message builder for error message of a string type.
7+
* @version Experimental This `object` is an experimental version of the message builder.
8+
*/
89
export class MessageBuilder {
910
#regExp = {
1011
class: /\[class\]/i,
@@ -64,10 +65,7 @@ export class MessageBuilder {
6465

6566
public setReturn(returns: string, callback?: ResultCallback): this {
6667
if (guard.string(returns, callback)) {
67-
this.replace(this.#regExp.return, returns);
68-
if (returns.length > 0) {
69-
this.replace(returns, `: ${returns}`);
70-
}
68+
this.replace(this.#regExp.return, returns.length > 0 ? `: ${returns}` : returns);
7169
}
7270
return this;
7371
}
@@ -82,10 +80,3 @@ export class MessageBuilder {
8280
return this;
8381
}
8482
}
85-
86-
// console.log(
87-
// new MessageBuilder('function')
88-
// .param('firstName?', 'string')
89-
// .function('isComponentLoader')
90-
// .get
91-
// );

0 commit comments

Comments
 (0)