1 var asciiWords = require('./_asciiWords'),
2 hasUnicodeWord = require('./_hasUnicodeWord'),
3 toString = require('./toString'),
4 unicodeWords = require('./_unicodeWords');
7 * Splits `string` into an array of its words.
13 * @param {string} [string=''] The string to inspect.
14 * @param {RegExp|string} [pattern] The pattern to match words.
15 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
16 * @returns {Array} Returns the words of `string`.
19 * _.words('fred, barney, & pebbles');
20 * // => ['fred', 'barney', 'pebbles']
22 * _.words('fred, barney, & pebbles', /[^, ]+/g);
23 * // => ['fred', 'barney', '&', 'pebbles']
25 function words(string, pattern, guard) {
26 string = toString(string);
27 pattern = guard ? undefined : pattern;
29 if (pattern === undefined) {
30 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
32 return string.match(pattern) || [];
35 module.exports = words;