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:
Luiz Américo
2019-08-18 15:24:56 -03:00
committed by John-David Dalton
parent 15e1557b2a
commit e2555a43ad
3 changed files with 45 additions and 44 deletions

View File

@@ -1,13 +1,16 @@
import unicodeWords from './.internal/unicodeWords.js'
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 ]/
)
/** Used to match words composed of alphanumeric characters. */
const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g
function asciiWords(string) {
return string.match(reAsciiWord)
}
/**
* Splits `string` into an array of its words.
*