graphviz-builder/lib/Element.ts

29 lines
646 B
TypeScript
Raw Normal View History

2020-04-24 12:02:32 +02:00
export class Element {
public name: string;
2020-04-24 14:05:58 +02:00
protected parent_name: string;
2020-04-24 12:02:32 +02:00
public get full_name (): string {
2020-04-24 14:05:58 +02:00
if (this.parent_name)
return `${this.parent_name}_${this.name}`;
2020-04-24 12:21:26 +02:00
return this.name;
2020-04-24 12:02:32 +02:00
}
2020-04-24 14:05:58 +02:00
public get parent (): string {
return this.parent_name;
}
2020-04-24 12:02:32 +02:00
public constructor (name: string, parent = '') {
2020-04-27 18:57:23 +02:00
const regex = /^[a-z_][a-z_0-9]+$/iu;
2020-04-28 11:26:21 +02:00
2020-04-27 18:57:23 +02:00
if (!regex.test (name))
throw new Error ('invalid name specified');
2020-04-24 12:02:32 +02:00
this.name = name;
2020-04-24 14:05:58 +02:00
this.parent_name = parent;
2020-04-24 12:02:32 +02:00
}
// eslint-disable-next-line @typescript-eslint/naming-convention
public toString (): string {
return this.full_name;
}
}