import * as _ from 'lodash' ; const DV_TX_TAG = 'dv-tx' ; const INDENT_NUM_SPACES = 2 ; /**
 * A path of components (represented by their fqtags). The first node is the
 * root.
 *
 * A component path is a DOM path that includes only components (it filters
 * HTML elements like `div`)
 */ export class ComponentPath { private readonly path : ReadonlyArray < string > ; public static fromString ( from ) { return new ComponentPath ( JSON . parse ( from ) ) ; } param nodes constructor ( nodes ) { if ( nodes . length < 1 ) { throw new Error ( `Can't create an empty component path` ) ; } this . path = nodes ; } nodes ( ) { return this . path ; } first ( ) { return this . path [ 0 ] ; } last ( ) { return < string > _ . last ( this . path ) ; } length ( ) { return this . path . length ; } tail ( ) { return new ComponentPath ( _ . tail ( this . path ) ) ; } indexOfClosestTxNode ( ) { return this . indexOf ( DV_TX_TAG ) ; } returns isDvTx ( ) { return this . indexOfClosestTxNode ( ) === this . length ( ) - 2 ; } returns serialize ( ) { return JSON . stringify ( this . path ) ; } toString ( ) { return JSON . stringify ( this . path , null , INDENT_NUM_SPACES ) ; } private indexOf ( tag ) { const indexOfTag = _ . lastIndexOf ( this . path , tag ) ; return indexOfTag === - 1 ? null : indexOfTag ; } }