diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb22391..a5e49bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
@@ -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
@@ -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
diff --git a/README.md b/README.md
index aa83fbf..802223b 100644
--- a/README.md
+++ b/README.md
@@ -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)
@@ -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.
@@ -110,6 +114,18 @@ import {
} from '@angular-package/error';
```
+```typescript
+/*
+ * Experimental.
+ */
+import {
+ // Class.
+ MessageBuilder,
+ MessageBuilderTemplate,
+ MessageFunctionBuilder,
+} from '@angular-package/error';
+```
+
## `ValidationError`
@@ -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.';
@@ -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.';
@@ -302,6 +318,108 @@ interface ErrorMessage {
+## 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);
+```
+
+
+
+#### `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);
+```
+
+
+
+## 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/)
+
+
+
## GIT
### Commit
@@ -345,6 +463,7 @@ MIT © angular-package ([license][error-license])
[skeleton]: https://github.com/angular-package/skeleton
+[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
diff --git a/package-lock.json b/package-lock.json
index a257880..c7d3964 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "error",
- "version": "1.0.2",
+ "version": "1.0.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
@@ -17,7 +17,7 @@
"@angular/common": "^12.1.1",
"@angular/core": "^12.1.1"
},
- "version": "1.0.2"
+ "version": "1.0.3"
},
"node_modules/@angular-package/testing": {
"version": "1.1.0",
diff --git a/package.json b/package.json
index da91d8f..2f4661c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@angular-package/error",
- "version": "1.0.2",
+ "version": "1.0.3",
"description": "Manages the callback function.",
"author": "Angular Package (https://wvvw.dev)",
"homepage": "https://github.com/angular-package/error#readme",
diff --git a/src/message-builder/index.ts b/src/message-builder/index.ts
index e69de29..6a9974f 100644
--- a/src/message-builder/index.ts
+++ b/src/message-builder/index.ts
@@ -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';
diff --git a/src/message-builder/src/message-builder-template.class.ts b/src/message-builder/src/message-builder-template.class.ts
index 64022cb..3ea7a3d 100644
--- a/src/message-builder/src/message-builder-template.class.ts
+++ b/src/message-builder/src/message-builder-template.class.ts
@@ -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]`
};
diff --git a/src/message-builder/src/message-builder.class.ts b/src/message-builder/src/message-builder.class.ts
index 42d9a5d..0facfdb 100644
--- a/src/message-builder/src/message-builder.class.ts
+++ b/src/message-builder/src/message-builder.class.ts
@@ -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,
@@ -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;
}
@@ -82,10 +80,3 @@ export class MessageBuilder {
return this;
}
}
-
-// console.log(
-// new MessageBuilder('function')
-// .param('firstName?', 'string')
-// .function('isComponentLoader')
-// .get
-// );
diff --git a/src/message-builder/src/message-class-builder.class.ts b/src/message-builder/src/message-class-builder.class.ts
deleted file mode 100644
index dcde20f..0000000
--- a/src/message-builder/src/message-class-builder.class.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { is, guard } from '@angular-package/type';
-import { MessageBuilderTemplate } from './message-builder-template.class';
-import { MessageBuilder } from './message-builder.class';
-
-// export class MessageClassBuilder extends MessageBuilder {
-// private class$$: string;
-// private param$$: {
-// name?: string;
-// type?: string;
-// } = {};
-// private method$$: string;
-
-// constructor() {
-// super('class');
-// }
-
-// /**
-// * Build class message.
-// */
-// public build(): this {
-// // class.
-// // this.replace('class', this.class$$);
-// // // method.
-// // this.replace('method', is.string(this.method$$) && is.string(this.class$$) ? `.${this.method$$}` : this.method$$);
-// // // param.
-// // const param = `${this.param$$.name}${this.param$$.type}`;
-// // this
-// // .replace('param.type', this.param$$.type)
-// // .replace('param.name', this.param$$.name)
-// // .replace(param, `(${param})`)
-// // .replace(this.param$$.type, `: ${this.param$$.type}`);
-// return this;
-// }
-
-// /**
-// * Set class name to build message.
-// * @param name Class name.
-// * @returns this.
-// */
-// public class(name: string): this {
-// if (guard.is.string(name)) {
-// this.class$$ = name;
-// }
-// return this;
-// }
-
-// /**
-// * Set class method name to build message.
-// * @param name Class method name.
-// * @returns this.
-// */
-// public method(name: string): this {
-// if (guard.is.string(name)) {
-// this.method$$ = name;
-// }
-// return this;
-// }
-
-// /**
-// * Set method param name with type to build message.
-// * @param name Method param name.
-// * @param type Method param type.
-// * @returns this.
-// */
-// public param(name: string, type?: string): this {
-// if (guard.is.string(name)) {
-// this.param$$.name = name;
-// }
-// if (guard.is.string(type)) {
-// this.param$$.type = type;
-// }
-// return this;
-// }
-// }
-
-// const messageBuilderClass: MessageClassBuilder = new MessageClassBuilder()
-// .class('NameProperty')
-// .method('set')
-// .param('name', 'Array')
-// .build();
-
-// console.log(`messageBuilderClass`, messageBuilderClass.get);
-
diff --git a/src/message-builder/src/message-function-builder.class.ts b/src/message-builder/src/message-function-builder.class.ts
index e0d2451..2afad1a 100644
--- a/src/message-builder/src/message-function-builder.class.ts
+++ b/src/message-builder/src/message-function-builder.class.ts
@@ -4,7 +4,8 @@ import { MessageBuilder } from './message-builder.class';
// Interface.
import { Parameter } from '../interface/parameter.interface';
/**
- *
+ * Message function builder for error message of a string type.
+ * @version Experimental This `object` is an experimental version of the message function builder that is using `MessageBuilder`.
*/
export class MessageFunctionBuilder {
#messageBuilder: MessageBuilder;
@@ -15,16 +16,22 @@ export class MessageFunctionBuilder {
};
#return = '';
+ /**
+ * Gets the build function of a `string` type.
+ */
get get(): string {
return this.#messageBuilder.get;
}
+ /**
+ * Creates an instance of `MessageFunctionBuilder`.
+ */
constructor() {
this.#messageBuilder = new MessageBuilder('function');
}
/**
- * Build function message.
+ * Builds string-type function from the privately stored `name`, `param`, and `return`.
*/
public build(): this {
this
@@ -36,24 +43,26 @@ export class MessageFunctionBuilder {
}
/**
- * Sets the function name to build message.
+ * Sets the function name to build function of a `string` type.
* @param name Function name of a `string` type.
- * @param callback
- * @returns The return value is an instance of `MessageBuilderFunction`.
+ * @param callback An optional callback function of `ResultCallback` to handle the result of the check whether the provided `name`
+ * is a `string` type.
+ * @returns The return value is an instance of `MessageFunctionBuilder`.
*/
public setName(name: string, callback?: ResultCallback): this {
if (guard.string(name, callback)) {
this.#name = name;
}
- // this.setFunction(name);
return this;
}
/**
- * Set method param name with type to build message.
- * @param name Method param name.
- * @param type Method param type.
- * @returns this.
+ * Sets param name with an optional type of `function` to build function of a `string` type.
+ * @param name Parameter name of a function guarded by string.
+ * @param type An optional parameter type of function guarded by string.
+ * @param callback An optional callback function of `ResultCallback` to handle the result of the check whether the provided `name`
+ * is a `string` type.
+ * @returns The return value is an instance of `MessageFunctionBuilder`.
*/
public setParam(name: string, type?: string, callback?: ResultCallback): this {
if (guard.string(name, callback)) {
@@ -65,6 +74,13 @@ export class MessageFunctionBuilder {
return this;
}
+ /**
+ * Sets return type to build the function of a `string` type.
+ * @param returns A return type of `function` guarded by `string`.
+ * @param callback An optional callback function of `ResultCallback` to handle the result of the check whether the provided `returns`
+ * is a `string` type.
+ * @returns The return value is an instance of `MessageFunctionBuilder`.
+ */
public setReturn(returns: string, callback?: ResultCallback): this {
if (guard.string(returns, callback)) {
this.#return = returns;
@@ -72,11 +88,3 @@ export class MessageFunctionBuilder {
return this;
}
}
-
-const messageBuilderFunction = new MessageFunctionBuilder();
-messageBuilderFunction
- .setName('isString')
- .setParam('one', 'string')
- .setReturn('this')
- .build();
-console.log(messageBuilderFunction.get);
diff --git a/src/message-builder/test/message-builder.spec.ts b/src/message-builder/test/message-builder.spec.ts
new file mode 100644
index 0000000..a643d7d
--- /dev/null
+++ b/src/message-builder/test/message-builder.spec.ts
@@ -0,0 +1,68 @@
+// External class.
+import { Testing, TestingToBeMatchers } from '@angular-package/testing';
+// Class.
+import { MessageBuilder } from '../src/message-builder.class';
+/**
+ * Initialize `Testing`.
+ */
+const testing = new Testing(true, true);
+const toBe = new TestingToBeMatchers();
+/**
+ * Tests.
+ */
+testing.describe(MessageBuilder.name, () => {
+ let messageClassBuilder = new MessageBuilder('class');
+ let messageFunctionBuilder = new MessageBuilder('function');
+ let messageMethodBuilder = new MessageBuilder('method');
+
+ beforeEach(() => (messageClassBuilder = new MessageBuilder('class')));
+ beforeEach(() => (messageFunctionBuilder = new MessageBuilder('function')));
+ beforeEach(() => (messageMethodBuilder = new MessageBuilder('method')));
+
+ // Basic testing.
+ testing
+ .it(`defined`, () =>
+ toBe
+ .defined(MessageBuilder)
+ .defined(messageClassBuilder)
+ .defined(messageFunctionBuilder)
+ .defined(messageMethodBuilder)
+ .instance(messageClassBuilder, MessageBuilder)
+ .instance(messageFunctionBuilder, MessageBuilder)
+ .instance(messageMethodBuilder, MessageBuilder)
+ )
+ .toBeClass(MessageBuilder);
+
+ testing.it(`build function`, () => {
+ messageFunctionBuilder
+ .setFunctionName('guardString')
+ .setParam('value', 'string')
+ .setReturn('boolean');
+
+ toBe.string(messageFunctionBuilder.get);
+ console.log(messageFunctionBuilder.get);
+ expect(messageFunctionBuilder.get).toEqual('guardString(value: string): boolean');
+ });
+
+ testing.it(`build class`, () => {
+ messageClassBuilder
+ .setClassName('Person.prototype.')
+ .setMethodName('setPerson')
+ .setParam('value?', 'object')
+ .setReturn('object');
+
+ toBe.string(messageClassBuilder.get);
+ expect(messageClassBuilder.get).toEqual('Person.prototype.setPerson(value?: object): object');
+ });
+
+ testing.it(`build method`, () => {
+ messageMethodBuilder
+ .setMethodName('setPerson')
+ .setParam('value', 'string')
+ .setReturn('this');
+
+ console.log(messageMethodBuilder.get);
+ toBe.string(messageMethodBuilder.get);
+ expect(messageMethodBuilder.get).toEqual('setPerson(value: string): this');
+ });
+});
diff --git a/src/message-builder/test/message-function-builder.spec.ts b/src/message-builder/test/message-function-builder.spec.ts
new file mode 100644
index 0000000..74c2222
--- /dev/null
+++ b/src/message-builder/test/message-function-builder.spec.ts
@@ -0,0 +1,38 @@
+// External class.
+import { Testing, TestingToBeMatchers } from '@angular-package/testing';
+// Class.
+import { MessageFunctionBuilder } from '../src/message-function-builder.class';
+/**
+ * Initialize `Testing`.
+ */
+const testing = new Testing(true, true);
+const toBe = new TestingToBeMatchers();
+/**
+ * Tests.
+ */
+testing.describe(MessageFunctionBuilder.name, () => {
+ let messageFunctionBuilder = new MessageFunctionBuilder();
+
+ beforeEach(() => (messageFunctionBuilder = new MessageFunctionBuilder()));
+
+ // Basic testing.
+ testing
+ .it(`defined`, () =>
+ toBe
+ .defined(messageFunctionBuilder)
+ .defined(messageFunctionBuilder)
+ .instance(messageFunctionBuilder, MessageFunctionBuilder)
+ )
+ .toBeClass(MessageFunctionBuilder);
+
+ testing.it(`build function`, () => {
+ messageFunctionBuilder
+ .setName('guardString')
+ .setParam('value', 'string')
+ .setReturn('boolean')
+ .build();
+
+ toBe.string(messageFunctionBuilder.get);
+ expect(messageFunctionBuilder.get).toEqual('guardString(value: string): boolean');
+ });
+});
diff --git a/src/public-api.ts b/src/public-api.ts
index b43a6fd..83f99bb 100644
--- a/src/public-api.ts
+++ b/src/public-api.ts
@@ -5,3 +5,13 @@
export { ValidationError } from './lib/validation-error.class';
// Interface.
export { ErrorMessage } from './interface/error-message.interface';
+
+/*
+ * Experimental
+ */
+export {
+ // Class.
+ MessageBuilder,
+ MessageFunctionBuilder,
+ MessageBuilderTemplate,
+} from './message-builder/';