UNPKG

moltres-utils

Version:
40 lines (33 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _unicodeWords = _interopRequireDefault(require("./unicodeWords")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const asciiWords = RegExp.prototype.exec.bind(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g); const hasUnicodeWord = RegExp.prototype.test.bind(/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/); /** * Splits `string` into an array of its words. * * @param {string} [string=''] The string to inspect. * @param {RegExp|string} [pattern] The pattern to match words. * @returns {Array} Returns the words of `string`. * @example * * words('fred, barney, & pebbles') * // => ['fred', 'barney', 'pebbles'] * * words('fred, barney, & pebbles', /[^, ]+/g) * // => ['fred', 'barney', '&', 'pebbles'] */ const words = (string, pattern) => { if (pattern === undefined) { const result = hasUnicodeWord(string) ? (0, _unicodeWords.default)(string) : asciiWords(string); return result || []; } return string.match(pattern) || []; }; var _default = words; exports.default = _default; //# sourceMappingURL=words.js.map