diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
commit | 0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch) | |
tree | f9864d4a4148621378958794cbbfdc2393733283 /node_modules/split-string/index.js | |
parent | 6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff) |
upgrade dependencies
Diffstat (limited to 'node_modules/split-string/index.js')
-rw-r--r-- | node_modules/split-string/index.js | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/node_modules/split-string/index.js b/node_modules/split-string/index.js index 9c86d37c1..7bc0ea91b 100644 --- a/node_modules/split-string/index.js +++ b/node_modules/split-string/index.js @@ -1,7 +1,7 @@ /*! * split-string <https://github.com/jonschlinkert/split-string> * - * Copyright (c) 2015, 2017, Jon Schlinkert. + * Copyright (c) 2015-2017, Jon Schlinkert. * Released under the MIT License. */ @@ -26,13 +26,33 @@ module.exports = function(str, options, fn) { var opts = extend({sep: '.'}, options); var quotes = opts.quotes || ['"', "'", '`']; + var brackets; + + if (opts.brackets === true) { + brackets = { + '<': '>', + '(': ')', + '[': ']', + '{': '}' + }; + } else if (opts.brackets) { + brackets = opts.brackets; + } + var tokens = []; + var stack = []; var arr = ['']; var sep = opts.sep; var len = str.length; var idx = -1; var closeIdx; + function expected() { + if (brackets && stack.length) { + return brackets[stack[stack.length - 1]]; + } + } + while (++idx < len) { var ch = str[idx]; var next = str[idx + 1]; @@ -50,8 +70,53 @@ module.exports = function(str, options, fn) { continue; } + if (brackets && brackets[ch]) { + stack.push(ch); + var e = expected(); + var i = idx + 1; + + if (str.indexOf(e, i + 1) !== -1) { + while (stack.length && i < len) { + var s = str[++i]; + if (s === '\\') { + s++; + continue; + } + + if (quotes.indexOf(s) !== -1) { + i = getClosingQuote(str, s, i + 1); + continue; + } + + e = expected(); + if (stack.length && str.indexOf(e, i + 1) === -1) { + break; + } + + if (brackets[s]) { + stack.push(s); + continue; + } + + if (e === s) { + stack.pop(); + } + } + } + + closeIdx = i; + if (closeIdx === -1) { + arr[arr.length - 1] += ch; + continue; + } + + ch = str.slice(idx, closeIdx + 1); + tok.val = ch; + tok.idx = idx = closeIdx; + } + if (quotes.indexOf(ch) !== -1) { - closeIdx = getClose(str, ch, idx + 1); + closeIdx = getClosingQuote(str, ch, idx + 1); if (closeIdx === -1) { arr[arr.length - 1] += ch; continue; @@ -84,10 +149,10 @@ module.exports = function(str, options, fn) { return arr; }; -function getClose(str, ch, i) { +function getClosingQuote(str, ch, i, brackets) { var idx = str.indexOf(ch, i); if (str.charAt(idx - 1) === '\\') { - return getClose(str, ch, idx + 1); + return getClosingQuote(str, ch, idx + 1); } return idx; } @@ -99,5 +164,8 @@ function keepQuotes(ch, opts) { } function keepEscaping(opts, str, idx) { + if (typeof opts.keepEscaping === 'function') { + return opts.keepEscaping(str, idx); + } return opts.keepEscaping === true || str[idx + 1] === '\\'; } |