guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 1 | function 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 | |||||
15 | export default trim |