/**
 * Helper class to parse ngx translate extraction pattern
 * and to decide wether a given message matches the pattern.
 */ export class NgxTranslateExtractionPattern { private _matchExplicitId : boolean ; private _descriptionPatterns : string [ ] ; param extractionPatternString throws constructor ( private extractionPatternString ) { const parts = extractionPatternString . split ( '|' ) ; this . _matchExplicitId = false ; this . _descriptionPatterns = [ ] ; for ( let i = 0 ; i < parts . length ; i ++ ) { const part = parts [ i ] ; if ( part === '@@' ) { if ( this . _matchExplicitId ) { throw new Error ( 'extraction pattern must not contain @@ twice' ) ; } this . _matchExplicitId = true ; } else { const errorString = this . checkValidDescriptionPattern ( part ) ; if ( errorString ) { throw new Error ( errorString ) ; } this . _descriptionPatterns . push ( part ) ; } } } param id return public isExplicitIdMatched ( id ) { return id && this . _matchExplicitId ; } param description return public isDescriptionMatched ( description ) { return this . _descriptionPatterns . indexOf ( description ) >= 0 ; } private checkValidDescriptionPattern ( descriptionPattern ) { if ( ! descriptionPattern ) { return 'empty value not allowed' ; } if ( /^[a-zA-Z_][a-zA-Z_-]*$/ . test ( descriptionPattern ) ) { return null ; } else { return 'description pattern must be an identifier containing only letters, digits, _ or -' ; } } }