@@ -93,7 +93,7 @@ export function useHelper() {
9393 return Object . keys ( diff ) . length ? diff : undefined ;
9494 }
9595
96- function slugifyDomain ( input : string ) {
96+ function slugifyDomain ( input : string , allowDots = false ) {
9797 const specialChars = {
9898 ß : 'ss' ,
9999 ä : 'ae' ,
@@ -103,19 +103,18 @@ export function useHelper() {
103103 const a = 'àáâæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôòóœøōõőṕŕřśšşșťțûùúūǘůűųẃẍÿýžźż·/_,:;' ;
104104 const b = 'aaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnooooooooprrssssttuuuuuuuuwxyyzzz------' ;
105105 const p = new RegExp ( a . split ( '' ) . join ( '|' ) , 'g' ) ;
106+
106107 return input
107108 . toString ( )
108109 . toLowerCase ( )
109- . replace ( / [ ä ö ü ß ] / gi, ( matched ) => {
110- return specialChars [ matched . toLowerCase ( ) ] ;
111- } ) // Replace german special characters
110+ . replace ( / [ ä ö ü ß ] / gi, ( matched ) => specialChars [ matched . toLowerCase ( ) ] ) // German special chars
112111 . replace ( / \s + / g, '-' ) // Replace spaces with -
113112 . replace ( p , ( c ) => b . charAt ( a . indexOf ( c ) ) ) // Replace special characters
114- . replace ( / & / g, '-' ) // Replace & with '-'
115- . replace ( / [ ^ \w \- ] + / g , '' ) // Remove all non-word characters
116- . replace ( / \- \- + / g, '-' ) // Replace multiple - with single -
117- . replace ( / ^ - + / , '' ) // Trim - from start of text
118- . replace ( / - + $ / , '' ) ; // Trim - from end of text
113+ . replace ( / & / g, '-' ) // Replace & with -
114+ . replace ( new RegExp ( allowDots ? ` [^\w\-.]+` : `[^\w\-]+` , 'g' ) , '' ) // Allow dots if requested
115+ . replace ( / \- \- + / g, '-' ) // Collapse multiple -
116+ . replace ( / ^ - + / , '' ) // Trim leading -
117+ . replace ( / - + $ / , '' ) ; // Trim trailing -
119118 }
120119
121120 function hashCode ( input : any ) {
0 commit comments