blob: 72adc37deb3af5ab65ccedebc3d04dc472e8dbea [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001function trim(str, pos = 'both') {
2 if (pos == 'both') {
3 return str.replace(/^\s+|\s+$/g, "");
4 } else if (pos == "left") {
5 return str.replace(/^\s*/, '');
6 } else if (pos == 'right') {
7 return str.replace(/(\s*$)/g, "");
8 } else if (pos == 'all') {
9 return str.replace(/\s+/g, "");
10 } else {
11 return str;
12 }
13}
14
15export default trim