1 var baseToString = require('../internal/baseToString'),
2 isIterateeCall = require('../internal/isIterateeCall');
4 /** Used to match words to create compound words. */
5 var reWords = (function() {
6 var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
7 lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
9 return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
13 * Splits `string` into an array of its words.
18 * @param {string} [string=''] The string to inspect.
19 * @param {RegExp|string} [pattern] The pattern to match words.
20 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
21 * @returns {Array} Returns the words of `string`.
24 * _.words('fred, barney, & pebbles');
25 * // => ['fred', 'barney', 'pebbles']
27 * _.words('fred, barney, & pebbles', /[^, ]+/g);
28 * // => ['fred', 'barney', '&', 'pebbles']
30 function words(string, pattern, guard) {
31 if (guard && isIterateeCall(string, pattern, guard)) {
34 string = baseToString(string);
35 return string.match(pattern || reWords) || [];
38 module.exports = words;