UNPKG

awesome-string

Version:

The ultimate JavaScript string library

24 lines (23 loc) 832 B
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 * as.split('rage against the dying of the light', ' '); * // => ['rage', 'against', 'the', 'dying', 'of', 'the', 'light'] * * as.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); }