mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Bump to v4.9.0.
This commit is contained in:
27
split.js
27
split.js
@@ -1,5 +1,19 @@
|
||||
import isRegExp from './isRegExp';
|
||||
import stringToArray from './_stringToArray';
|
||||
import toString from './toString';
|
||||
|
||||
/** Used to compose unicode character classes. */
|
||||
var rsAstralRange = '\\ud800-\\udfff',
|
||||
rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
||||
rsComboSymbolsRange = '\\u20d0-\\u20f0',
|
||||
rsVarRange = '\\ufe0e\\ufe0f';
|
||||
|
||||
/** Used to compose unicode capture groups. */
|
||||
var rsZWJ = '\\u200d';
|
||||
|
||||
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
|
||||
var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
|
||||
|
||||
/**
|
||||
* Splits `string` by `separator`.
|
||||
*
|
||||
@@ -20,7 +34,18 @@ import toString from './toString';
|
||||
* // => ['a', 'b']
|
||||
*/
|
||||
function split(string, separator, limit) {
|
||||
return toString(string).split(separator, limit);
|
||||
string = toString(string);
|
||||
if (string && (
|
||||
typeof separator == 'string' ||
|
||||
(separator != null && !isRegExp(separator))
|
||||
)) {
|
||||
separator += '';
|
||||
if (separator == '' && reHasComplexSymbol.test(string)) {
|
||||
var strSymbols = stringToArray(string);
|
||||
return limit === undefined ? strSymbols : strSymbols.slice(0, limit < 0 ? 0 : limit);
|
||||
}
|
||||
}
|
||||
return string.split(separator, limit);
|
||||
}
|
||||
|
||||
export default split;
|
||||
|
||||
Reference in New Issue
Block a user