UNPKG

voca

Version:

The ultimate JavaScript string library

32 lines (27 loc) 937 B
'use strict'; require('./internal/is_nil.js'); require('./is_string.js'); var coerce_to_string = require('./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 = coerce_to_string.coerceToString(subject); return subjectString.split(separator, limit); } module.exports = split;