-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.js
35 lines (26 loc) · 812 Bytes
/
index.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
29
30
31
32
33
34
35
export function trimNewlines(string) {
let start = 0;
let end = string.length;
while (start < end && (string[start] === '\r' || string[start] === '\n')) {
start++;
}
while (end > start && (string[end - 1] === '\r' || string[end - 1] === '\n')) {
end--;
}
return (start > 0 || end < string.length) ? string.slice(start, end) : string;
}
export function trimNewlinesStart(string) {
const end = string.length;
let start = 0;
while (start < end && (string[start] === '\r' || string[start] === '\n')) {
start++;
}
return start > 0 ? string.slice(start, end) : string;
}
export function trimNewlinesEnd(string) {
let end = string.length;
while (end > 0 && (string[end - 1] === '\r' || string[end - 1] === '\n')) {
end--;
}
return end < string.length ? string.slice(0, end) : string;
}