Skip to content

Commit

Permalink
cli: modify _split behaviour
Browse files Browse the repository at this point in the history
Modify `_split` to push to array first substring of `str` which
is not `splitter`, if limit is present and `leaveEmpty` set to false.

PR-URL: metarhia/jstp#107
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
  • Loading branch information
belochub authored and aqrln committed May 5, 2017
1 parent d6dbf97 commit f1a24ca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ function _split(str, separator, limit, leaveEmpty) {
const result = [];
let start = 0;

// eslint-disable-next-line no-unmodified-loop-condition
for (let i = 0; !limit || i < limit; i++) {
const split = str.indexOf(separator, start);
if (split === -1) break;
if (!shouldTrim(start, split)) {
result.push(str.slice(start, split));
} else {
limit--;
} else {
i--;
}
start = split + separator.length;
}
Expand Down

0 comments on commit f1a24ca

Please sign in to comment.