import { Injectable } from '@angular/core' ; import { RegexService } from './regex.service' ; /**
 * Parse hashtags from a string.
 */ @ Injectable ( { providedIn : 'root' } ) export class HashtagsFromStringService { constructor ( private regex ) { } param { string } value returns { string [ ] } public parseHashtagsFromString ( value ) { if ( ! value ) { return [ ] ; } value = this . stripUrls ( value ) ; return ( value . match ( this . regex . getRegex ( 'hash' ) ) ?. map ( tag => { tag = tag . trim ( ) ; return tag . charAt ( 0 ) === '#' ? tag . substr ( 1 ) : tag ; } ) ?? [ ] ) ; } param { string } value returns { string [ ] } public parseCryptoTagsFromString ( value ) { if ( ! value ) { return [ ] ; } value = this . stripUrls ( value ) ; return ( value . match ( this . regex . getRegex ( 'crypto' ) ) ?. map ( tag => { tag = tag . trim ( ) ; return tag . charAt ( 0 ) === '#' ? tag . substr ( 1 ) : tag ; } ) ?? [ ] ) ; } param value returns { string } private stripUrls ( value ) { return value . replace ( this . regex . getRegex ( 'url' ) , '' ) ; } }