Skip to content

Commit adb9146

Browse files
committed
fixed replace bug
1 parent dee5dbc commit adb9146

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/utils/options/replace.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,33 @@ replace.file = (filepath, options, cb) => {
6767
};
6868

6969
replace.string = (string, regex) => {
70-
// save beginning and endchar
71-
// bug in here
70+
// save the string characters
7271
const beginChar = string.charAt(0);
7372
const endChar = string.charAt(string.length - 1);
7473

75-
74+
// remove the string characters
7675
string = string.slice(1, string.length);
7776
string = string.slice(0, string.length - 1);
7877
// set whitespaces all whitespaces in string from 1 to 3
7978
string = string.replace(/\s+/g, ' ');
8079

80+
8181
// add whitespace at the beginning and the end
8282
string = ' ' + string + ' ';
8383

84-
string = string.replace(regex, match => {
85-
return rcs.selectorLibrary.get(match);
86-
});
8784

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, '');
9088

91-
string = string.replace(/\s+/, ' ');
89+
return ' ' + selectorChar + rcs.selectorLibrary.get(match) + ' ';
90+
});
9291

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
9397
string = beginChar + string + endChar;
9498

9599
return string

0 commit comments

Comments
 (0)