UNPKG

606 BJavaScriptView Raw
1function splitLeft(self, sep, maxSplit, limit) {
2
3 if (typeof maxSplit === 'undefined') {
4 var maxSplit = -1;
5 }
6
7 var splitResult = self.split(sep);
8 var splitPart1 = splitResult.slice(0, maxSplit);
9 var splitPart2 = splitResult.slice(maxSplit);
10
11 if (splitPart2.length === 0) {
12 splitResult = splitPart1;
13 } else {
14 splitResult = splitPart1.concat(splitPart2.join(sep));
15 }
16
17 if (typeof limit === 'undefined') {
18 return splitResult;
19 } else if (limit < 0) {
20 return splitResult.slice(limit);
21 } else {
22 return splitResult.slice(0, limit);
23 }
24
25}
26
27module.exports = splitLeft;