From 1da7144001c2b1b535b1d3a60a7ab12696bc9171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=BC?= Date: Wed, 17 Feb 2016 21:17:38 +0700 Subject: [PATCH] Update index.js --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e9dc82c..cfbe20c 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,17 @@ function split (matcher, mapper, options) { } function next (stream, buffer) { - var pieces = ((soFar != null ? soFar : '') + buffer).split(matcher) + var bufs = ((soFar != null ? soFar : '') + buffer); + var pieces = []; + + if(options && 'function' === typeof options.split) { + pieces = options.split(bufs, matcher); + } else if(!isNaN(parseFloat(matcher)) && isFinite(matcher)) { + pieces = bufs.match(new RegExp(".{1,"+matcher+"}", "g")); + } else { + pieces = bufs.split(matcher); + } + soFar = pieces.pop() if (maxLength && soFar.length > maxLength)