All files / src/accessor accessors.ts

100% Statements 3/3
100% Branches 3/3
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24          22x           938x                 28x      
/**
 * Class that have accessor behavior. An accessor is a reference
 * to a property or method that exists on a controller. To define an accessor
 * is necessary to use double brackets among it, e.g. {{Controller.property}}.
 */
export class Accessor {
	/**
	 * Checks if the value is a valid accessor definition
	 * @param value Accessor definition
	 */
	public static isAccessorDefinition(value: any) {
		return typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}');
	}
 
	/**
	 * Retrieves an array with the first position with controller name and
	 * the second position with property or method name
	 * @param value Accessor definition
	 */
	public static getAccessor(value: string) {
		return value.substring(2, value.length - 2).split('.');
	}
}