PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/words.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 35 lines | 13 code | 3 blank | 19 comment | 2 complexity | c1d0b16cc03d8e437b7d68bf2e31a591 MD5 | raw file
 1var asciiWords = require('./_asciiWords'),
 2    hasUnicodeWord = require('./_hasUnicodeWord'),
 3    toString = require('./toString'),
 4    unicodeWords = require('./_unicodeWords');
 5
 6/**
 7 * Splits `string` into an array of its words.
 8 *
 9 * @static
10 * @memberOf _
11 * @since 3.0.0
12 * @category String
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`.
17 * @example
18 *
19 * _.words('fred, barney, & pebbles');
20 * // => ['fred', 'barney', 'pebbles']
21 *
22 * _.words('fred, barney, & pebbles', /[^, ]+/g);
23 * // => ['fred', 'barney', '&', 'pebbles']
24 */
25function words(string, pattern, guard) {
26  string = toString(string);
27  pattern = guard ? undefined : pattern;
28
29  if (pattern === undefined) {
30    return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
31  }
32  return string.match(pattern) || [];
33}
34
35module.exports = words;