28 lines
		
	
	
		
			645 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			645 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| export class Element {
 | |
|   public name: string;
 | |
|   protected parent_name: string;
 | |
| 
 | |
|   public get full_name (): string {
 | |
|     if (this.parent_name)
 | |
|       return `${this.parent_name}_${this.name}`;
 | |
|     return this.name;
 | |
|   }
 | |
| 
 | |
|   public get parent (): string {
 | |
|     return this.parent_name;
 | |
|   }
 | |
| 
 | |
|   public constructor (name: string, parent = '') {
 | |
|     const regex = /^[a-z_][a-z_0-9]+$/iu;
 | |
|     if (!regex.test (name))
 | |
|       throw new Error ('invalid name specified');
 | |
|     this.name = name;
 | |
|     this.parent_name = parent;
 | |
|   }
 | |
| 
 | |
|   // eslint-disable-next-line @typescript-eslint/naming-convention
 | |
|   public toString (): string {
 | |
|     return this.full_name;
 | |
|   }
 | |
| }
 |