mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Implement asciiWords and unicodeWords using String.match instead of binding RegExp.exec (#4417)
* Enable words tests * Implement asciiWords and unicodeWords using String.match instead of binding RegExp.exec
This commit is contained in:
committed by
John-David Dalton
parent
15e1557b2a
commit
e2555a43ad
@@ -45,14 +45,7 @@ const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])'
|
||||
const rsSeq = rsOptVar + reOptMod + rsOptJoin
|
||||
const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`
|
||||
|
||||
/**
|
||||
* Splits a Unicode `string` into an array of its words.
|
||||
*
|
||||
* @private
|
||||
* @param {string} The string to inspect.
|
||||
* @returns {Array} Returns the words of `string`.
|
||||
*/
|
||||
const unicodeWords = RegExp.prototype.exec.bind(RegExp([
|
||||
const reUnicodeWords = RegExp([
|
||||
`${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
|
||||
`${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
|
||||
`${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
|
||||
@@ -61,6 +54,17 @@ const unicodeWords = RegExp.prototype.exec.bind(RegExp([
|
||||
rsOrdLower,
|
||||
`${rsDigit}+`,
|
||||
rsEmoji
|
||||
].join('|'), 'g'))
|
||||
].join('|'), 'g')
|
||||
|
||||
/**
|
||||
* Splits a Unicode `string` into an array of its words.
|
||||
*
|
||||
* @private
|
||||
* @param {string} The string to inspect.
|
||||
* @returns {Array} Returns the words of `string`.
|
||||
*/
|
||||
function unicodeWords(string) {
|
||||
return string.match(reUnicodeWords)
|
||||
}
|
||||
|
||||
export default unicodeWords
|
||||
|
||||
Reference in New Issue
Block a user