1 var baseToString = require('./_baseToString'),
2 castSlice = require('./_castSlice'),
3 hasUnicode = require('./_hasUnicode'),
4 isIterateeCall = require('./_isIterateeCall'),
5 isRegExp = require('./isRegExp'),
6 stringToArray = require('./_stringToArray'),
7 toString = require('./toString');
9 /** Used as references for the maximum length and index of an array. */
10 var MAX_ARRAY_LENGTH = 4294967295;
13 * Splits `string` by `separator`.
15 * **Note:** This method is based on
16 * [`String#split`](https://mdn.io/String/split).
22 * @param {string} [string=''] The string to split.
23 * @param {RegExp|string} separator The separator pattern to split by.
24 * @param {number} [limit] The length to truncate results to.
25 * @returns {Array} Returns the string segments.
28 * _.split('a-b-c', '-', 2);
31 function split(string, separator, limit) {
32 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
33 separator = limit = undefined;
35 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
39 string = toString(string);
41 typeof separator == 'string' ||
42 (separator != null && !isRegExp(separator))
44 separator = baseToString(separator);
45 if (!separator && hasUnicode(string)) {
46 return castSlice(stringToArray(string), 0, limit);
49 return string.split(separator, limit);
52 module.exports = split;