Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fixes handing of multiline strings in chop function #463

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion chop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = function chop(str, step) {
if (str == null) return [];
str = String(str);
step = ~~step;
return step > 0 ? str.match(new RegExp('.{1,' + step + '}', 'g')) : [str];
return step > 0 ? str.match(new RegExp('[^]{1,' + step + '}', 'gm')) : [str];
};
1 change: 1 addition & 0 deletions tests/chop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ test('#chop', function(){
ok(chop('whitespace', 3).length === 4, 'output [whi, tes, pac, e]');
ok(chop('whitespace')[0].length === 10, 'output [whitespace]');
ok(chop(12345, 1).length === 5, 'output [1, 2, 3, 4, 5]');
ok(chop('mul\nti\nline', 5).length === 3, 'output [mul\nt, i\nlin, e]');
});