moltres-utils
Version:
Utils for Moltres apps
48 lines (37 loc) • 1.43 kB
JavaScript
require("core-js/modules/es6.object.define-property");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("core-js/modules/es6.regexp.match");
require("core-js/modules/es6.regexp.constructor");
require("core-js/modules/es6.function.bind");
var _unicodeWords = _interopRequireDefault(require("./unicodeWords"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var asciiWords = RegExp.prototype.exec.bind(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g);
var 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']
*/
var words = function words(string, pattern) {
if (pattern === undefined) {
var 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
;