Skip to content

Commit d9ecdc7

Browse files
chore: change the folder from lib to src
1 parent f68b3cf commit d9ecdc7

8 files changed

+285
-222
lines changed

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

Lines changed: 0 additions & 83 deletions
This file was deleted.

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

Lines changed: 0 additions & 63 deletions
This file was deleted.

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @angular-package/type
2+
import { is } from '@angular-package/type';
3+
// Interface.
4+
import { MessageTemplate } from '../interface/message-template.interface';
5+
/**
6+
*
7+
*/
8+
export class MessageBuilderTemplate {
9+
#template: MessageTemplate = {
10+
class: `[class][method]([param.name][param.type])[return]`, // argument value is [value.type] type, must be [param.type] type
11+
function: `[function]([param.name][param.type])[return]`,
12+
method: `[method]([param.name][param.type])[return]`
13+
};
14+
15+
#type!: keyof MessageTemplate;
16+
17+
/**
18+
* Gets privately stored template of the provided in the constructor type.
19+
*/
20+
get get(): string {
21+
return this.#template[this.#type];
22+
}
23+
24+
constructor(type: 'class' | 'function' | 'method') {
25+
if (is.string(type)) {
26+
this.#type = type;
27+
}
28+
}
29+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// @angular-package/type
2+
import { is, guard, ResultCallback } from '@angular-package/type';
3+
// Class.
4+
import { MessageBuilderTemplate } from './message-builder-template.class';
5+
6+
// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type';
7+
8+
export class MessageBuilder {
9+
#regExp = {
10+
class: /\[class\]/i,
11+
function: /\[function\]/i,
12+
method: /\[method\]/i,
13+
param: {
14+
name: /\[param.name\]/i,
15+
type: /\[param.type\]/i,
16+
},
17+
return: /\[return\]/i
18+
};
19+
20+
#template: string;
21+
22+
get get(): string {
23+
return this.#template;
24+
}
25+
26+
constructor(template: 'class' | 'function' | 'method') {
27+
this.#template = new MessageBuilderTemplate(template).get;
28+
}
29+
30+
public setClassName(name: string, callback?: ResultCallback): this {
31+
if (guard.string(name, callback)) {
32+
this.replace(this.#regExp.class, name);
33+
}
34+
return this;
35+
}
36+
37+
public setFunctionName(name: string, callback?: ResultCallback): this {
38+
if (guard.string(name, callback)) {
39+
this.replace(this.#regExp.function, name);
40+
}
41+
return this;
42+
}
43+
44+
public setMethodName(name: string, callback?: ResultCallback): this {
45+
if (guard.string(name, callback)) {
46+
this.replace(this.#regExp.method, name);
47+
}
48+
return this;
49+
}
50+
51+
public setParam(name: string, type: string = ''): this {
52+
if (guard.string(name)) {
53+
const param = `${name}${type}`;
54+
this
55+
.replace(this.#regExp.param.name, name)
56+
.replace(this.#regExp.param.type, type);
57+
58+
if (type.length > 0) {
59+
this.replace(type, `: ${type}`);
60+
}
61+
}
62+
return this;
63+
}
64+
65+
public setReturn(returns: string, callback?: ResultCallback): this {
66+
if (guard.string(returns, callback)) {
67+
this.replace(this.#regExp.return, returns);
68+
if (returns.length > 0) {
69+
this.replace(returns, `: ${returns}`);
70+
}
71+
}
72+
return this;
73+
}
74+
75+
private replace(searchValue: string | RegExp, replaceValue: string): this {
76+
if (is.defined(searchValue)) {
77+
this.#template = this.#template.replace(
78+
searchValue,
79+
is.string(replaceValue) ? replaceValue : ''
80+
);
81+
}
82+
return this;
83+
}
84+
}
85+
86+
// console.log(
87+
// new MessageBuilder('function')
88+
// .param('firstName?', 'string')
89+
// .function('isComponentLoader')
90+
// .get
91+
// );

0 commit comments

Comments
 (0)