graphviz-builder/lib/Element.ts

44 lines
1003 B
TypeScript

export class Element {
private _name = '';
protected parent_name: string;
public get full_name (): string {
if (this.parent_name)
return `${this.parent_name}_${this.name}`;
return this.name;
}
public get name (): string {
return this._name;
}
public set name (val: string) {
const new_name = val.replace (/[^a-z0-9]/giu, '')
.replace (/^[0-9]+/iu, '');
if (new_name === '')
throw new Error ('invalid name specified');
this._name = new_name;
}
public get parent (): string {
return this.parent_name;
}
public constructor (name: string, parent = '') {
<<<<<<< HEAD
=======
const regex = /^[a-z_][a-z_0-9]+$/iu;
if (!regex.test (name))
throw new Error ('invalid name specified');
>>>>>>> f553396eee29e1e0820624345e5d23dc3471a4a4
this.name = name;
this.parent_name = parent;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
public toString (): string {
return this.full_name;
}
}