source: imaps-frontend/node_modules/lodash-es/split.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import baseToString from './_baseToString.js';
2import castSlice from './_castSlice.js';
3import hasUnicode from './_hasUnicode.js';
4import isIterateeCall from './_isIterateeCall.js';
5import isRegExp from './isRegExp.js';
6import stringToArray from './_stringToArray.js';
7import toString from './toString.js';
8
9/** Used as references for the maximum length and index of an array. */
10var MAX_ARRAY_LENGTH = 4294967295;
11
12/**
13 * Splits `string` by `separator`.
14 *
15 * **Note:** This method is based on
16 * [`String#split`](https://mdn.io/String/split).
17 *
18 * @static
19 * @memberOf _
20 * @since 4.0.0
21 * @category String
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.
26 * @example
27 *
28 * _.split('a-b-c', '-', 2);
29 * // => ['a', 'b']
30 */
31function split(string, separator, limit) {
32 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
33 separator = limit = undefined;
34 }
35 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
36 if (!limit) {
37 return [];
38 }
39 string = toString(string);
40 if (string && (
41 typeof separator == 'string' ||
42 (separator != null && !isRegExp(separator))
43 )) {
44 separator = baseToString(separator);
45 if (!separator && hasUnicode(string)) {
46 return castSlice(stringToArray(string), 0, limit);
47 }
48 }
49 return string.split(separator, limit);
50}
51
52export default split;
Note: See TracBrowser for help on using the repository browser.