@chezearth/string
Version:
This is a temporary package until I can open a pull request on the original. string contains methods that aren't included in the vanilla JavaScript string such as escaping html, decoding html entities, stripping tags, etc.
28 lines (21 loc) • 606 B
JavaScript
function splitLeft(self, sep, maxSplit, limit) {
if (typeof maxSplit === 'undefined') {
var maxSplit = -1;
}
var splitResult = self.split(sep);
var splitPart1 = splitResult.slice(0, maxSplit);
var splitPart2 = splitResult.slice(maxSplit);
if (splitPart2.length === 0) {
splitResult = splitPart1;
} else {
splitResult = splitPart1.concat(splitPart2.join(sep));
}
if (typeof limit === 'undefined') {
return splitResult;
} else if (limit < 0) {
return splitResult.slice(limit);
} else {
return splitResult.slice(0, limit);
}
}
module.exports = splitLeft;