-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathsplit.js
More file actions
24 lines (23 loc) · 831 Bytes
/
split.js
File metadata and controls
24 lines (23 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import coerceToString from 'helper/string/coerce_to_string';
/**
* Splits `subject` into an array of chunks by `separator`.
*
* @function split
* @static
* @since 1.0.0
* @memberOf Split
* @param {string} [subject=''] The string to split into characters.
* @param {string|RegExp} [separator] The pattern to match the separator.
* @param {number} [limit] Limit the number of chunks to be found.
* @return {Array} Returns the array of chunks.
* @example
* v.split('rage against the dying of the light', ' ');
* // => ['rage', 'against', 'the', 'dying', 'of', 'the', 'light']
*
* v.split('the dying of the light', /\s/, 3);
* // => ['the', 'dying', 'of']
*/
export default function split(subject, separator, limit) {
const subjectString = coerceToString(subject);
return subjectString.split(separator, limit);
}