From 4a01081c3f154813a70844129eb4234846439430 Mon Sep 17 00:00:00 2001 From: evgenyzinoviev Date: Fri, 27 Nov 2015 01:04:02 +0100 Subject: [PATCH 1/2] Fix chop for multiline strings --- chop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chop.js b/chop.js index 73e17eb7..e4782c8a 100644 --- a/chop.js +++ b/chop.js @@ -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]; }; From e453be9113056de4db0c90c2bf77b196d457f69c Mon Sep 17 00:00:00 2001 From: evgenyzinoviev Date: Fri, 27 Nov 2015 01:05:24 +0100 Subject: [PATCH 2/2] Added a test for chop for multiline strings --- tests/chop.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/chop.js b/tests/chop.js index 8106337c..32773663 100644 --- a/tests/chop.js +++ b/tests/chop.js @@ -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]'); });