UNPKG

voca

Version:

The ultimate JavaScript string library

30 lines (26 loc) 903 B
import './internal/is_nil.js'; import './is_string.js'; import { c as coerceToString } from './internal/coerce_to_string.js'; /** * 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'] */ function split(subject, separator, limit) { var subjectString = coerceToString(subject); return subjectString.split(separator, limit); } export default split;