export default class RedditDiscussion { private name : string ; private altNames : string [ ] ; private episode : string ; private endpoint : string = "https://www.reddit.com/r/anime/search?q=" ; public constructor ( name , episode = "" , altNames = [ ] ) { this . name = name ; this . altNames = altNames ; this . episode = episode ; } returns { string } public url ( ) { if ( this . episode ) { return this . urlWithEp ( ) ; } else { return this . urlWithoutEp ( ) ; } } private cleanTitle ( ) { return this . name . replace ( /\(DUB\)|\(SUB\)|\(TV\)/gi , "" ) . trim ( ) ; } private addAltNames ( ) { let altNames = "" ; if ( this . altNames . length > 0 ) { this . altNames . forEach ( name => { altNames += ` OR title:"${ name }` ; } ) ; } return altNames ; } private urlWithEp ( ) { let titleText = `title:"${ this . cleanTitle ( ) } - Episode ${ this . episode }"` ; let params = `subreddit:anime self:yes title:"Spoiler" title:"Discussion"` ; return encodeURI ( this . endpoint + titleText + this . addAltNames ( ) + " " + params + "&sort=new" ) ; } private urlWithoutEp ( ) { let titleText = `title:"${ this . cleanTitle ( ) }"` ; let params = `subreddit:anime self:yes title:"Spoiler" title:"Discussion"` ; return encodeURI ( this . endpoint + titleText + this . addAltNames ( ) + " " + params + "&sort=new" ) ; } }