1- ' use strict' ;
1+ " use strict" ;
22
33
44class Message {
@@ -8,13 +8,13 @@ class Message {
88 * @param { String } message
99 * @param { Number } priority
1010 */
11- constructor ( topic , title = '' , message = '' , priority = 3 ) {
11+ constructor ( topic , title = "" , message = "" , priority = 3 ) {
1212 this . topic = topic ;
1313 this . title = title ;
1414 this . message = message ;
1515 this . priority = priority ;
1616
17- this . delay = '' ;
17+ this . delay = "" ;
1818 this . tags = [ ] ;
1919 this . clickURL = null ;
2020 this . iconURL = null ;
@@ -27,7 +27,7 @@ class Message {
2727 * @param { string | null } delay
2828 */
2929 addDelay ( delay ) {
30- if ( delay !== null && delay !== '' ) this . delay = delay ;
30+ if ( delay !== null && delay !== "" ) this . delay = delay ;
3131 }
3232
3333 /**
@@ -46,7 +46,7 @@ class Message {
4646 }
4747
4848 addClickURL ( url ) {
49- if ( url === null || url === '' ) return ;
49+ if ( url === null || url === "" ) return ;
5050 if ( ! this . isValidUrl ( url ) ) return ;
5151 this . clickURL = url ;
5252 }
@@ -57,12 +57,12 @@ class Message {
5757 }
5858
5959 addAttachment ( attachFromURL , filename ) {
60- if ( attachFromURL === null || attachFromURL === '' ) return ;
60+ if ( attachFromURL === null || attachFromURL === "" ) return ;
6161 if ( ! this . isValidUrl ( attachFromURL ) ) return ;
6262
6363 this . attachment = {
6464 url : attachFromURL ,
65- filename : ( filename !== null && filename !== '' ) ? filename : attachFromURL . substring ( attachFromURL . lastIndexOf ( '/' ) + 1 )
65+ filename : ( filename !== null && filename !== "" ) ? filename : attachFromURL . substring ( attachFromURL . lastIndexOf ( "/" ) + 1 )
6666 } ;
6767 }
6868
@@ -71,24 +71,24 @@ class Message {
7171 }
7272
7373 isValidUrl ( urlString ) {
74- const urlPattern = new RegExp ( ' ^(https?:\\/\\/)?' + // validate protocol
75- ' ((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
76- ' ((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
77- ' (\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
78- ' (\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
79- ' (\\#[-a-z\\d_]*)?$' , 'i' ) ; // validate fragment locator
74+ const urlPattern = new RegExp ( " ^(https?:\\/\\/)?" + // validate protocol
75+ " ((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // validate domain name
76+ " ((\\d{1,3}\\.){3}\\d{1,3}))" + // validate OR ip (v4) address
77+ " (\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // validate port and path
78+ " (\\?[;&a-z\\d%_.~+=-]*)?" + // validate query string
79+ " (\\#[-a-z\\d_]*)?$" , "i" ) ; // validate fragment locator
8080 return ! ! urlPattern . test ( urlString ) ;
8181 }
8282
8383 toJSON ( ) {
8484 return {
8585 topic : this . topic ,
8686 priority : this . priority ,
87- ...( this . title !== null && this . title !== '' && { title : this . title } ) ,
88- ...( this . message !== null && this . message !== '' && { message : this . message } ) ,
89- ...( this . iconURL !== null && this . iconURL !== '' && { icon : this . iconURL } ) ,
90- ...( this . delay !== null && this . delay !== '' && { delay : this . delay } ) ,
91- ...( this . clickURL !== null && this . clickURL !== '' && { click : this . clickURL } ) ,
87+ ...( this . title !== null && this . title !== "" && { title : this . title } ) ,
88+ ...( this . message !== null && this . message !== "" && { message : this . message } ) ,
89+ ...( this . iconURL !== null && this . iconURL !== "" && { icon : this . iconURL } ) ,
90+ ...( this . delay !== null && this . delay !== "" && { delay : this . delay } ) ,
91+ ...( this . clickURL !== null && this . clickURL !== "" && { click : this . clickURL } ) ,
9292 ...( this . attachment !== null && { attach : this . attachment . url , filename : this . attachment . filename } ) ,
9393 ...( this . tags . length > 0 && { tags : this . tags } ) ,
9494 ...( this . actionBtns . length > 0 && { actions : this . actionBtns } ) ,
0 commit comments