-
Notifications
You must be signed in to change notification settings - Fork 18
/
trim.js
28 lines (25 loc) · 867 Bytes
/
trim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
@function trim
@desc Cross-browser implementation of [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim).
@param {String} str
*/
function trim(str) {
return str.toString().replace(/^\s+|\s+$/g, "");
}
/**
@function trimLeft
@desc Cross-browser implementation of [trimLeft](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimLeft).
@param {String} str
*/
function trimLeft(str) {
return str.toString().replace(/^\s+/, "");
}
/**
@function trimRight
@desc Cross-browser implementation of [trimRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight).
@param {String} str
*/
function trimRight(str) {
return str.toString().replace(/\s+$/, "");
}
export {trim, trimLeft, trimRight};