Skip to content

Commit

Permalink
Merge pull request #4 from angular-package/1.0.x
Browse files Browse the repository at this point in the history
1.0.3
  • Loading branch information
angularpackage authored Aug 6, 2021
2 parents 3c9fbd3 + 99e9b9a commit 955fee6
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 130 deletions.
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.3] - 2021-08-06

### 1.0.3 Added

- [`5752d9e`][5752d9e]
Tests for the `MessageFunctionBuilder`.
- [`488270d`][488270d]
Tests for the `MessageBuilder`.

[5752d9e]: https://github.com/angular-package/error/commit/5752d9e7b3631dcca0d6945e25a92d1fdfb9eee3
[488270d]: https://github.com/angular-package/error/commit/488270d4c88f8575c8289022559e4f8ce1de828b

### 1.0.3 Changed

- [`5bd6a2b`][5bd6a2b]
jsdoc description of the `MessageBuilder`.
- [`1dffd31`][1dffd31]
Updated `README.md`.

[5bd6a2b]: https://github.com/angular-package/error/commit/5bd6a2bf8dc98db6666f8d84bb28771357f17105
[1dffd31]: https://github.com/angular-package/error/commit/1dffd31ab4db736a4f583ac4d3c1994c92da92ea

### 1.0.3 Fixed

- [`5427c65`][5427c65]
Added message builder to api.

[5427c65]: https://github.com/angular-package/error/commit/5427c6585ddebe01bc6e3733425e07b924ec0ca6

----

## [1.0.2] - 2021-08-04

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

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

## [1.0.1] - 2021-08-04

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

[77f326a]: https://github.com/angular-package/error/commit/ab8729f3627d63729326ddfd354296c2ae800c33
[ab8729f]: https://github.com/angular-package/error/commit/ab8729f3627d63729326ddfd354296c2ae800c33
135 changes: 127 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Manages an [`Error`][js-error].
* [Api](#api)
* [`ValidationError`](#validationerror)
* [Interface](#interface)
* [Experimental](#experimental)
* [Changelog](#changelog)
* [Git](#git)
* [Commit](#commit)
* [Versioning](#versioning)
Expand All @@ -63,13 +65,15 @@ Type guard (constrain)
Guards
> It's a **combination** of both above, **constrains** the type of the parameter in the **code editor**, and checks its provided argument.
Sets
> Sets the existing given value in the `object`.
Defines
> Returns defined value from the method of the `object`.
> Defines the new value in the `object`.
> Both above at the same time.
> Returns defined value from a method of an object.
> Defines new value in an object and returns a defined value.
Gets
> Returns a value from an object.
Sets
> Adds or updates an element with a specified key and a value to an object and returns an object.
<br>

Expand Down Expand Up @@ -110,6 +114,18 @@ import {
} from '@angular-package/error';
```

```typescript
/*
* Experimental.
*/
import {
// Class.
MessageBuilder,
MessageBuilderTemplate,
MessageFunctionBuilder,
} from '@angular-package/error';
```

<br>

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

```typescript
// Example usage.
import { ValidationError } from '@angular-package/core';
import { ValidationError } from '@angular-package/error';

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

```typescript
// Example usage.
import { ValidationError } from '@angular-package/core';
import { ValidationError } from '@angular-package/error';

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

<br>

## Experimental

![experimental]

### Message builder

#### `MessageBuilder`

Message builder for error message of a [`string`][js-string] type.

```typescript
// Example usage of building a function.
import { MessageBuilder } from '@angular-package/error';

/**
* Initialize `MessageBuilder`.
*/
const messageFunctionBuilder = new MessageBuilder('function');

messageFunctionBuilder
.setFunctionName('guardString')
.setParam('value', 'string')
.setReturn('boolean');

// Console returns `guardString(value: string): boolean`
console.log(messageFunctionBuilder.get);
```

```typescript
// Example usage of building a method.
import { MessageBuilder } from '@angular-package/error';

/**
* Initialize `MessageBuilder`.
*/
const messageMethodBuilder = new MessageBuilder('method');

// Build the class method.
messageMethodBuilder
.setMethodName('setPerson')
.setParam('value', 'string')
.setReturn('this');

// Console returns `setPerson(value: string): this`
console.log(messageMethodBuilder.get);
```

```typescript
// Example usage of building a class.
import { MessageBuilder } from '@angular-package/error';

/**
* Initialize `MessageBuilder`.
*/
const messageClassBuilder = new MessageBuilder('class');

// Build the class.
messageClassBuilder
.setClassName('Person.prototype.')
.setMethodName('setPerson')
.setParam('value?', 'object')
.setReturn('object');

// Console returns `Person.prototype.setPerson(value?: object): object`
console.log(messageClassBuilder.get);
```

<br>

#### `MessageFunctionBuilder`

Message function builder for error message of a [`string`][js-string] type.

```typescript
// Example usage of building a function.
import { MessageFunctionBuilder } from '@angular-package/error';

/**
* Initialize `MessageFunctionBuilder`.
*/
const messageFunctionBuilder = new MessageFunctionBuilder();

messageFunctionBuilder
.setName('guardString')
.setParam('value', 'string')
.setReturn('boolean')
.build();

// Console returns `guardString(value: string): boolean`
console.log(messageFunctionBuilder.get);
```

<br>

## Changelog

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.

> 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/)
<br>

## GIT

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

<!-- Update status -->
[experimental]: https://img.shields.io/badge/-experimental-orange
[fix]: https://img.shields.io/badge/-fix-red
[new]: https://img.shields.io/badge/-new-green
[update]: https://img.shields.io/badge/-update-red
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular-package/error",
"version": "1.0.2",
"version": "1.0.3",
"description": "Manages the callback function.",
"author": "Angular Package <angular-package@wvvw.dev> (https://wvvw.dev)",
"homepage": "https://github.com/angular-package/error#readme",
Expand Down
3 changes: 3 additions & 0 deletions src/message-builder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MessageBuilder } from './src/message-builder.class';
export { MessageBuilderTemplate } from './src/message-builder-template.class';
export { MessageFunctionBuilder } from './src/message-function-builder.class';
6 changes: 4 additions & 2 deletions src/message-builder/src/message-builder-template.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { is } from '@angular-package/type';
// Interface.
import { MessageTemplate } from '../interface/message-template.interface';
/**
*
* MessageBuilderTemplate.
*/
export class MessageBuilderTemplate {
// argument value is [value.type] type, must be [param.type] type

#template: MessageTemplate = {
class: `[class][method]([param.name][param.type])[return]`, // argument value is [value.type] type, must be [param.type] type
class: `[class][method]([param.name][param.type])[return]`,
function: `[function]([param.name][param.type])[return]`,
method: `[method]([param.name][param.type])[return]`
};
Expand Down
19 changes: 5 additions & 14 deletions src/message-builder/src/message-builder.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import { is, guard, ResultCallback } from '@angular-package/type';
// Class.
import { MessageBuilderTemplate } from './message-builder-template.class';

// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type';

/**
* Message builder for error message of a string type.
* @version Experimental This `object` is an experimental version of the message builder.
*/
export class MessageBuilder {
#regExp = {
class: /\[class\]/i,
Expand Down Expand Up @@ -64,10 +65,7 @@ export class MessageBuilder {

public setReturn(returns: string, callback?: ResultCallback): this {
if (guard.string(returns, callback)) {
this.replace(this.#regExp.return, returns);
if (returns.length > 0) {
this.replace(returns, `: ${returns}`);
}
this.replace(this.#regExp.return, returns.length > 0 ? `: ${returns}` : returns);
}
return this;
}
Expand All @@ -82,10 +80,3 @@ export class MessageBuilder {
return this;
}
}

// console.log(
// new MessageBuilder('function')
// .param('firstName?', 'string')
// .function('isComponentLoader')
// .get
// );
Loading

0 comments on commit 955fee6

Please sign in to comment.