@@ -67,29 +67,33 @@ replace.file = (filepath, options, cb) => {
67
67
} ;
68
68
69
69
replace . string = ( string , regex ) => {
70
- // save beginning and endchar
71
- // bug in here
70
+ // save the string characters
72
71
const beginChar = string . charAt ( 0 ) ;
73
72
const endChar = string . charAt ( string . length - 1 ) ;
74
73
75
-
74
+ // remove the string characters
76
75
string = string . slice ( 1 , string . length ) ;
77
76
string = string . slice ( 0 , string . length - 1 ) ;
78
77
// set whitespaces all whitespaces in string from 1 to 3
79
78
string = string . replace ( / \s + / g, ' ' ) ;
80
79
80
+
81
81
// add whitespace at the beginning and the end
82
82
string = ' ' + string + ' ' ;
83
83
84
- string = string . replace ( regex , match => {
85
- return rcs . selectorLibrary . get ( match ) ;
86
- } ) ;
87
84
88
- string = string . slice ( 1 , string . length ) ;
89
- string = string . slice ( 0 , string . length - 1 ) ;
85
+ string = string . replace ( regex , match => {
86
+ let selectorChar = match . charAt ( 0 ) === '.' || match . charAt ( 0 ) === '#' ? match . charAt ( 0 ) : '' ;
87
+ match = match . replace ( / \s + / g, '' ) ;
90
88
91
- string = string . replace ( / \s + / , ' ' ) ;
89
+ return ' ' + selectorChar + rcs . selectorLibrary . get ( match ) + ' ' ;
90
+ } ) ;
92
91
92
+ // remove whitespaces at beginning and end of string
93
+ string = string . replace ( / ^ \s + | \s + $ / g, '' ) ;
94
+ // set all whitespaces from before set 3 to one now
95
+ string = string . replace ( / \s + / g, ' ' ) ;
96
+ // add the string characters
93
97
string = beginChar + string + endChar ;
94
98
95
99
return string
0 commit comments